[polly] r314146 - [ScopInfo] Allow invariant loads in branch conditions

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 13:27:15 PDT 2017


Author: grosser
Date: Mon Sep 25 13:27:15 2017
New Revision: 314146

URL: http://llvm.org/viewvc/llvm-project?rev=314146&view=rev
Log:
[ScopInfo] Allow invariant loads in branch conditions

In case the value used in a branch condition is a load instruction, assume this
load to be invariant.

Added:
    polly/trunk/test/ScopInfo/invariant_load_branch_condition.ll
Modified:
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=314146&r1=314145&r2=314146&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Mon Sep 25 13:27:15 2017
@@ -595,6 +595,12 @@ bool ScopDetection::isValidBranch(BasicB
       return true;
   }
 
+  if (auto Load = dyn_cast<LoadInst>(Condition))
+    if (!IsLoopBranch) {
+      Context.RequiredILS.insert(Load);
+      return true;
+    }
+
   // Non constant conditions of branches need to be ICmpInst.
   if (!isa<ICmpInst>(Condition)) {
     if (!IsLoopBranch && AllowNonAffineSubRegions &&

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=314146&r1=314145&r2=314146&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Sep 25 13:27:15 2017
@@ -1540,9 +1540,18 @@ bool buildConditionSets(Scop &S, BasicBl
                         TerminatorInst *TI, Loop *L, __isl_keep isl_set *Domain,
                         DenseMap<BasicBlock *, isl::set> &InvalidDomainMap,
                         SmallVectorImpl<__isl_give isl_set *> &ConditionSets) {
+  ScalarEvolution &SE = *S.getSE();
   isl_set *ConsequenceCondSet = nullptr;
 
-  if (auto *PHI = dyn_cast<PHINode>(Condition)) {
+  if (auto Load = dyn_cast<LoadInst>(Condition)) {
+    const SCEV *LHSSCEV = SE.getSCEVAtScope(Load, L);
+    const SCEV *RHSSCEV = SE.getZero(LHSSCEV->getType());
+    bool NonNeg = false;
+    isl_pw_aff *LHS = getPwAff(S, BB, InvalidDomainMap, LHSSCEV, NonNeg);
+    isl_pw_aff *RHS = getPwAff(S, BB, InvalidDomainMap, RHSSCEV, NonNeg);
+    ConsequenceCondSet =
+        buildConditionSet(ICmpInst::ICMP_SLE, LHS, RHS, Domain);
+  } else if (auto *PHI = dyn_cast<PHINode>(Condition)) {
     auto *Unique = dyn_cast<ConstantInt>(
         getUniqueNonErrorValue(PHI, &S.getRegion(), *S.getLI(), *S.getDT()));
 
@@ -1583,7 +1592,6 @@ bool buildConditionSets(Scop &S, BasicBl
     assert(ICond &&
            "Condition of exiting branch was neither constant nor ICmp!");
 
-    ScalarEvolution &SE = *S.getSE();
     LoopInfo &LI = *S.getLI();
     DominatorTree &DT = *S.getDT();
     Region &R = S.getRegion();

Added: polly/trunk/test/ScopInfo/invariant_load_branch_condition.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/invariant_load_branch_condition.ll?rev=314146&view=auto
==============================================================================
--- polly/trunk/test/ScopInfo/invariant_load_branch_condition.ll (added)
+++ polly/trunk/test/ScopInfo/invariant_load_branch_condition.ll Mon Sep 25 13:27:15 2017
@@ -0,0 +1,51 @@
+; RUN: opt %loadPolly -polly-scops -analyze \
+; RUN:     -polly-invariant-load-hoisting < %s | FileCheck %s
+
+; CHECK:      Invariant Accesses: {
+; CHECK-NEXT:         ReadAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:             [val] -> { Stmt_next[] -> MemRef_ptr[0] };
+; CHECK-NEXT:         Execution Context: [val] -> {  :  }
+; CHECK-NEXT: }
+
+; CHECK: Statements {
+; CHECK-NEXT: 	Stmt_a
+; CHECK-NEXT:         Domain :=
+; CHECK-NEXT:             [val] -> { Stmt_a[] : val = -1 };
+; CHECK-NEXT:         Schedule :=
+; CHECK-NEXT:             [val] -> { Stmt_a[] -> [1, 0] };
+; CHECK-NEXT:         MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:             [val] -> { Stmt_a[] -> MemRef_X[0] };
+; CHECK-NEXT: 	Stmt_loop
+; CHECK-NEXT:         Domain :=
+; CHECK-NEXT:             [val] -> { Stmt_loop[i0] : val = 0 and 0 <= i0 <= 1025 };
+; CHECK-NEXT:         Schedule :=
+; CHECK-NEXT:             [val] -> { Stmt_loop[i0] -> [0, i0] };
+; CHECK-NEXT:         MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:             [val] -> { Stmt_loop[i0] -> MemRef_X[0] };
+; CHECK-NEXT: }
+
+define void @foo(i1* %ptr, float* %X) {
+entry:
+  br label %next
+
+next:
+  %val = load i1, i1* %ptr
+  br i1 %val, label %a, label %loop
+
+a:
+  store float 1.0, float* %X
+  br label %merge
+
+loop:
+  %indvar = phi i64 [0, %next], [%indvar.next, %loop]
+  store float 1.0, float* %X
+  %indvar.next = add nsw i64 %indvar, 1
+  %cmp = icmp sle i64 %indvar, 1024
+  br i1 %cmp, label %loop, label %merge
+
+merge:
+  br label %exit
+
+exit:
+  ret void
+}




More information about the llvm-commits mailing list