Skip to content

Commit 64b4879

Browse files
haonanya1petrhosek
authored andcommitted
[InstCombine][foldPHIArgGEPIntoPHI] Early return for const vector index for gep inst (#138661)
1 parent 947a33c commit 64b4879

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
574574
// substantially cheaper to compute for the constants, so making it a
575575
// variable index could pessimize the path. This also handles the case
576576
// for struct indices, which must always be constant.
577-
if (isa<ConstantInt>(FirstInst->getOperand(Op)) ||
578-
isa<ConstantInt>(GEP->getOperand(Op)))
577+
if (isa<Constant>(FirstInst->getOperand(Op)) ||
578+
isa<Constant>(GEP->getOperand(Op)))
579579
return nullptr;
580580

581581
if (FirstInst->getOperand(Op)->getType() !=
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
4+
%foo = type { i16, i16, i16 }
5+
6+
define <16 x ptr> @test(i1 %tobool) {
7+
; CHECK-LABEL: define <16 x ptr> @test(
8+
; CHECK-SAME: i1 [[TOBOOL:%.*]]) {
9+
; CHECK-NEXT: [[ENTRY:.*:]]
10+
; CHECK-NEXT: [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16
11+
; CHECK-NEXT: [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0
12+
; CHECK-NEXT: br i1 [[TOBOOL]], label %[[F1:.*]], label %[[F0:.*]]
13+
; CHECK: [[F0]]:
14+
; CHECK-NEXT: [[MM_VECTORGEP:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> splat (i32 1)
15+
; CHECK-NEXT: br label %[[MERGE:.*]]
16+
; CHECK: [[F1]]:
17+
; CHECK-NEXT: [[MM_VECTORGEP2:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> zeroinitializer, <16 x i32> splat (i32 2)
18+
; CHECK-NEXT: br label %[[MERGE]]
19+
; CHECK: [[MERGE]]:
20+
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP]], %[[F0]] ], [ [[MM_VECTORGEP2]], %[[F1]] ]
21+
; CHECK-NEXT: ret <16 x ptr> [[VEC_PHI]]
22+
;
23+
entry:
24+
%lane.0 = alloca %foo, align 16
25+
%lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0
26+
%mm_vectorGEP = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 1)
27+
%mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 2)
28+
br i1 %tobool, label %f1, label %f0
29+
30+
f0:
31+
br label %merge
32+
33+
f1:
34+
br label %merge
35+
36+
merge:
37+
%vec.phi = phi <16 x ptr> [ %mm_vectorGEP, %f0], [ %mm_vectorGEP2, %f1 ]
38+
ret <16 x ptr> %vec.phi
39+
}

0 commit comments

Comments
 (0)