[llvm] d23da7d - [InstCombine] Increase recursion limit to 3 in `simplifyNonNullOperand` (#128695)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 25 06:19:29 PST 2025
Author: Yingwei Zheng
Date: 2025-02-25T22:19:25+08:00
New Revision: d23da7d6300ec6732b462d475c331f289170cb83
URL: https://github.com/llvm/llvm-project/commit/d23da7d6300ec6732b462d475c331f289170cb83
DIFF: https://github.com/llvm/llvm-project/commit/d23da7d6300ec6732b462d475c331f289170cb83.diff
LOG: [InstCombine] Increase recursion limit to 3 in `simplifyNonNullOperand` (#128695)
Address review comment
https://github.com/llvm/llvm-project/pull/128466#discussion_r1967228790
Compile-time impact:
https://llvm-compile-time-tracker.com/compare.php?from=72781f58efddecee19feb07fec4e6104ef4c4812&to=3853aee61626b0eda06671b4cbbc4cdd1344440c&stat=instructions:u
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/load.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 622884ea1eb46..221511e9aba0b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -996,7 +996,8 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
if (!V->hasOneUse())
return nullptr;
- if (Depth == 1)
+ constexpr unsigned RecursionLimit = 3;
+ if (Depth == RecursionLimit)
return nullptr;
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
diff --git a/llvm/test/Transforms/InstCombine/load.ll b/llvm/test/Transforms/InstCombine/load.ll
index a5ad1e0c21526..d10aabff6709a 100644
--- a/llvm/test/Transforms/InstCombine/load.ll
+++ b/llvm/test/Transforms/InstCombine/load.ll
@@ -451,3 +451,33 @@ define i32 @load_select_with_null_gep(i1 %cond, ptr %p, i64 %off) {
%res = load i32, ptr %gep, align 4
ret i32 %res
}
+
+define i16 @load_select_with_null_gep2(i1 %cond, ptr %p, i64 %x) {
+; CHECK-LABEL: @load_select_with_null_gep2(
+; CHECK-NEXT: [[INVARIANT_GEP:%.*]] = getelementptr i8, ptr [[SEL:%.*]], i64 -2
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[INVARIANT_GEP]], i64 [[X:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = load i16, ptr [[GEP]], align 2
+; CHECK-NEXT: ret i16 [[RES]]
+;
+ %sel = select i1 %cond, ptr %p, ptr null
+ %invariant.gep = getelementptr i8, ptr %sel, i64 -2
+ %gep = getelementptr i16, ptr %invariant.gep, i64 %x
+ %res = load i16, ptr %gep, align 2
+ ret i16 %res
+}
+
+define i16 @load_select_with_null_gep3(i1 %cond, ptr %p, i64 %x, i64 %y) {
+; CHECK-LABEL: @load_select_with_null_gep3(
+; CHECK-NEXT: [[INVARIANT_GEP:%.*]] = getelementptr i8, ptr [[SEL:%.*]], i64 -2
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[INVARIANT_GEP]], i64 [[X:%.*]]
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i16, ptr [[GEP]], i64 [[Y:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = load i16, ptr [[GEP2]], align 2
+; CHECK-NEXT: ret i16 [[RES]]
+;
+ %sel = select i1 %cond, ptr %p, ptr null
+ %invariant.gep = getelementptr i8, ptr %sel, i64 -2
+ %gep = getelementptr i16, ptr %invariant.gep, i64 %x
+ %gep2 = getelementptr i16, ptr %gep, i64 %y
+ %res = load i16, ptr %gep2, align 2
+ ret i16 %res
+}
More information about the llvm-commits
mailing list