From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C52ED3858C20; Sat, 1 Oct 2022 17:59:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C52ED3858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664647172; bh=0fsWaJHNKmJandUHS+xBbV7WzkDHl6BTRvGq+gnOc+o=; h=From:To:Subject:Date:From; b=cduOGGmThsPeZyX0bAjYSXRm4CJt8ZEZKKJcxn7Kmhr7j/8JIp/8cQLm+iedrtw6s egx+a62Ct0AqgwIBmBLFRMEZ6xTWLPNuKkzcL3seMrHNvkreYNBcBSWur3Do2IZIOL tjQWthMLSJ3FPi9xHiB2BITqx46hEuHokYqlX9dQ= From: "jeffreyalaw at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107114] New: [13 Regression] Failure to discover range results in bogus warning Date: Sat, 01 Oct 2022 17:59:31 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jeffreyalaw at gmail dot com 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 cc target_milestone cf_gcctarget 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107114 Bug ID: 107114 Summary: [13 Regression] Failure to discover range results in bogus warning Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jeffreyalaw at gmail dot com CC: aldyh at redhat dot com, amacleod at redhat dot com Target Milestone: --- Target: arc-elf After this change (from me): aa360fbf68b11e54017e8fa5b1bdb87ce7c19188 I'm seeing a case on arc-elf where VRP/Ranger is no longer identifying the range of one object as not including zero. As a result a test later in the= CFG isn't simplified and we get a bogus warning. What's really interesting here is my change simplifies the CFG by eliminati= ng a handful of blocks in the affected loop (including a sub-loop). Here's the testcase: /* { dg-do compile } */ short a; long b; void fn1() { int c =3D a =3D 1; for (; a; a++) { for (; 9 <=3D 8;) for (;;) { a =3D 20; for (; a <=3D 35; a++) ; line:; } if ((c +=3D 264487869) =3D=3D 9) { unsigned *d =3D 0; for (; b;) d =3D (unsigned *)&c; if (d) for (;;) ; } } goto line; } Compiled on arc-elf with -Os -Wall: [jlaw@X10DRH-iT gcc]$ ./cc1 -Os -Wall k.c -quiet k.c: In function =E2=80=98fn1=E2=80=99: k.c:17:14: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations] 17 | if ((c +=3D 264487869) =3D=3D 9) | ^~ k.c:8:10: note: within this loop 8 | for (; a; a++) | ^ If we look at the .vrp2 dump before my change we have this: Global Exported: a_lsm.14_26 =3D [irange] short int [1, 9] NONZERO 0xf This is key because we have this in the CFG: ;; basic block 7, loop depth 1, count 21262216 (estimated locally), maybe= hot ;; prev block 6, next block 1, flags: (NEW, REACHABLE, VISITED) ;; pred: 2 [always] count:1346238 (estimated locally) (FALLTHRU,EXECUTABLE) k.c:8:3 ;; 6 [always] count:20092794 (estimated locally) (FALLTHRU,DFS_BACK,EXECUTABLE) # a_lsm.14_26 =3D PHI <1(2), _11(6)> # a_lsm_flag.15_28 =3D PHI <0(2), 1(6)> # c_lsm.16_29 =3D PHI <1(2), _6(6)> if (a_lsm.14_26 !=3D 0)=20 goto ; [94.50%] else=20 goto ; [5.50%] We really want to simplify that condition to a compile-time constant. That avoids the incorrect warning. After my change we do not discover the range for a_lsm.14_26 in vfp2 and naturally conditional above isn't simplified and the warning gets triggered. Maybe I'm missing something subtle, but it looks like the simplifications d= one in dom3 are resulting in vrp2 missing discovery of the key range. It's not clear to me why that's that's happening though. Thoughts?=