Skip to content

Commit 1383cb6

Browse files
committed
[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.
1 parent 4d3284c commit 1383cb6

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
15491549
return PoisonValue::get(GEPTy);
15501550

15511551
if (isa<UndefValue>(C))
1552-
// If inbounds, we can choose an out-of-bounds pointer as a base pointer.
1553-
return InBounds ? PoisonValue::get(GEPTy) : UndefValue::get(GEPTy);
1552+
return UndefValue::get(GEPTy);
15541553

15551554
auto IsNoOp = [&]() {
15561555
// Avoid losing inrange information.

llvm/test/Transforms/InstSimplify/ConstProp/poison.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ define void @vec_aggr_ops() {
104104

105105
define void @other_ops(i8 %x) {
106106
; CHECK-LABEL: @other_ops(
107-
; CHECK-NEXT: call void (...) @use(i1 poison, i1 poison, i8 poison, i8 poison, ptr poison, ptr poison, ptr poison)
107+
; CHECK-NEXT: call void (...) @use(i1 poison, i1 poison, i8 poison, i8 poison, ptr poison, ptr undef, ptr undef)
108108
; CHECK-NEXT: ret void
109109
;
110110
%i1 = icmp eq i8 poison, 1

0 commit comments

Comments
 (0)