From patchwork Wed Feb 1 11:37:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 51310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp224288wrn; Wed, 1 Feb 2023 03:38:18 -0800 (PST) X-Google-Smtp-Source: AK7set9grZ0/X92+9HP1g6eUCdh7YygbpliJGCE0OA1EYsPtbPgiNvUt8y0NMSZaZhJ8u+DES/uX X-Received: by 2002:a17:906:ae5a:b0:878:81d7:9f6f with SMTP id lf26-20020a170906ae5a00b0087881d79f6fmr2011327ejb.67.1675251498796; Wed, 01 Feb 2023 03:38:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675251498; cv=none; d=google.com; s=arc-20160816; b=dzx5zepYyNBTe+gJ1iKBPg3QvS5woGkTCEvr0f4961NQQSuk9NxgtXE+ud67t8yOZv rEc4q8ro2Wk6pMLMrAmXb06RLQY+TfSWVoQteA5cxpuNChCeq80OBdhPffevkFGq0yBR VMkaSpxb5LVbqOXY9CUxXn8gHWok+rVLwZxxuyIOowoEF5IKOllCfzsErFuPRU9VEt/K MeSaJlG1doCZzy97VRfzDHVKfRzWbUTv+e+GU76oDXAE3LcpcwzPQjCaSbfde6fbbyA9 MAgMdFWg+zpKSc6ZdLzCVbJ+AB8IFqqXZxD5VlQ51VQLAUQc79a2WJU3d9w7sRb1u2CT 9Vhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=4I97UWg50j7hAuYpM7kINYdFsWxUCr5RUrNgy7qckz0=; b=fdXaDxafWrw2XocMrx4o8Qufpm9SPf4XsvmNiQRsHbDw3E7uZ9oLag+F2oxfDydoOJ pG49jri9662MTyTzg0Y9Fr4CiOkfVLMNu2gZ1hS8n6rYq/btVYSVzfTNCMLn9/gaPJhI glzyoC5+aDzQ61vMoOWMJIXRA3eGUGW54ilpjB24x8ANXYJnAGRtVmUk3uMvJR+u02pV XbRN19Nv2wKXMHeZ9bAgKIIaFH7rJ5cLZj0Q2fx9wdgnuq7A6HRqMfBEuK9NLpJcmxhe FTO+jxeZRDebQPUjLqK4wWmgTVyeFbdF62AJtAgX5Kf8QX8b2j4jcB6MwydiONbwG2oz dtww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DqMpYyC5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eu3-20020a170907298300b0086ea1c7ae21si26391946ejc.54.2023.02.01.03.38.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 03:38:18 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DqMpYyC5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 951193858004 for ; Wed, 1 Feb 2023 11:38:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 951193858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675251497; bh=4I97UWg50j7hAuYpM7kINYdFsWxUCr5RUrNgy7qckz0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DqMpYyC5UjVqZma0pZ+kcG7+Ubo1i0/MBEo59tSOCkq5TsOadDsWboxXyMAUXAz59 lwDjyWjLwEORKOvpR9nq8eLb5wUD3LnVtI+6DCC5XtIp2n/D61YZ5zmOLiKvF8tYCU sjyOW78ETVbDBfzf9C/vTV94tp036EPt8ZlSBS70= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0DCEC3858D39 for ; Wed, 1 Feb 2023 11:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DCEC3858D39 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-222-3AzWY0zrMr2T4WxSTbyehQ-1; Wed, 01 Feb 2023 06:37:29 -0500 X-MC-Unique: 3AzWY0zrMr2T4WxSTbyehQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18718101A521; Wed, 1 Feb 2023 11:37:29 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C36EA112132C; Wed, 1 Feb 2023 11:37:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 311BbPVc3219441 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 1 Feb 2023 12:37:26 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 311BbOjp3219440; Wed, 1 Feb 2023 12:37:24 +0100 Date: Wed, 1 Feb 2023 12:37:24 +0100 To: Jeff Law , Richard Biener , Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ree: Fix -fcompare-debug issues in combine_reaching_defs [PR108573] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756628515471110207?= X-GMAIL-MSGID: =?utf-8?q?1756628515471110207?= Hi! The PR78437 r7-4871 changes made combine_reaching_defs punt on WORD_REGISTER_OPERATIONS targets if a setter of smaller than word register has wider uses. This unfortunately breaks -fcompare-debug, because if such a use appears only in DEBUG_INSN(s), while all other uses aren't wider than the setter, we can REE optimize it without -g and not with -g. Such decisions shouldn't be based on debug instructions. We could try to reset them or adjust in some other way after we decide to perform the change, but at least on the testcase which used to fail on riscv64-linux the (debug_insn 8 7 9 2 (var_location:HI s (minus:HI (subreg:HI (and:DI (reg:DI 10 a0 [160]) (const_int 1 [0x1])) 0) (subreg:HI (ashiftrt:DI (reg/v:DI 9 s1 [orig:151 l ] [151]) (debug_expr:SI D#1)) 0))) "pr108573.c":12:5 -1 (nil)) clearly doesn't care about the upper bits and I have hard time imaging how could one end up with DEBUG_INSN which actually cares about those upper bits. So, the following patch just ignores uses on DEBUG_INSNs in this case, if we run into something where we'd need to do something further later on, let's deal with it when we have a testcase for it. Bootstrapped/regtested on x86_64-linux and i686-linux (admittedly non-WORD_REGISTER_OPERATIONS targets) and tested using a cross to riscv64-linux on the testcase, ok for trunk? 2023-02-01 Jakub Jelinek PR debug/108573 * ree.cc (combine_reaching_defs): Don't return false for paradoxical subregs in DEBUG_INSNs. * gcc.dg/pr108573.c: New test. Jakub --- gcc/ree.cc.jj 2023-02-01 10:19:22.833436546 +0100 +++ gcc/ree.cc 2023-02-01 12:25:57.468252609 +0100 @@ -875,7 +875,8 @@ combine_reaching_defs (ext_cand *cand, c for (df_link *use = uses; use; use = use->next) if (paradoxical_subreg_p (GET_MODE (*DF_REF_LOC (use->ref)), - GET_MODE (SET_DEST (*dest_sub_rtx)))) + GET_MODE (SET_DEST (*dest_sub_rtx))) + && !DEBUG_INSN_P (DF_REF_INSN (use->ref))) return false; } @@ -963,7 +964,8 @@ combine_reaching_defs (ext_cand *cand, c rtx dest2 = SET_DEST (*dest_sub_rtx2); for (use = uses; use; use = use->next) if (paradoxical_subreg_p (GET_MODE (*DF_REF_LOC (use->ref)), - GET_MODE (dest2))) + GET_MODE (dest2)) + && !DEBUG_INSN_P (DF_REF_INSN (use->ref))) break; if (use) break; --- gcc/testsuite/gcc.dg/pr108573.c.jj 2023-02-01 12:15:20.476577340 +0100 +++ gcc/testsuite/gcc.dg/pr108573.c 2023-02-01 12:15:03.044832520 +0100 @@ -0,0 +1,18 @@ +/* PR debug/108573 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +unsigned g; + +int bar (void); +int baz (int); + +void +foo (unsigned short s, long l) +{ + unsigned u = bar (); + s &= __builtin_add_overflow_p (0, u, 0); + s %= g; + s -= l >> s; + baz (s); +}