[llvm] aa603c4 - [NFC][LoopPredication] Add parsed checks logging

Aleksandr Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 04:23:52 PDT 2023


Author: Aleksandr Popov
Date: 2023-08-10T12:50:32+02:00
New Revision: aa603c41caab63e246f4a4258c8b96e6ea06fdc9

URL: https://github.com/llvm/llvm-project/commit/aa603c41caab63e246f4a4258c8b96e6ea06fdc9
DIFF: https://github.com/llvm/llvm-project/commit/aa603c41caab63e246f4a4258c8b96e6ea06fdc9.diff

LOG: [NFC][LoopPredication] Add parsed checks logging

Differential Revision: https://reviews.llvm.org/D157491

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopPredication.cpp
    llvm/test/Transforms/LoopPredication/visited.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index 79a3da9020e2e2..29d8e37d31955c 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -767,14 +767,23 @@ unsigned LoopPredication::widenChecks(SmallVectorImpl<Value *> &Checks,
   return NumWidened;
 }
 
-bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard,
-                                           SCEVExpander &Expander) {
+static SmallVector<Value *> extractChecksFromGuard(Instruction *Guard) {
   LLVM_DEBUG(dbgs() << "Processing guard:\n");
   LLVM_DEBUG(Guard->dump());
 
-  TotalConsidered++;
   SmallVector<Value *, 4> 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::widenGuardConditions(IntrinsicInst *Guard,
 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 @@ bool LoopPredication::widenWidenableBranchGuardConditions(
   (void)Parsed;
 
   TotalConsidered++;
-  SmallVector<Value *, 4> 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
index cc713313799a7a..efefa0f1156369 100644
--- 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<scalar-evolution>,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<scalar-evolution>,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


        


More information about the llvm-commits mailing list