Revert "[InstCombine] propagate 'nsw' on pointer difference of 'inbounds' geps (PR47430)"
This reverts commit 324a53205a3af979e3de109fdd52f91781816cba.
On closer examination of at least one of the test diffs,
this does not appear to be correct in all cases. Even the
existing 'nsw' creation may be wrong based on this example:
https://alive2.llvm.org/ce/z/uL4Hw9
https://alive2.llvm.org/ce/z/fJMKQS
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index a5dd8f6..5ce32bc 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1671,12 +1671,11 @@
I->getOpcode() == Instruction::Mul)
I->setHasNoUnsignedWrap();
- // If we have a 2nd GEP of the same base pointer, subtract the offsets.
- // If both GEPs are inbounds, then the subtract does not have signed overflow.
+ // If we had a constant expression GEP on the other side offsetting the
+ // pointer, subtract it from the offset we have.
if (GEP2) {
Value *Offset = EmitGEPOffset(GEP2);
- Result = Builder.CreateSub(Result, Offset, "gepdiff", /* NUW */ false,
- GEP1->isInBounds() && GEP2->isInBounds());
+ Result = Builder.CreateSub(Result, Offset, "gepdiff");
}
// If we have p - gep(p, ...) then we have to negate the result.