[llvm] 8858340 - [SCEV] Swap operands if LHS is not unknown.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 07:53:00 PDT 2020


Author: Florian Hahn
Date: 2020-09-25T15:50:01+01:00
New Revision: 8858340bd380b821bbad773c7b3a022a9bb5b2d9

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

LOG: [SCEV] Swap operands if LHS is not unknown.

Currently we only use information from guards for unknown expressions.
Swap LHS/RHS and predicate, if LHS is not unknown.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 980c75f3073b..ddca61e996e3 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12593,6 +12593,11 @@ const SCEV* ScalarEvolution::computeMaxBackedgeTakenCount(const Loop *L) {
 const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
   auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
                               const SCEV *RHS, ValueToSCEVMapTy &RewriteMap) {
+    if (!isa<SCEVUnknown>(LHS)) {
+      std::swap(LHS, RHS);
+      Predicate = CmpInst::getSwappedPredicate(Predicate);
+    }
+
     // For now, limit to conditions that provide information about unknown
     // expressions.
     auto *LHSUnknown = dyn_cast<SCEVUnknown>(LHS);

diff  --git a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
index ccc27643f1c9..4696801a0695 100644
--- a/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
+++ b/llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
@@ -28,7 +28,7 @@ exit:
 define void @test_guard_less_than_16_operands_swapped(i32* nocapture %a, i64 %i) {
 ; CHECK-LABEL: Determining loop execution counts for: @test_guard_less_than_16_operands_swapped
 ; CHECK-NEXT:  Loop %loop: backedge-taken count is (15 + (-1 * %i))
-; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
+; CHECK-NEXT:  Loop %loop: max backedge-taken count is 15
 ; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (15 + (-1 * %i))
 ;
 entry:


        


More information about the llvm-commits mailing list