From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5B63B3851C27; Sat, 20 Jun 2020 10:13:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B63B3851C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592647993; bh=A7rC5xYLKJG740Divk79XC1v4y9XacYLdpmHQpXUJbA=; h=From:To:Subject:Date:From; b=tqEKCG1v4dYmjrosUdipzo87QG05nJ9wge83/ogA+aq8PlUgT9UwHtvZwcUfC/UoA 5UifVi5qngKCcITxIzKnQDlSWZlbhVE9NmblfD3XA0Sa0dyXW+c9Htu6v9Yo201UtI 8dWVF1bOyxRHW23uIcB0j/d8eYwrQqkbGO+pTj5U= From: "gabravier at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/95784] New: Failure to optimize usage of __builtin_add_overflow with return statement properly Date: Sat, 20 Jun 2020 10:13:13 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gabravier 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: 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: Sat, 20 Jun 2020 10:13:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95784 Bug ID: 95784 Summary: Failure to optimize usage of __builtin_add_overflow with return statement properly Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- int f(uint8_t operand, int8_t *result) { if (__builtin_add_overflow(operand, 0, result)) { *result =3D 0; return 10213; } return 0; } With -O3, LLVM outputs this : f(unsigned char, signed char*): # @f(unsigned char, signed char*) movsx eax, dil xor ecx, ecx cmp edi, eax cmovne edi, ecx mov byte ptr [rsi], dil mov eax, 10213 cmove eax, ecx ret GCC outputs this : f(unsigned char, signed char*): movzx eax, dil movsx di, dil cmp ax, di setne dl mov r8d, edx sal r8d, 31 sar r8d, 31 and r8d, 10213 test dl, dl mov edx, 0 cmovne eax, edx mov BYTE PTR [rsi], al mov eax, r8d ret=