[LLVMdev] Instruction combiner multiplication canonicalization
Nema, Ashutosh
Ashutosh.Nema at amd.com
Thu Apr 16 04:40:47 PDT 2015
Thanks Sanjoy for detailed explanation.
I got your point, there is a possibility of overflow.
Hence we can't do explained transformation.
Regards,
Ashutosh
-----Original Message-----
From: Sanjoy Das [mailto:sanjoy at playingwithpointers.com]
Sent: Wednesday, April 15, 2015 10:43 PM
To: Nema, Ashutosh
Cc: llvmdev at cs.uiuc.edu; Nick Lewycky
Subject: Re: Instruction combiner multiplication canonicalization
> Consider following scenarios:
> 1) If input is ((X+C1)*C2)<nsw>
> Then post canonicalization output should be (X*C2+C1*C2) <nsw>
Say X = INT_SMAX, C1 = C2 = 1.
Then (X + C1) = INT_SMIN and INT_SMIN * 1 does not overflow.
But X*C2 = INT_SMAX and C1*C2 = 1 and INT_SMAX + 1 does sign overflow.
> 2) If input is (((X+C1)<nsw>)*C2)<nsw>
> Then post canonicalization output should be ((X*C2) <nsw>+(C1*C2) <nsw>)
> <nsw>
This is more interesting, let X = INT_SMIN, C1 = 1, C2 -1.
Then the first set of operations don't sign overflow. But X * C2 =
INT_SMIN * -1 will sign overflow
-- Sanjoy
More information about the llvm-dev
mailing list