This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/57503] [6/7/8 Regression] Wrong extension of multiply operand
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 15 Jan 2018 19:01:25 +0000
- Subject: [Bug tree-optimization/57503] [6/7/8 Regression] Wrong extension of multiply operand
- Auto-submitted: auto-generated
- References: <bug-57503-4@http.gcc.gnu.org/bugzilla/>
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.