From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 734F93858C98 for ; Tue, 5 Mar 2024 19:54:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 734F93858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 734F93858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709668494; cv=none; b=mYapF8+g0REgV7Ady1sHtTUSS977atzsoQhTkTCshXoe9ir89J8AsCn3tQFGcAeufONbwRpQY8mgtuPYnn49IlzD9497PhiTFm/zeHy0O0CcwcX46/1CdEwlBUI8RzJmPSTuqkrw3PULAWrNmX6enbEs1f3lQq1aVc4JC11vpPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709668494; c=relaxed/simple; bh=J8YZ5mVek/dvFwOFx+iV58avhnG+dxCbtKRyq6BXSAQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sH6reYgAueYFsFDie4OBVwbrciqO+FseMKbapgBGJuWz44LjqAnU46ccoeTKEc3Dow8Yi7LMlcgfbdvKajaNSvcgbPz0rmgf+M1fuHRVfsXOgD9ifNHmlpcIGoU5j292un4eKsJMA5POz7rH+FDVUFZuz4eGjeSKnCaIC5BSD34= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C85711FB; Tue, 5 Mar 2024 11:55:28 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 051853F73F; Tue, 5 Mar 2024 11:54:50 -0800 (PST) From: Richard Sandiford To: HAO CHEN GUI Mail-Followup-To: HAO CHEN GUI ,gcc-patches , Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Jeff Law , richard.sandiford@arm.com Cc: gcc-patches , Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Jeff Law Subject: Re: [PATCHv2] fwprop: Avoid volatile defines to be propagated References: Date: Tue, 05 Mar 2024 19:54:49 +0000 In-Reply-To: (HAO CHEN GUI's message of "Tue, 5 Mar 2024 15:12:13 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-20.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: HAO CHEN GUI writes: > Hi, > This patch tries to fix a potential problem which is raised by the patch > for PR111267. The volatile asm operand tries to be propagated to a single > set insn with the patch for PR111267. The volatile asm operand might be > executed for multiple times if the define insn isn't eliminated after > propagation. Now set_src_cost comparison might reject such propagation. > But it has the chance to be taken after replacing set_src_cost with insn > cost. Actually I found the problem in testing my patch which replacing > set_src_cost with insn_cost in fwprop pass. > > Compared to the last version, the check volatile_insn_p is replaced with > volatile_refs_p in order to check volatile memory reference also. > https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646482.html > > Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no > regressions. Is it OK for the trunk? OK, thanks. I'm not sure this fixes a known regression, but IMO the barrier should be lower for things that fix loss of volatility, since it's usually so hard to observe the effect in a determinstic way. Richard > > Thanks > Gui Haochen > > ChangeLog > fwprop: Avoid volatile defines to be propagated > > The patch for PR111267 (commit id 86de9b66480b710202a2898cf513db105d8c432f) > which introduces an exception for propagation on single set insn. The > propagation which might not be profitable (checked by profitable_p) is still > allowed to be propagated to single set insn. It has a potential problem > that a volatile operand might be propagated to a single set insn. If the > define insn is not eliminated after propagation, the volatile operand will > be executed for multiple times. This patch fixes the problem by skipping > volatile set source rtx in propagation. > > gcc/ > * fwprop.cc (forward_propagate_into): Return false for volatile set > source rtx. > > gcc/testsuite/ > * gcc.target/powerpc/fwprop-1.c: New. > > patch.diff > diff --git a/gcc/fwprop.cc b/gcc/fwprop.cc > index 7872609b336..cb6fd6700ca 100644 > --- a/gcc/fwprop.cc > +++ b/gcc/fwprop.cc > @@ -854,6 +854,8 @@ forward_propagate_into (use_info *use, bool reg_prop_only = false) > > rtx dest = SET_DEST (def_set); > rtx src = SET_SRC (def_set); > + if (volatile_refs_p (src)) > + return false; > > /* Allow propagations into a loop only for reg-to-reg copies, since > replacing one register by another shouldn't increase the cost. > diff --git a/gcc/testsuite/gcc.target/powerpc/fwprop-1.c b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c > new file mode 100644 > index 00000000000..07b207f980c > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/fwprop-1.c > @@ -0,0 +1,15 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fdump-rtl-fwprop1-details" } */ > +/* { dg-final { scan-rtl-dump-not "propagating insn" "fwprop1" } } */ > + > +/* Verify that volatile asm operands doesn't be propagated. */ > +long long foo () > +{ > + long long res; > + __asm__ __volatile__( > + "" > + : "=r" (res) > + : > + : "memory"); > + return res; > +}