From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5B1173858C39; Wed, 6 Oct 2021 22:21:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B1173858C39 From: "mk.aard.gcc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102634] New: Optimization in dom2 pass makes wrong signed integer overflow inference Date: Wed, 06 Oct 2021 22:21:04 +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: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mk.aard.gcc 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 target_milestone attachments.created 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, 06 Oct 2021 22:21:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102634 Bug ID: 102634 Summary: Optimization in dom2 pass makes wrong signed integer overflow inference Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: mk.aard.gcc at gmail dot com Target Milestone: --- Created attachment 51563 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51563&action=3Dedit Sample code which fails. Integer with 'NaN' handling user type using min integer value as NaN Compiled using GCC 10.2.1 on Debian 11 Bullseye, amd64: g++ -c -O2 -std=3Dc++17 example.cpp This generates the following assembly for strange_code() (see attached .ii) 00000000000000d0 : d0: 55 push %rbp d1: 48 83 ec 10 sub $0x10,%rsp d5: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp) dc: 00 00=20 de: 48 8d 6c 24 08 lea 0x8(%rsp),%rbp e3: 48 89 ef mov %rbp,%rdi e6: e8 00 00 00 00 callq eb eb: 48 89 ef mov %rbp,%rdi **ee: 48 be 00 00 00 00 00 movabs $0x8000000000000000,%rsi f5: 00 00 80=20 f8: e8 00 00 00 00 callq fd fd: 48 83 c4 10 add $0x10,%rsp 101: b8 01 00 00 00 mov $0x1,%eax 106: 5d pop %rbp 107: c3 retq The use of 0x8000000000000000 as the argument for the second call we believ= e is an incorrect optimization. Although -fwrapv resolves this issue for us, and bug reporting guidelines indicate that -fwrapv fixes are likely user error, I and several teammates = have been unable to find any signed integer overflow issues in the example provi= ded. As far as we can tell, each usage of the problematic value avoids any opera= tion which could cause overflow. I apologize that the example isn't smaller, changing virtually anything in = it causes the issue to go away.=