Skip to content

Commit 7c836e2

Browse files
committed
[VPlan] Invert condition if needed when creating inner regions.
1 parent f97b7fd commit 7c836e2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ static void introduceInnerLoopRegions(VPlan &Plan) {
3636
continue;
3737
assert(VPDT.dominates(PreheaderVPBB, HeaderVPBB) &&
3838
"preheader must dominate header");
39+
if (LatchVPBB->getSuccessors()[1] != HeaderVPBB) {
40+
auto *Term = cast<VPBasicBlock>(LatchVPBB)->getTerminator();
41+
auto *Not = new VPInstruction(VPInstruction::Not, {Term->getOperand(0)});
42+
Not->insertBefore(Term);
43+
Term->setOperand(0, Not);
44+
}
45+
3946
VPBlockUtils::disconnectBlocks(PreheaderVPBB, HeaderVPBB);
4047
VPBlockUtils::disconnectBlocks(LatchVPBB, HeaderVPBB);
4148
VPBlockBase *Succ = LatchVPBB->getSingleSuccessor();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
5151
make_early_inc_range(make_range(VPBB->begin(), EndIter))) {
5252

5353
VPValue *VPV = Ingredient.getVPSingleValue();
54+
if (!VPV->getUnderlyingValue())
55+
continue;
56+
5457
Instruction *Inst = cast<Instruction>(VPV->getUnderlyingValue());
5558

5659
VPRecipeBase *NewRecipe = nullptr;

llvm/test/Transforms/LoopVectorize/outer-loop-inner-latch-successors.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
@A = common global [1024 x i64] zeroinitializer, align 16
55
@B = common global [1024 x i64] zeroinitializer, align 16
66

7-
; FIXME: The exit condition of the inner loop is incorrect when vectorizing.
87
define void @inner_latch_header_first_successor(i64 %N, i32 %c, i64 %M) {
98
; CHECK-LABEL: define void @inner_latch_header_first_successor(
109
; CHECK-SAME: i64 [[N:%.*]], i32 [[C:%.*]], i64 [[M:%.*]]) {
@@ -35,8 +34,9 @@ define void @inner_latch_header_first_successor(i64 %N, i32 %c, i64 %M) {
3534
; CHECK-NEXT: [[TMP3]] = add nsw <4 x i64> [[TMP2]], [[VEC_PHI4]]
3635
; CHECK-NEXT: [[TMP4]] = add nuw nsw <4 x i64> [[VEC_PHI]], splat (i64 1)
3736
; CHECK-NEXT: [[TMP5:%.*]] = icmp ne <4 x i64> [[TMP4]], [[BROADCAST_SPLAT2]]
38-
; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0
39-
; CHECK-NEXT: br i1 [[TMP6]], label %[[VECTOR_LATCH]], label %[[INNER3]]
37+
; CHECK-NEXT: [[TMP6:%.*]] = xor <4 x i1> [[TMP5]], splat (i1 true)
38+
; CHECK-NEXT: [[TMP9:%.*]] = extractelement <4 x i1> [[TMP6]], i32 0
39+
; CHECK-NEXT: br i1 [[TMP9]], label %[[VECTOR_LATCH]], label %[[INNER3]]
4040
; CHECK: [[VECTOR_LATCH]]:
4141
; CHECK-NEXT: [[VEC_PHI6:%.*]] = phi <4 x i64> [ [[TMP3]], %[[INNER3]] ]
4242
; CHECK-NEXT: call void @llvm.masked.scatter.v4i64.v4p0(<4 x i64> [[VEC_PHI6]], <4 x ptr> [[TMP0]], i32 4, <4 x i1> splat (i1 true))

0 commit comments

Comments
 (0)