[Bug tree-optimization/94757] GCC does not optimise unsigned multiplication known not to overflow

qianjh at cn dot fujitsu.com gcc-bugzilla@gcc.gnu.org
Fri Jun 19 08:09:30 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94757

Qian Jianhua <qianjh at cn dot fujitsu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qianjh at cn dot fujitsu.com

--- Comment #2 from Qian Jianhua <qianjh at cn dot fujitsu.com> ---
>GCC knows that the multiplication cannot overflow, because replacing the 
>returned expression with __builtin_mul_overflow_p(x, 3, x) is makes it optimise 
>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(=x).

I tested some other cases. 
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".


More information about the Gcc-bugs mailing list