[llvm] 5b8664f - [InstCombine][foldPHIArgGEPIntoPHI] Early return for const vector index for gep inst (#138661)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 01:00:53 PDT 2025
Author: haonan
Date: 2025-05-08T10:00:49+02:00
New Revision: 5b8664fcb253fbd9eb0e83db3c1c0e19dd2499ef
URL: https://github.com/llvm/llvm-project/commit/5b8664fcb253fbd9eb0e83db3c1c0e19dd2499ef
DIFF: https://github.com/llvm/llvm-project/commit/5b8664fcb253fbd9eb0e83db3c1c0e19dd2499ef.diff
LOG: [InstCombine][foldPHIArgGEPIntoPHI] Early return for const vector index for gep inst (#138661)
Added:
llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
Modified:
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 80308bf92dbbc..a842a5edcb8a3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -574,8 +574,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
// substantially cheaper to compute for the constants, so making it a
// variable index could pessimize the path. This also handles the case
// for struct indices, which must always be constant.
- if (isa<ConstantInt>(FirstInst->getOperand(Op)) ||
- isa<ConstantInt>(GEP->getOperand(Op)))
+ if (isa<Constant>(FirstInst->getOperand(Op)) ||
+ isa<Constant>(GEP->getOperand(Op)))
return nullptr;
if (FirstInst->getOperand(Op)->getType() !=
diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
new file mode 100644
index 0000000000000..0bbb1035b1093
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+%foo = type { i16, i16, i16 }
+
+define <16 x ptr> @test(i1 %tobool) {
+; CHECK-LABEL: define <16 x ptr> @test(
+; CHECK-SAME: i1 [[TOBOOL:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16
+; CHECK-NEXT: [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0
+; CHECK-NEXT: br i1 [[TOBOOL]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK: [[F0]]:
+; CHECK-NEXT: [[MM_VECTORGEP:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> splat (i32 1)
+; CHECK-NEXT: br label %[[MERGE:.*]]
+; CHECK: [[F1]]:
+; CHECK-NEXT: [[MM_VECTORGEP2:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> splat (i32 2)
+; CHECK-NEXT: br label %[[MERGE]]
+; CHECK: [[MERGE]]:
+; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP]], %[[F0]] ], [ [[MM_VECTORGEP2]], %[[F1]] ]
+; CHECK-NEXT: ret <16 x ptr> [[VEC_PHI]]
+;
+entry:
+ %lane.0 = alloca %foo, align 16
+ %lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0
+ %mm_vectorGEP = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 1)
+ %mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 2)
+ br i1 %tobool, label %f1, label %f0
+
+f0:
+ br label %merge
+
+f1:
+ br label %merge
+
+merge:
+ %vec.phi = phi <16 x ptr> [ %mm_vectorGEP, %f0], [ %mm_vectorGEP2, %f1 ]
+ ret <16 x ptr> %vec.phi
+}
More information about the llvm-commits
mailing list