Skip to content

Commit 7b96f8d

Browse files
committed
[LV] Strip unreachable SCEV-check blocks
emitSCEVChecks checks if SCEVCheckCond matches zero, and returns nullptr. However, it sets SCEVCheckCond as used before it does this, which prevents it from being removed during cleanup, resulting in unreachable blocks being emitted. Fix this.
1 parent 80bdfcd commit 7b96f8d

File tree

3 files changed

+2
-10
lines changed

3 files changed

+2
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,15 +2095,13 @@ class GeneratedRTChecks {
20952095
/// depending on the generated condition.
20962096
BasicBlock *emitSCEVChecks(BasicBlock *Bypass,
20972097
BasicBlock *LoopVectorPreHeader) {
2098-
if (!SCEVCheckCond)
2098+
using namespace llvm::PatternMatch;
2099+
if (!SCEVCheckCond || match(SCEVCheckCond, m_ZeroInt()))
20992100
return nullptr;
21002101

21012102
Value *Cond = SCEVCheckCond;
21022103
// Mark the check as used, to prevent it from being removed during cleanup.
21032104
SCEVCheckCond = nullptr;
2104-
if (auto *C = dyn_cast<ConstantInt>(Cond))
2105-
if (C->isZero())
2106-
return nullptr;
21072105

21082106
auto *Pred = LoopVectorPreHeader->getSinglePredecessor();
21092107

llvm/test/Transforms/LoopVectorize/AArch64/conditional-branches-cost.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,6 @@ define void @multiple_exit_conditions(ptr %src, ptr noalias %dst) #1 {
793793
; DEFAULT-NEXT: [[BC_RESUME_VAL:%.*]] = phi ptr [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DST]], [[ENTRY:%.*]] ]
794794
; DEFAULT-NEXT: [[BC_RESUME_VAL1:%.*]] = phi i64 [ 512, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
795795
; DEFAULT-NEXT: br label [[LOOP:%.*]]
796-
; DEFAULT: vector.scevcheck:
797-
; DEFAULT-NEXT: unreachable
798796
; DEFAULT: loop:
799797
; DEFAULT-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP]] ]
800798
; DEFAULT-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
@@ -857,8 +855,6 @@ define void @multiple_exit_conditions(ptr %src, ptr noalias %dst) #1 {
857855
; PRED-NEXT: [[BC_RESUME_VAL:%.*]] = phi ptr [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[DST]], [[ENTRY:%.*]] ]
858856
; PRED-NEXT: [[BC_RESUME_VAL2:%.*]] = phi i64 [ [[IND_END1]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ]
859857
; PRED-NEXT: br label [[LOOP:%.*]]
860-
; PRED: vector.scevcheck:
861-
; PRED-NEXT: unreachable
862858
; PRED: loop:
863859
; PRED-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP]] ]
864860
; PRED-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]

llvm/test/Transforms/LoopVectorize/X86/pr36524.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ define void @foo(ptr %ptr, ptr %ptr.2) {
4040
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 80, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
4141
; CHECK-NEXT: [[BC_RESUME_VAL2:%.*]] = phi i64 [ 82, [[MIDDLE_BLOCK]] ], [ 2, [[ENTRY]] ], [ 2, [[VECTOR_MEMCHECK]] ]
4242
; CHECK-NEXT: br label [[LOOP:%.*]]
43-
; CHECK: vector.scevcheck:
44-
; CHECK-NEXT: unreachable
4543
; CHECK: loop:
4644
; CHECK-NEXT: [[CAN_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[CAN_IV_NEXT:%.*]], [[LOOP]] ]
4745
; CHECK-NEXT: [[TMP9:%.*]] = phi i64 [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ], [ [[TMP12:%.*]], [[LOOP]] ]

0 commit comments

Comments
 (0)