[Bug tree-optimization/94757] New: GCC does not optimise unsigned multiplication known not to overflow
felix.von.s at posteo dot de
gcc-bugzilla@gcc.gnu.org
Sat Apr 25 08:55:08 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94757
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 <limits.h>
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 multiplication).
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.
More information about the Gcc-bugs
mailing list