[polly] r233477 - Code generate parameters and run-time checks after branching new code region

Tobias Grosser tobias at grosser.es
Sat Mar 28 02:34:41 PDT 2015


Author: grosser
Date: Sat Mar 28 04:34:40 2015
New Revision: 233477

URL: http://llvm.org/viewvc/llvm-project?rev=233477&view=rev
Log:
Code generate parameters and run-time checks after branching new code region

When creating parameters the SCEVexpander may introduce new induction variables,
that possibly create scalar dependences in the original scop, before we code
generate the scop. The resulting scalar dependences may then inhibit correct
code generation of the scop. To prevent this, we first version the code without
a run-time check and only then introduce new parameters and the run-time
condition. The if-condition that guards the original scop from being modified by
the SCEVexpander.

This change causes some test case changes as the run-time conditions are now
introduced in the split basic block rather than in the entry basic block.

This fixes http://llvm.org/PR22069

Test case reduced by: Karthik Senthil

Added:
    polly/trunk/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
Modified:
    polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
    polly/trunk/test/Isl/CodeGen/aliasing_different_pointer_types.ll
    polly/trunk/test/Isl/CodeGen/multidim_2d_parametric_array_static_loop_bounds.ll
    polly/trunk/test/Isl/CodeGen/run-time-condition-with-scev-parameters.ll

Modified: polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslCodeGeneration.cpp?rev=233477&r1=233476&r2=233477&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/IslCodeGeneration.cpp Sat Mar 28 04:34:40 2015
@@ -977,10 +977,20 @@ public:
     PollyIRBuilder Builder = createPollyIRBuilder(EnteringBB, Annotator);
 
     IslNodeBuilder NodeBuilder(Builder, Annotator, this, *DL, *LI, *SE, *DT, S);
-    NodeBuilder.addParameters(S.getContext());
 
+    // Only build the run-time condition and parameters _after_ having
+    // introduced the conditional branch. This is important as the conditional
+    // branch will guard the original scop from new induction variables that
+    // the SCEVExpander may introduce while code generating the parameters and
+    // which may introduce scalar dependences that prevent us from correctly
+    // code generating this scop.
+    BasicBlock *StartBlock =
+        executeScopConditionally(S, this, Builder.getTrue());
+    auto SplitBlock = StartBlock->getSinglePredecessor();
+    Builder.SetInsertPoint(SplitBlock->getTerminator());
+    NodeBuilder.addParameters(S.getContext());
     Value *RTC = buildRTC(Builder, NodeBuilder.getExprBuilder());
-    BasicBlock *StartBlock = executeScopConditionally(S, this, RTC);
+    SplitBlock->getTerminator()->setOperand(0, RTC);
     Builder.SetInsertPoint(StartBlock->begin());
 
     NodeBuilder.create(AstRoot);

Added: polly/trunk/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll?rev=233477&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll (added)
+++ polly/trunk/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll Sat Mar 28 04:34:40 2015
@@ -0,0 +1,34 @@
+; RUN: opt %loadPolly -polly-detect-unprofitable -polly-no-early-exit -polly-codegen-isl -S < %s | FileCheck %s
+
+; CHECK: polly
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo() {
+entry:
+  br label %while.header
+
+while.cond.loopexit3:
+  br label %while.header
+
+while.header:
+  br label %switchbb
+
+switchbb:
+  switch i32 undef, label %while.header [
+    i32 1, label %for.body121
+    i32 2, label %unreachableA
+    i32 3, label %unreachableB
+  ]
+
+unreachableA:
+  unreachable
+
+for.body121:
+  %indvar = phi i32 [ 0, %switchbb ], [ %indvar.next, %for.body121 ]
+  %indvar.next = add nsw i32 %indvar, 1
+  br i1 false, label %for.body121, label %while.cond.loopexit3
+
+unreachableB:
+  unreachable
+}

Modified: polly/trunk/test/Isl/CodeGen/aliasing_different_pointer_types.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/aliasing_different_pointer_types.ll?rev=233477&r1=233476&r2=233477&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/aliasing_different_pointer_types.ll (original)
+++ polly/trunk/test/Isl/CodeGen/aliasing_different_pointer_types.ll Sat Mar 28 04:34:40 2015
@@ -3,7 +3,7 @@
 ; Check that we cast the different pointer types correctly before we compare
 ; them in the RTC's. We use i8* as max pointer type.
 ;
-; CHECK: entry:
+; CHECK:   polly.split_new_and_old:
 ; CHECK:   %polly.access.B = getelementptr float*, float** %B, i64 1024
 ; CHECK:   %polly.access.A = getelementptr double*, double** %A, i64 0
 ; CHECK:   %[[paBb:[._a-zA-Z0-9]]] = bitcast float** %polly.access.B to i8*
@@ -16,7 +16,6 @@
 ; CHECK:   %[[A1LeB2:[._a-zA-Z0-9]]] = icmp ule i8* %[[paA1b]], %[[paB2b]]
 ; CHECK:   %[[le1OrLe2:[._a-zA-Z0-9]]] = or i1 %[[ALeB]], %[[A1LeB2]]
 ; CHECK:   %[[orAndTrue:[._a-zA-Z0-9]]] = and i1 true, %[[le1OrLe2]]
-; CHECK:   br label %polly.split_new_and_old
 ;
 ;    void jd(double **A, float **B) {
 ;      for (int i = 0; i < 1024; i++)

Modified: polly/trunk/test/Isl/CodeGen/multidim_2d_parametric_array_static_loop_bounds.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/multidim_2d_parametric_array_static_loop_bounds.ll?rev=233477&r1=233476&r2=233477&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/multidim_2d_parametric_array_static_loop_bounds.ll (original)
+++ polly/trunk/test/Isl/CodeGen/multidim_2d_parametric_array_static_loop_bounds.ll Sat Mar 28 04:34:40 2015
@@ -11,8 +11,8 @@ target triple = "x86_64-unknown-linux-gn
 ; }
 ;
 ; CHECK: entry:
-; CHECK: %0 = icmp sge i64 %m, 150
 ; CHECK: polly.split_new_and_old:
+; CHECK: %0 = icmp sge i64 %m, 150
 ; CHECK: br i1 %0, label %polly.start, label %for.i
 
 define void @foo(i64 %n, i64 %m, double* %A) {

Modified: polly/trunk/test/Isl/CodeGen/run-time-condition-with-scev-parameters.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/run-time-condition-with-scev-parameters.ll?rev=233477&r1=233476&r2=233477&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/run-time-condition-with-scev-parameters.ll (original)
+++ polly/trunk/test/Isl/CodeGen/run-time-condition-with-scev-parameters.ll Sat Mar 28 04:34:40 2015
@@ -1,9 +1,8 @@
 ; RUN: opt %loadPolly -polly-detect-unprofitable -polly-no-early-exit -polly-codegen-isl -S -polly-delinearize < %s | FileCheck %s
 
-; CHECK: %1 = zext i32 %n to i64
-; CHECK-NEST: %2 = icmp sge i64 %1, 1
-; CHECK-NEST: br label %polly.split_new_and_old
 ; CHECK: polly.split_new_and_old:
+; CHECK-NEXT: %1 = zext i32 %n to i64
+; CHECK-NEXT: %2 = icmp sge i64 %1, 1
 ; CHECK-NEXT: br i1 %2, label %polly.start, label %for.body4
 
 





More information about the llvm-commits mailing list