[InstSimplify] Allow gep inbounds x, 0 -> x in non-refining op replacement
authorNikita Popov <npopov@redhat.com>
Fri, 14 Jul 2023 14:14:50 +0000 (16:14 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 14 Jul 2023 14:14:50 +0000 (16:14 +0200)
commit547544112b60da4c6a75210ca4fc6e3bd05914ec
treee211b0ee35ac23df89301568a33e4d26edf398f8
parent91b84811ab11ea169cb8ac3d6ccf8a4b8740ec98
[InstSimplify] Allow gep inbounds x, 0 -> x in non-refining op replacement

After the semantics change from https://reviews.llvm.org/D154051,
gep inbounds x, 0 can no longer produce poison. As such, we can
also perform this fold during non-refining operand replacement
and avoid unnecessary drops of the inbounds flag.

The online alive2 version has not been update to the new
semantics yet, but we can use the following proof locally:

    define ptr @src(ptr %base, i64 %offset) {
      %cmp = icmp eq i64 %offset, 0
      %gep = getelementptr inbounds i8, ptr %base, i64 %offset
      %sel = select i1 %cmp, ptr %base, ptr %gep
      ret ptr %sel
    }

    define ptr @tgt(ptr %base, i64 %offset) {
      %gep = getelementptr inbounds i8, ptr %base, i64 %offset
      ret ptr %gep
    }
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/select.ll