diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -767,14 +767,23 @@ return NumWidened; } -bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, - SCEVExpander &Expander) { +static SmallVector extractChecksFromGuard(Instruction *Guard) { LLVM_DEBUG(dbgs() << "Processing guard:\n"); LLVM_DEBUG(Guard->dump()); - TotalConsidered++; SmallVector Checks; parseWidenableGuard(Guard, Checks); + LLVM_DEBUG(dbgs() << "Found checks:\n"); + std::for_each(Checks.begin(), Checks.end(), [](const Value *Check) { + LLVM_DEBUG(dbgs() << *Check << "\n"); + }); + return Checks; +} + +bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, + SCEVExpander &Expander) { + TotalConsidered++; + auto Checks = extractChecksFromGuard(Guard); unsigned NumWidened = widenChecks(Checks, Expander, Guard); if (NumWidened == 0) return false; @@ -799,8 +808,6 @@ bool LoopPredication::widenWidenableBranchGuardConditions( BranchInst *BI, SCEVExpander &Expander) { assert(isGuardAsWidenableBranch(BI) && "Must be!"); - LLVM_DEBUG(dbgs() << "Processing guard:\n"); - LLVM_DEBUG(BI->dump()); Value *Cond, *WC; BasicBlock *IfTrueBB, *IfFalseBB; @@ -809,8 +816,7 @@ (void)Parsed; TotalConsidered++; - SmallVector Checks; - parseWidenableGuard(BI, Checks); + auto Checks = extractChecksFromGuard(BI); // At the moment, our matching logic for wideable conditions implicitly // assumes we preserve the form: (br (and Cond, WC())). FIXME Checks.push_back(WC); diff --git a/llvm/test/Transforms/LoopPredication/visited.ll b/llvm/test/Transforms/LoopPredication/visited.ll --- a/llvm/test/Transforms/LoopPredication/visited.ll +++ b/llvm/test/Transforms/LoopPredication/visited.ll @@ -1,10 +1,15 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -passes=loop-predication < %s 2>&1 | FileCheck %s -; RUN: opt -S -passes='require,loop-mssa(loop-predication)' -verify-memoryssa < %s 2>&1 | FileCheck %s +; RUN: opt -S -passes=loop-predication -debug-only=loop-predication < %s 2>&1 | FileCheck %s +; RUN: opt -S -passes='require,loop-mssa(loop-predication)' -verify-memoryssa -debug-only=loop-predication < %s 2>&1 | FileCheck %s +; REQUIRES: asserts declare void @llvm.experimental.guard(i1, ...) define i32 @test_visited(ptr %array, i32 %length, i32 %n, i32 %x) { +; CHECK: Found checks: +; CHECK-NEXT: %unrelated.cond = icmp eq i32 %x, %i +; CHECK-NEXT: %within.bounds = icmp ult i32 %i, %length +; ; CHECK-LABEL: @test_visited( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[N:%.*]], 0