aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-05-28 11:08:42 +0200
committerNikita Popov <npopov@redhat.com>2024-05-28 11:14:07 +0200
commit1383cb6e648ba9f4516fa2317f948116c4f35c10 (patch)
tree922c82a09aef4b8b36e73107e64e65ba388f3474 /llvm
parent4d3284cadfa0dc9850d58b97e943481a30c39c1b (diff)
downloadllvm-1383cb6e648ba9f4516fa2317f948116c4f35c10.zip
llvm-1383cb6e648ba9f4516fa2317f948116c4f35c10.tar.gz
llvm-1383cb6e648ba9f4516fa2317f948116c4f35c10.tar.bz2
[ConstFold] Fix incorrect gep inbounds of undef fold
gep inbounds of undef can only be folded to poison if we know that the offset is non-zero. I don't think precise handling here is important, so just drop the inbounds special case. This matches what InstSimplify does.
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp3
-rw-r--r--llvm/test/Transforms/InstSimplify/ConstProp/poison.ll2
2 files changed, 2 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 4c5e1ce..8fce782 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1549,8 +1549,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
return PoisonValue::get(GEPTy);
if (isa<UndefValue>(C))
- // If inbounds, we can choose an out-of-bounds pointer as a base pointer.
- return InBounds ? PoisonValue::get(GEPTy) : UndefValue::get(GEPTy);
+ return UndefValue::get(GEPTy);
auto IsNoOp = [&]() {
// Avoid losing inrange information.
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll b/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll
index cc498ab..8fbe532 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/poison.ll
@@ -104,7 +104,7 @@ define void @vec_aggr_ops() {
define void @other_ops(i8 %x) {
; CHECK-LABEL: @other_ops(
-; CHECK-NEXT: call void (...) @use(i1 poison, i1 poison, i8 poison, i8 poison, ptr poison, ptr poison, ptr poison)
+; CHECK-NEXT: call void (...) @use(i1 poison, i1 poison, i8 poison, i8 poison, ptr poison, ptr undef, ptr undef)
; CHECK-NEXT: ret void
;
%i1 = icmp eq i8 poison, 1