From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 467C73858400; Wed, 1 Sep 2021 07:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 467C73858400 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly Date: Wed, 01 Sep 2021 07:09:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Sep 2021 07:09:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102155 Bug ID: 102155 Summary: LIM fill_always_executed_in handles contains_call incorrectly Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- fill_always_executed_in walks loop bodies in dominator order (get_loop_body_in_dom_order) but that does not run into BB3 before marking = BB4 as always executed: do { BB1: if (x) BB2: if (y) BB3: bar(); BB4; } while (++i < n); the dominator children of BB1 are BB2 and BB4, BB3 with the call to bar() is only a dominator child of BB2. Since LIM gives up on "unanalyzable" refs like calls a testcase that is miscompiled is a bit difficult to construct - it requires a 'pure' (or cons= t) call but whether it's valid for those to exit the program could be subject to discussion. The following uses a looping const function to show the effect and the testcase segfaults with -O1+ while it runs into the infinite loop at -O0. Note we'd technically need to set looping_const but there's now way to do this and with just -fno-inline and letting IPA figure out looping-const dominator children are ordered in a "lucky" way for fill_sons_in_loop to compute an order that happens to work. extern void abort (void); int flag[32]; int __attribute__((noinline,const)) bar (int i) { if (i) return i; while (1= ); } int __attribute__((noipa)) foo (int *p, int n) { int i =3D 0, res =3D 0; do { if (!flag[i]) { if (i % 3 =3D=3D 0) res +=3D bar (i); else res++; } res +=3D *p; } while (++i < n); return res; } int main() { if (foo ((int *)0, 5) !=3D 0) abort (); return 0; }=