From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 42CDF385AC0A; Sun, 15 Aug 2021 11:45:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42CDF385AC0A From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/48580] missed optimization: integer overflow checks Date: Sun, 15 Aug 2021 11:45:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.6.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia 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: --- 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: Sun, 15 Aug 2021 11:45:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D48580 --- Comment #22 from Andrew Pinski --- For the original testcase in comment #0 we produce (in GCC 11+): movl %edi, %eax mull %esi seto %dl xorl %r8d, %r8d movzbl %dl, %edx testl %eax, %eax jle .L1 testl %edx, %edx sete %r8b .L1: movl %r8d, %eax ret ------- CUT ---- I have a patch which I think improves the code even more. The gimple level looks like this correctly: x.0_1 =3D (unsigned int) x_6(D); y.1_2 =3D (unsigned int) y_7(D); _11 =3D .MUL_OVERFLOW (x.0_1, y.1_2); tmp_8 =3D REALPART_EXPR <_11>; tmp.3_3 =3D (int) tmp_8; if (tmp.3_3 > 0) goto ; [59.00%] else goto ; [41.00%] [local count: 633507680]: _12 =3D IMAGPART_EXPR <_11>; _10 =3D _12 =3D=3D 0; [local count: 1073741824]: # iftmp.2_5 =3D PHI <_10(3), 0(2)> Notice no divide. The _12 =3D=3D 0 part really should just _12 ^ 1. After my patch (which I need to finish up) we get: movl %edi, %eax mull %esi seto %dl xorl %r8d, %r8d movzbl %dl, %edx xorl $1, %edx testl %eax, %eax cmovg %edx, %r8d movl %r8d, %eax ret Which should be exactly what you wanted or very close. There looks to be a few micro-optimizations needed still really.=