From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 921A83858425; Thu, 22 Dec 2022 14:32:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 921A83858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671719548; bh=H3Ubbr3kGU6ZUlLQTV/hnXh3G9SwwA1g/K2u+g4JtRs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c4aYgK4jwYxFGabHZlKuZvjfR1snai76WQdr/y2P2/h0znhiaPR/5gAScbm8Z0/4w Qt+sm8nVI4mSh4PxbI5lvFQjKJ1Tg+qSOOTDgu0bDFxcRnn/gUYgnkaUtJbnu5iepb 2/Nv+CKY5GAMSiBwSRoOY23BXEIJd7KlTugUfEvQ= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107114] [13 Regression] Failure to discover range results in bogus warning Date: Thu, 22 Dec 2022 14:32:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: keywords everconfirmed bug_status cf_reconfirmed_on Message-ID: In-Reply-To: References: 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 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2022-12-22 --- Comment #6 from Richard Biener --- Confirmed for the diagnostics. But note the loop in question is basically for (a =3D 1; a !=3D 0; a++) so it iterates until we wrap to zero (a is 'short', the increment is in 'int' due to promotion so short wrap doesn't invoke undefined overflow). That means the loop iterates >65000 times which means the repeated add of 264487869 overflows. At the point we emit this diagnostic this will always happen so the diagnostic is correct? We do fail to optimize if ((c +=3D 264487869) =3D=3D 9) though, but likely because VRP no longer iterates. c starts from 1 and we only add positive numbers the range for it should be [1, +INF]. The entry to the line: tail loop has this optimized and the add removed as dead code. That's what possibly happened before - we optimized this branch and thus DCEd the add? Anyhow, on x86_64 we mangle the whole thing a bit more than on arc-elf. Huh, it looks like arc-elf disables GIMPLE loop optimizers. I can reproduce the diagnostic on x86_64 with -fno-tree-loop-optimize. gcc/common/config/arc/arc-common.cc has { OPT_LEVELS_SIZE, OPT_ftree_loop_optimize, NULL, 0}, for whatever reason. -ftree-loop-optimize "fixes" the diagnostic. But as said, I think the diagnostic is correct.=