[LLVMdev] `llvm.$op.with.overflow`, InstCombine and ScalarEvolution

Sanjoy Das sanjoy at playingwithpointers.com
Thu Mar 26 23:52:14 PDT 2015


> If we don't care about trying to optimize out overflow checks in
> InstCombine, I'd go with moving the complexity to CGP.

I think instcombine should optimize out overflow checks (as it does
today) without introducing _with_overflow calls.  Are there reasons
why such an approach would not work?

> However, I think
> InstCombine is doing the right thing here by forming these.

I don't quite agree with you on this -- by materializing these
intrinsics InstCombine is making every pass that runs after it less
effective.  All of them have to know about the _with_overflow
intrinsics to optimize IR that it could have otherwise optimized.

Another example is GVN -- `opt -gvn` optimizes away %to.optimize but
`opt -instcombine -gvn` does not.

declare void @side_effect(i1)

define void @foo(i8 %x, i8 %y) {
 entry:
  %sum = add i8 %x, %y
  %e = icmp ugt i8 %x, %sum
  br i1 %e, label %yes, label %no

 yes:
  %to.optimize = icmp ugt i8 %x, %sum
  call void @side_effect(i1 %to.optimize)
  br label %no

 no:
  ret void
}



More information about the llvm-dev mailing list