From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22144 invoked by alias); 1 Aug 2015 10:59:56 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22106 invoked by uid 48); 1 Aug 2015 10:59:53 -0000 From: "m.mukovnikov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/67089] New: [4.8/4.9/5/6 Regression] Integer overflow checks not optimized on x86/x86_64 Date: Sat, 01 Aug 2015 10:59:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 5.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: m.mukovnikov 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 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-08/txt/msg00013.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67089 Bug ID: 67089 Summary: [4.8/4.9/5/6 Regression] Integer overflow checks not optimized on x86/x86_64 Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: m.mukovnikov at gmail dot com Target Milestone: --- Starting from 4.8.3, gcc does not optimize integer overflow and underflow checks inserting a redundant cmp instruction in both 32-bit and 64-bit modes. Having git-bisected the revisions, I found out r204088 (by pr58779) had added such behavior. --------------- example --------------- extern void underflow(void) __attribute__((noreturn)); unsigned sub(unsigned a, unsigned b) { unsigned r = a - b; if (r > a) underflow(); return r; } ------------ gcc-4.8.2 -O1 ------------ sub(unsigned int, unsigned int): movl %edi, %eax subl %esi, %eax /* CF is set on overflow */ jae .L4 /* jae = jnb = jnc = 73h */ subq $8, %rsp call underflow() .L4: rep; ret ------------ gcc-4.8.3 -O1 ------------ sub(unsigned int, unsigned int): movl %edi, %eax subl %esi, %eax cmpl %eax, %edi /* absolutely redundant */ jnb .L4 subq $8, %rsp call underflow() .L4: rep ret ---------------------------------------