[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
clattner at apple.com
Thu Jun 28 09:55:55 PDT 2007
On Jun 28, 2007, at 3:09 AM, Duncan Sands wrote:
>>> It seems like folding undef/X to undef isn't safe either though,
>>> the way it sounds like undef is intended to work. This code:
>>> %x = udiv i32 undef, %intmax
>>> %y = udiv i32 %x, 2
>>> will always set %y to 0. Maybe instcombine can fold the second
>>> udiv by looking through its operands, but it can't safely fold the
>>> first. The best it could do is try to fold away all of %x's uses so
>>> that %x isn't needed anymore.
> presumably undef/X should be folded to 0. [This means that undef/0
> folded to 0, not sure if that's OK].
Ah, duncan's right. I confused myself.
We can fold undef/x -> 0 because there is some value of the undef
where it is always safe to produce zero for any x. In particular, if
the undef was 0, x can be anything (if it is also zero, the result is
undefined, so zero is fine).
More information about the llvm-commits