[llvm] 1383cb6 - [ConstFold] Fix incorrect gep inbounds of undef fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 02:14:19 PDT 2024
Author: Nikita Popov
Date: 2024-05-28T11:14:07+02:00
New Revision: 1383cb6e648ba9f4516fa2317f948116c4f35c10
URL: https://github.com/llvm/llvm-project/commit/1383cb6e648ba9f4516fa2317f948116c4f35c10
DIFF: https://github.com/llvm/llvm-project/commit/1383cb6e648ba9f4516fa2317f948116c4f35c10.diff
LOG: [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.
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/InstSimplify/ConstProp/poison.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 4c5e1ce3df7c7..8fce782f47a9c 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 cc498abd9af0f..8fbe5323742df 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
More information about the llvm-commits
mailing list