This should be NFC: it's just to make it clear in the docs that shift returns a poison value if shift amount >= bitwidth (and not an undef value).
A few instcombine optimizations rely on this already.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
A few instcombine optimizations rely on this already.
Can you please give one or two examples?
This one for example (stole from Dave; I don't have my list here handy):
rewrite (1 << Y) * X into X << Y:
%Op0 = shl 1, %Y
%r = mul %Op0, %Op1
=>
%r = shl %Op1, %Y
With shl yielding undef this optimization is incorrect:
ERROR: Mismatch in values for i4 %r
Example:
i4 %Y = 0x8 (8, -8)
i4 %Op0 = 0x0 (0)
i4 %Op1 = 0x0 (0)
source: 0x0 (0)
target: 0x1 (1)
Looking over LangRef, I think these are the operations which can return undef given operands that aren't undef/poison, and are likely reasonable to change over to return poison:
- sitofp and friends (if the result is out of range)
- llvm.ctlz.* and friends (is_zero_undef)
- shufflevector (undef elements in shuffle mask)
- shl and friends (shift amount out of range)
- alloca (allocating zero bytes)
- insertelement/extractelement (element index out of range)
- certain operations involving the result of an inrange GEP (see http://llvm.org/docs/LangRef.html#getelementptr-instruction)
If we're committing to killing undef, I think switching all of these to do something other than return undef is fine as an intermediate step... but please send a proposal to llvmdev outlining what's changing (or not really changing, as the case may be), and how it interacts with the general undef/poison/freeze plan.
(The other places I can find that say we return undef are loads and fast-math floating-point operations. Loads are obviously special, and the description of nnan/ninf should probably say it returns an unspecified value rather than undef.)
Thanks, can you please put this in the commit message? Other than that this LGTM, but I also agree with what Eli said.
rewrite (1 << Y) * X into X << Y:
%Op0 = shl 1, %Y
%r = mul %Op0, %Op1=>%r = shl %Op1, %Y
With shl yielding undef this optimization is incorrect:
ERROR: Mismatch in values for i4 %r
Example:
i4 %Y = 0x8 (8, -8)
i4 %Op0 = 0x0 (0)
i4 %Op1 = 0x0 (0)
source: 0x0 (0)
target: 0x1 (1)