This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]