From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CB69A3858410; Tue, 24 Aug 2021 08:47:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB69A3858410 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/30484] INT_MIN % -1 is well defined for -fwrapv Date: Tue, 24 Aug 2021 08:47:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.1.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net 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: 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 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: Tue, 24 Aug 2021 08:47:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D30484 --- Comment #18 from Vincent Lef=C3=A8vre -= -- (In reply to Vincent Lef=C3=A8vre from comment #16) > int f (int a, int b, int c) > { > if (b < 0) > return a + b + c; > else > return a + c + b; > } >=20 > The generated code with -O3 has 6 instructions: >=20 > leal (%rdi,%rdx), %eax > addl %esi, %edi > addl %edx, %edi > addl %esi, %eax > testl %esi, %esi > cmovs %edi, %eax >=20 > In theory, the compiler could normally optimize to produce the same code = as > with the source that assumes -fwrapv (here, a + b + c and a + c + b are > obviously equivalent on a typical processor), but in practice, this is of= ten > not the case as shown above. Surprisingly, GCC can optimize this second test to 2 instructions with -fwr= apv. I've reported PR102032 about the missed optimization without -fwrapv.=