From f126e8ec2873ceedde53d2ccee1a66a83620e9a6 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Tue, 1 Jun 2021 20:21:04 +0100 Subject: [PATCH] [SLPVectorizer] Ignore unreachable blocks 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. --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 6 ++++++ llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll | 11 +++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 31d2c71..90f76c9 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2831,6 +2831,12 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Keeps the reordered operands to avoid code duplication. SmallVector 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) diff --git a/llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll b/llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll index 255d27f..a4793ce 100644 --- a/llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll @@ -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:%.*]] ], [ , [[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: -- 2.7.4