Skip to content

Commit

Permalink
[SLPVectorizer] Ignore unreachable blocks
Browse files Browse the repository at this point in the history
As the existing test unreachable.ll shows, we should be doing more
work to avoid entering unreachable blocks: we should not stop
vectorization just because a PHI incoming value from an unreachable
block cannot be vectorized. We know that particular value will never
be used so we can just replace it with poison.
  • Loading branch information
hvdijk committed Jun 1, 2021
1 parent 2020c98 commit f126e8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,12 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
// Keeps the reordered operands to avoid code duplication.
SmallVector<ValueList, 2> OperandsVec;
for (unsigned I = 0, E = PH->getNumIncomingValues(); I < E; ++I) {
if (!DT->isReachableFromEntry(PH->getIncomingBlock(I))) {
ValueList Operands(VL.size(), PoisonValue::get(PH->getType()));
TE->setOperand(I, Operands);
OperandsVec.push_back(Operands);
continue;
}
ValueList Operands;
// Prepare the operand vector.
for (Value *V : VL)
Expand Down
11 changes: 3 additions & 8 deletions llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ define void @foo(i32* nocapture %x) #0 {
; CHECK-NEXT: [[T10:%.*]] = load i32, i32* [[T9]], align 4
; CHECK-NEXT: br label [[BB2]]
; CHECK: bb2:
; CHECK-NEXT: [[T1_0:%.*]] = phi i32 [ [[T4]], [[BB1:%.*]] ], [ 2, [[ENTRY:%.*]] ]
; CHECK-NEXT: [[T2_0:%.*]] = phi i32 [ [[T6]], [[BB1]] ], [ 2, [[ENTRY]] ]
; CHECK-NEXT: [[T3_0:%.*]] = phi i32 [ [[T8]], [[BB1]] ], [ 2, [[ENTRY]] ]
; CHECK-NEXT: [[T4_0:%.*]] = phi i32 [ [[T10]], [[BB1]] ], [ 2, [[ENTRY]] ]
; CHECK-NEXT: store i32 [[T1_0]], i32* [[X]], align 4
; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i32> [ poison, [[BB1:%.*]] ], [ <i32 2, i32 2, i32 2, i32 2>, [[ENTRY:%.*]] ]
; CHECK-NEXT: [[T12:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 1
; CHECK-NEXT: store i32 [[T2_0]], i32* [[T12]], align 4
; CHECK-NEXT: [[T13:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 2
; CHECK-NEXT: store i32 [[T3_0]], i32* [[T13]], align 4
; CHECK-NEXT: [[T14:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 3
; CHECK-NEXT: store i32 [[T4_0]], i32* [[T14]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[X]] to <4 x i32>*
; CHECK-NEXT: store <4 x i32> [[TMP0]], <4 x i32>* [[TMP1]], align 4
; CHECK-NEXT: ret void
;
entry:
Expand Down

0 comments on commit f126e8e

Please sign in to comment.