From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 22A93385DC1C; Sat, 25 Apr 2020 08:55:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22A93385DC1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587804909; bh=wqQUzpjIteF2ZNy6McxK3Qyi+LmDz1WPCVoLBoRf+GA=; h=From:To:Subject:Date:From; b=cAQfcmSCDoutvMHM+2F2g2LUKdcY8tyjbsR83HGB/XZgBn4rm2sN4QapdGzgTTfp1 VmnhXXjBWALcIhrNOCUUizHIZTk7xOZ+DczXfDCWwkLQyOpzgaIJOWUwXEy6dc3vgY WWwyjDKN2rrojGCh9zPr6eWQ5uKrXf/XturMCUmM= From: "felix.von.s at posteo dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94757] New: GCC does not optimise unsigned multiplication known not to overflow Date: Sat, 25 Apr 2020 08:55:08 +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.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: felix.von.s at posteo dot de 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 keywords 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, 25 Apr 2020 08:55:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94757 Bug ID: 94757 Summary: GCC does not optimise unsigned multiplication known not to overflow Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: felix.von.s at posteo dot de Target Milestone: --- This code: #include unsigned f(unsigned x) { if (x > UINT_MAX / 3) __builtin_unreachable(); return (x * 3) / 3; } should be possible to optimise into the identity function, but (on x86_64) = gcc -O3 generates a multiplication (via LEA) then a division (via multiplicatio= n). GCC knows that the multiplication cannot overflow, because replacing the returned expression with __builtin_mul_overflow_p(x, 3, x) is makes it opti= mise to returning constant 0.=