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 E83B8385840D for ; Sat, 2 Dec 2023 11:04:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E83B8385840D 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 E83B8385840D 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=1701515048; cv=none; b=Rf6eUKuoEv/b07vPZbvx7Yo32fz5wMecqcswM2rHw0p92V27lvUHZjYhVKwH9BpEXDVJT+PIw51mjmXLG3yExAfbEOvPcHslpWBwM9b3i3A0Z2lG6YAM8ZW5Bw5VjbyhRPxvrij/a+UXtDR7bjKMJhqiCyU7Aqo2w7Xypr8Hmj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701515048; c=relaxed/simple; bh=d1FeaeTk84OMv+/MQCMUTGh7z6MWlhdrAGiENlk+u7E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gQqWhDoLNkj4u4+oACcGJnm5QbBEjRCaRRqui+4bNJtbiHW2svKkMR8JkNXnZKHTyQC4GAwAuL/ibbNcYvVBtsEpwPm5gEXwzFPdiVs4LNBCXP4lrX6OuPjTg1Yj2fy3B+JGZQufrBXDiaADcuOkUIyxTGgGiwqixB4DQMCy+OI= 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 90DC8FEC; Sat, 2 Dec 2023 03:04:52 -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 7B6603F6C4; Sat, 2 Dec 2023 03:04:05 -0800 (PST) From: Richard Sandiford To: Jakub Jelinek Mail-Followup-To: Jakub Jelinek ,Eric Botcazou , Segher Boessenkool , Jeff Law , gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Cc: Eric Botcazou , Segher Boessenkool , Jeff Law , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760] References: Date: Sat, 02 Dec 2023 11:04:04 +0000 In-Reply-To: (Jakub Jelinek's message of "Sat, 2 Dec 2023 11:44:08 +0100") 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=-16.3 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Jakub Jelinek writes: > Hi! > > The following testcase ICEs on x86_64-linux since df_note_add_problem () > call has been added to mode switching. > The problem is that the pro_and_epilogue pass in > prepare_shrink_wrap -> copyprop_hardreg_forward_bb_without_debug_insn > uses regcprop.cc infrastructure which relies on accurate REG_DEAD/REG_UNUSED > notes. E.g. regcprop.cc > /* We need accurate notes. Earlier passes such as if-conversion may > leave notes in an inconsistent state. */ > df_note_add_problem (); > documents that. On the testcase below it is in particular the > /* Detect obviously dead sets (via REG_UNUSED notes) and remove them. */ > if (set > && !RTX_FRAME_RELATED_P (insn) > && NONJUMP_INSN_P (insn) > && !may_trap_p (set) > && find_reg_note (insn, REG_UNUSED, SET_DEST (set)) > && !side_effects_p (SET_SRC (set)) > && !side_effects_p (SET_DEST (set))) > { > bool last = insn == BB_END (bb); > delete_insn (insn); > if (last) > break; > continue; > } > case where a stale REG_UNUSED note breaks stuff up (added in vzeroupper > pass, redundant insn after it deleted later). > > The following patch makes sure the notes are not stale if shrink wrapping > is enabled. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? I still maintain that so much stuff relies on the lack of false-positive REG_UNUSED notes that (whatever the intention might have been) we need to prevent the false positive. Like Andrew says, any use of single_set is suspect if there's a REG_UNUSED note for something that is in fact used. So sorry to be awkward, but I don't think this is the way to go. I think we'll just end up playing whack-a-mole and adding df_note_add_problem to lots of passes. (FTR, I'm not saying passes have to avoid false negatives, just false positives. If a pass updates an instruction with a REG_UNUSED note, and the pass is no longer sure whether the register is unused or not, the pass can just delete the note.) Richard > 2023-12-02 Jakub Jelinek > > PR rtl-optimization/112760 > * function.cc (thread_prologue_and_epilogue_insns): If > SHRINK_WRAPPING_ENABLED, call df_note_add_problem before calling > df_analyze. > > * gcc.dg/pr112760.c: New test. > > --- gcc/function.cc.jj 2023-11-07 08:32:01.699254744 +0100 > +++ gcc/function.cc 2023-12-01 13:42:51.885189341 +0100 > @@ -6036,6 +6036,11 @@ make_epilogue_seq (void) > void > thread_prologue_and_epilogue_insns (void) > { > + /* prepare_shrink_wrap uses copyprop_hardreg_forward_bb_without_debug_insn > + which uses regcprop.cc functions which rely on accurate REG_UNUSED > + and REG_DEAD notes. */ > + if (SHRINK_WRAPPING_ENABLED) > + df_note_add_problem (); > df_analyze (); > > /* Can't deal with multiple successors of the entry block at the > --- gcc/testsuite/gcc.dg/pr112760.c.jj 2023-12-01 13:46:57.444746529 +0100 > +++ gcc/testsuite/gcc.dg/pr112760.c 2023-12-01 13:46:36.729036971 +0100 > @@ -0,0 +1,22 @@ > +/* PR rtl-optimization/112760 */ > +/* { dg-do run } */ > +/* { dg-options "-O2 -fno-dce -fno-guess-branch-probability --param=max-cse-insns=0" } */ > +/* { dg-additional-options "-m8bit-idiv -mavx" { target i?86-*-* x86_64-*-* } } */ > + > +unsigned g; > + > +__attribute__((__noipa__)) unsigned short > +foo (unsigned short a, unsigned short b) > +{ > + unsigned short x = __builtin_add_overflow_p (a, g, (unsigned short) 0); > + g -= g / b; > + return x; > +} > + > +int > +main () > +{ > + unsigned short x = foo (40, 6); > + if (x != 0) > + __builtin_abort (); > +} > > Jakub