Skip to content

Commit aa603c4

Browse files
committed
[NFC][LoopPredication] Add parsed checks logging
Differential Revision: https://reviews.llvm.org/D157491
1 parent 3d65f82 commit aa603c4

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,14 +767,23 @@ unsigned LoopPredication::widenChecks(SmallVectorImpl<Value *> &Checks,
767767
return NumWidened;
768768
}
769769

770-
bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
771-
SCEVExpander &Expander) {
770+
static SmallVector<Value *> extractChecksFromGuard(Instruction *Guard) {
772771
LLVM_DEBUG(dbgs() << "Processing guard:\n");
773772
LLVM_DEBUG(Guard->dump());
774773

775-
TotalConsidered++;
776774
SmallVector<Value *, 4> Checks;
777775
parseWidenableGuard(Guard, Checks);
776+
LLVM_DEBUG(dbgs() << "Found checks:\n");
777+
std::for_each(Checks.begin(), Checks.end(), [](const Value *Check) {
778+
LLVM_DEBUG(dbgs() << *Check << "\n");
779+
});
780+
return Checks;
781+
}
782+
783+
bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
784+
SCEVExpander &Expander) {
785+
TotalConsidered++;
786+
auto Checks = extractChecksFromGuard(Guard);
778787
unsigned NumWidened = widenChecks(Checks, Expander, Guard);
779788
if (NumWidened == 0)
780789
return false;
@@ -799,8 +808,6 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
799808
bool LoopPredication::widenWidenableBranchGuardConditions(
800809
BranchInst *BI, SCEVExpander &Expander) {
801810
assert(isGuardAsWidenableBranch(BI) && "Must be!");
802-
LLVM_DEBUG(dbgs() << "Processing guard:\n");
803-
LLVM_DEBUG(BI->dump());
804811

805812
Value *Cond, *WC;
806813
BasicBlock *IfTrueBB, *IfFalseBB;
@@ -809,8 +816,7 @@ bool LoopPredication::widenWidenableBranchGuardConditions(
809816
(void)Parsed;
810817

811818
TotalConsidered++;
812-
SmallVector<Value *, 4> Checks;
813-
parseWidenableGuard(BI, Checks);
819+
auto Checks = extractChecksFromGuard(BI);
814820
// At the moment, our matching logic for wideable conditions implicitly
815821
// assumes we preserve the form: (br (and Cond, WC())). FIXME
816822
Checks.push_back(WC);

llvm/test/Transforms/LoopPredication/visited.ll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -S -passes=loop-predication < %s 2>&1 | FileCheck %s
3-
; RUN: opt -S -passes='require<scalar-evolution>,loop-mssa(loop-predication)' -verify-memoryssa < %s 2>&1 | FileCheck %s
2+
; RUN: opt -S -passes=loop-predication -debug-only=loop-predication < %s 2>&1 | FileCheck %s
3+
; RUN: opt -S -passes='require<scalar-evolution>,loop-mssa(loop-predication)' -verify-memoryssa -debug-only=loop-predication < %s 2>&1 | FileCheck %s
4+
; REQUIRES: asserts
45

56
declare void @llvm.experimental.guard(i1, ...)
67

78
define i32 @test_visited(ptr %array, i32 %length, i32 %n, i32 %x) {
9+
; CHECK: Found checks:
10+
; CHECK-NEXT: %unrelated.cond = icmp eq i32 %x, %i
11+
; CHECK-NEXT: %within.bounds = icmp ult i32 %i, %length
12+
;
813
; CHECK-LABEL: @test_visited(
914
; CHECK-NEXT: entry:
1015
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0

0 commit comments

Comments
 (0)