From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 354463870868; Fri, 19 Jun 2020 08:09:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 354463870868 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592554170; bh=qevX3+ekYHWAPJ5TLnR4OoiO8FyAttdESMeb5w2GR/k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=p+XWqefEpgc1mjSX1JChMSmh28JrshKSmm86A3OTGAMtRil7d7Vm3hXp8ydsVz2OB MfW4iKEtjuXsIoAF2EURMPnoeJbpq2l3SyvuGoGoAOBBW/X2amqMLwQyPv33wZSrJP uQkGdULOizLCXKN84ijI1adjtdPakwv9JSEasZSE= From: "qianjh at cn dot fujitsu.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94757] GCC does not optimise unsigned multiplication known not to overflow Date: Fri, 19 Jun 2020 08:09:30 +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: 10.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: qianjh at cn dot fujitsu.com 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: cc 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: Fri, 19 Jun 2020 08:09:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94757 Qian Jianhua changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |qianjh at cn dot fujitsu.c= om --- Comment #2 from Qian Jianhua --- >GCC knows that the multiplication cannot overflow, because replacing the=20 >returned expression with __builtin_mul_overflow_p(x, 3, x) is makes it opt= imise=20 >to returning constant 0. __builtin_mul_overflow_p function only check the value range. So it could be optimised by VRP. The process like this x range [0, UINT_MAX/3] x*3 range [0, UINT_MAX] x*3/3 range [0, UINT_MAX/3], but not calculate the result(=3Dx). I tested some other cases.=20 It seems that the optimiser in gcc only check the value range of the expression, but not track/calculate the result of the expression, if the variable is not constant int the expression. So i think such optimisation of expression is not supported in gcc now. In clang, the expression "(x * 3) / 3" is optimised to "x".=