[Bug tree-optimization/57503] [6/7/8 Regression] Wrong extension of multiply operand

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 15 19:02:00 GMT 2018


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

--- Comment #18 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Georg-Johann Lay from comment #17)
> Obervation that -fno-wrapv also leads to correct code, hence there is
> somewhere a wrong assumption that signed overflow occurs (which doesn't).

(you probably meant -fwrapv instead of -fno-wrapv?)
Why do you say wrong?
unsigned ab = a * b;
in C, that means:
unsigned ab = (int)a * (int)b;
Since a is in [0, 255], so is (int)a. Multiplication may not overflow for a
signed type, so (int)a*(int)b must be nonnegative. Converting it to long
directly or through unsigned int is thus equivalent.


More information about the Gcc-bugs mailing list