From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9FC703858D39; Wed, 29 Dec 2021 03:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FC703858D39 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103855] Missed optimization: 64bit division used instead of 32bit division Date: Wed, 29 Dec 2021 03:53:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.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: Wed, 29 Dec 2021 03:53:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103855 --- Comment #4 from Andrew Pinski --- unsigned int optimized(unsigned int a, unsigned int b) { return (unsigned long long)a / b; } unsigned int unoptimized(unsigned int a, unsigned int b) { unsigned long long all =3D a; return all / b; } unsigned long long unoptimized1(unsigned int a, unsigned int b) { unsigned long long all =3D a; return all / b; } unsigned long long unoptimized2(unsigned long a, unsigned long b) { if (((unsigned int)a) !=3D a) __builtin_unreachable(); if (((unsigned int)b) !=3D b) __builtin_unreachable(); return a / b; } Is the full testcase, clang is able to handle all of them. GCC only handles the first one. If you just do the match.pd patch, unoptimized2 would be not handled. expmed.c (expand_divmod) is where the expansion happens from gimple to rtl.=