This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/69984] [4.9/5/6] Signed comparison instruction emitted for unsigned variable comparison
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 29 Feb 2016 18:23:04 +0000
- Subject: [Bug tree-optimization/69984] [4.9/5/6] Signed comparison instruction emitted for unsigned variable comparison
- Auto-submitted: auto-generated
- References: <bug-69984-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69984
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Edmar Wienskoski from comment #6)
> Hummm, You are almost convincing me, one last question,
> be patient with me.
>
> As Andrew posted:
> C = A * B
> should be equivalent to:
> C = (unsigned long)( ((int)A) * ((int)B) )
>
> The variables are promoted *before* the multiplication.
> How come (int)65535 multiplied by itself is undefined behavior ?
Because signed integer overflow is undefined. That is if there is an overflow
for int*int, the outcome is undefined. Since GCC Knows both sides of the
multiplier is positive, GCC treats the outcome of the multiply to be also
positive (due to overflow being undefined).