Skip to content

Commit ec5fe59

Browse files
committed
Don't move VPWidenPointerInductionRecipe, instead fixup location of phi in VPWidenPHI::execute
1 parent 61bd641 commit ec5fe59

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3659,7 +3659,12 @@ void VPReductionPHIRecipe::print(raw_ostream &O, const Twine &Indent,
36593659
void VPWidenPHIRecipe::execute(VPTransformState &State) {
36603660
Value *Op0 = State.get(getOperand(0));
36613661
Type *VecTy = Op0->getType();
3662-
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, Name);
3662+
Instruction *VecPhi = State.Builder.CreatePHI(VecTy, 2, Name);
3663+
// Manually move it with the other PHIs in case PHI recipes above this one
3664+
// also inserted non-phi instructions.
3665+
// TODO: Remove once VPWidenPointerInductionRecipe is also expanded in
3666+
// convertToConcreteRecipes.
3667+
VecPhi->moveBefore(State.Builder.GetInsertBlock()->getFirstNonPHIIt());
36633668
State.set(this, VecPhi);
36643669
}
36653670

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,20 +2511,6 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
25112511
SmallVector<VPRecipeBase *> ToRemove;
25122512
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
25132513
vp_depth_first_deep(Plan.getEntry()))) {
2514-
2515-
// Move VPWidenPointerInductionRecipes to the back of the phis
2516-
// since it may insert non-phi instructions in place, which will
2517-
// interfere with other header phis if they come after.
2518-
//
2519-
// TODO: Expand out VPWidenPointerInductionRecipe into multiple
2520-
// recipes here and remove this
2521-
SmallVector<VPRecipeBase *> PointerIVs;
2522-
for (VPRecipeBase &R : VPBB->phis())
2523-
if (isa<VPWidenPointerInductionRecipe>(R))
2524-
PointerIVs.push_back(&R);
2525-
for (VPRecipeBase *R : PointerIVs)
2526-
R->moveBefore(*VPBB, VPBB->getFirstNonPhi());
2527-
25282514
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
25292515
if (isa<VPCanonicalIVPHIRecipe, VPEVLBasedIVPHIRecipe>(&R)) {
25302516
auto *PhiR = cast<VPHeaderPHIRecipe>(&R);

llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ define i32 @pointer_iv_mixed(ptr noalias %a, ptr noalias %b, i64 %n) #0 {
237237
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
238238
; CHECK: vector.body:
239239
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
240-
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP12:%.*]], [[VECTOR_BODY]] ]
241240
; CHECK-NEXT: [[POINTER_PHI:%.*]] = phi ptr [ [[A]], [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
241+
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP12:%.*]], [[VECTOR_BODY]] ]
242242
; CHECK-NEXT: [[TMP8:%.*]] = shl nuw nsw i64 [[TMP5]], 3
243243
; CHECK-NEXT: [[TMP9:%.*]] = call <vscale x 2 x i64> @llvm.stepvector.nxv2i64()
244244
; CHECK-NEXT: [[TMP10:%.*]] = shl <vscale x 2 x i64> [[TMP9]], splat (i64 2)

llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ define ptr @test_first_order_recurrences_and_pointer_induction2(ptr %ptr) {
587587
; CHECK-NEXT: br label %vector.body
588588
; CHECK: vector.body:
589589
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
590-
; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x ptr> [ <ptr poison, ptr poison, ptr poison, ptr null>, %vector.ph ], [ [[TMP0:%.*]], %vector.body ]
591590
; CHECK-NEXT: [[POINTER_PHI:%.*]] = phi ptr [ [[PTR]], %vector.ph ], [ [[PTR_IND:%.*]], %vector.body ]
591+
; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x ptr> [ <ptr poison, ptr poison, ptr poison, ptr null>, %vector.ph ], [ [[TMP0:%.*]], %vector.body ]
592592
; CHECK-NEXT: [[TMP0]] = getelementptr i8, ptr [[POINTER_PHI]], <4 x i64> <i64 0, i64 4, i64 8, i64 12>
593593
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds ptr, ptr [[PTR]], i64 [[INDEX]]
594594
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds ptr, ptr [[TMP3]], i32 0

llvm/test/Transforms/LoopVectorize/pointer-induction.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ for.end: ; preds = %for.cond
283283
ret void
284284
}
285285

286-
; Test that WidenPointerInductionRecipes are ordered after the other header phis
286+
; Test that when WidenPointerInductionRecipes are ordered before other
287+
; WidenIntOrFpInductionRecipes that their PHIs are emitted in the right place.
287288
define void @outside_lattice(ptr noalias %p, ptr noalias %q, i32 %n) {
288289
; DEFAULT-LABEL: @outside_lattice(
289290
; DEFAULT-NEXT: entry:
@@ -305,8 +306,8 @@ define void @outside_lattice(ptr noalias %p, ptr noalias %q, i32 %n) {
305306
; DEFAULT-NEXT: br label [[VECTOR_BODY:%.*]]
306307
; DEFAULT: vector.body:
307308
; DEFAULT-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
308-
; DEFAULT-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
309309
; DEFAULT-NEXT: [[POINTER_PHI:%.*]] = phi ptr [ null, [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
310+
; DEFAULT-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
310311
; DEFAULT-NEXT: [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <4 x i64> <i64 0, i64 4, i64 8, i64 12>
311312
; DEFAULT-NEXT: [[OFFSET_IDX:%.*]] = trunc i64 [[INDEX]] to i32
312313
; DEFAULT-NEXT: [[TMP5:%.*]] = getelementptr inbounds ptr, ptr [[P:%.*]], i32 [[OFFSET_IDX]]
@@ -361,8 +362,8 @@ define void @outside_lattice(ptr noalias %p, ptr noalias %q, i32 %n) {
361362
; STRIDED-NEXT: br label [[VECTOR_BODY:%.*]]
362363
; STRIDED: vector.body:
363364
; STRIDED-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
364-
; STRIDED-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
365365
; STRIDED-NEXT: [[POINTER_PHI:%.*]] = phi ptr [ null, [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
366+
; STRIDED-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
366367
; STRIDED-NEXT: [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <4 x i64> <i64 0, i64 4, i64 8, i64 12>
367368
; STRIDED-NEXT: [[OFFSET_IDX:%.*]] = trunc i64 [[INDEX]] to i32
368369
; STRIDED-NEXT: [[TMP5:%.*]] = getelementptr inbounds ptr, ptr [[P:%.*]], i32 [[OFFSET_IDX]]

0 commit comments

Comments
 (0)