IslAst: always use the context during ast generation
authorTobias Grosser <tobias@grosser.es>
Thu, 10 Nov 2016 09:39:58 +0000 (09:39 +0000)
committerTobias Grosser <tobias@grosser.es>
Thu, 10 Nov 2016 09:39:58 +0000 (09:39 +0000)
Providing the context to the ast generator allows for additional simplifcations
and -- more importantly -- allows to generate loops with only partially bounded
domains, assuming the domains are bounded for all parameter configurations
that are valid as defined by the context.

This change fixes the crash reported in http://llvm.org/PR30956

The original reason why we did not include the context when generating an
AST was that CLooG and later isl used to sometimes transfer some of the
constraints that bound the size of parameters from the context into the
generated AST. This resulted in operations with very large constants, which
sometimes introduced problematic integer overflows. The latest versions of
the isl AST generator are careful to not introduce such constants.

Reported-by: Eli Friedman <efriedma@codeaurora.org>
llvm-svn: 286442

polly/lib/CodeGen/IslAst.cpp
polly/test/Isl/Ast/domain_bounded_only_with_context.ll [new file with mode: 0644]
polly/test/Isl/Ast/simple-run-time-condition.ll
polly/test/Isl/CodeGen/exprModDiv.ll
polly/test/ScheduleOptimizer/full_partial_tile_separation.ll

index 2f00b69d60690f8502ff351c955381caf6f2fea7..519284bf00553002d80dabeb319a7864627a8499 100644 (file)
@@ -63,7 +63,7 @@ static cl::opt<bool> PollyParallelForce(
 
 static cl::opt<bool> UseContext("polly-ast-use-context",
                                 cl::desc("Use context"), cl::Hidden,
-                                cl::init(false), cl::ZeroOrMore,
+                                cl::init(true), cl::ZeroOrMore,
                                 cl::cat(PollyCategory));
 
 static cl::opt<bool> DetectParallel("polly-ast-detect-parallel",
diff --git a/polly/test/Isl/Ast/domain_bounded_only_with_context.ll b/polly/test/Isl/Ast/domain_bounded_only_with_context.ll
new file mode 100644 (file)
index 0000000..1925add
--- /dev/null
@@ -0,0 +1,50 @@
+; RUN: opt %loadPolly -polly-ast -analyze < %s | FileCheck %s
+
+; CHECK:      {
+; CHECK-NEXT:    if (p <= -1 || p >= 1)
+; CHECK-NEXT:      Stmt_preheader();
+; CHECK-NEXT:    for (int c0 = 0; c0 < 2 * p; c0 += 1)
+; CHECK-NEXT:      Stmt_loop(c0);
+; CHECK-NEXT:    if (p <= -1) {
+; CHECK-NEXT:      for (int c0 = 0; c0 <= 2 * p + 255; c0 += 1)
+; CHECK-NEXT:        Stmt_loop(c0);
+; CHECK-NEXT:    } else if (p == 0) {
+; CHECK-NEXT:      Stmt_side();
+; CHECK-NEXT:    }
+; CHECK-NEXT:  }
+
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+
+define void @zot(float* %A, i32 %arg) {
+bb:
+  %p = ashr i32 %arg, 25
+  %tmpEven = shl nsw i32 %p, 1
+  %tmp3 = and i32 %tmpEven, 254
+  br label %cond
+
+cond:
+  %tmpEvenTrunc = trunc i32 %tmpEven to i8
+  %br.cmp = icmp eq i8 %tmpEvenTrunc, 0
+  br i1 %br.cmp, label %side, label %preheader
+
+preheader:
+  store float 1.0, float* %A
+  br label %loop
+
+loop:
+  %indvar = phi i32 [ %indvar.next, %loop ], [ 1, %preheader ]
+  store float 1.0, float* %A
+  %indvar.next = add nuw nsw i32 %indvar, 1
+  %cmp = icmp eq i32 %indvar, %tmp3
+  br i1 %cmp, label %exit, label %loop
+
+side:
+  store float 1.0, float* %A
+  br label %ret
+
+exit:
+  br label %ret
+
+ret:
+  ret void
+}
index ed48c4128a14e2dbd2f78ba42a9e0661f5114528..46b929266af59840366d259471cd4edb2d95843c 100644 (file)
@@ -17,7 +17,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
 ; for the delinearization is simplified such that conditions that would not
 ; cause any code to be executed are not generated.
 
-; CHECK: if (((o >= 1 && q <= 0 && m + q >= 0) || (o <= 0 && m + q >= 100 && q <= 100)) && 0 == ((o <= 0 && n >= 1 && m + q >= 9223372036854775909) || (m >= 1 && n + p >= 9223372036854775809) || (o <= 0 && m >= 1 && n >= 1 && q <= -9223372036854775709)))
+; CHECK: if (((o >= 1 && q <= 0 && m + q >= 0) || (o <= 0 && m + q >= 100 && q <= 100)) && 0 == ((m >= 1 && n + p >= 9223372036854775809) || (o <= 0 && n >= 1 && m + q >= 9223372036854775909) || (o <= 0 && m >= 1 && n >= 1 && q <= -9223372036854775709)))
 
 ; CHECK:     if (o <= 0) {
 ; CHECK:       for (int c0 = 0; c0 < n; c0 += 1)
index 43117819aa6680f53977b73f68775ccf9f124abb..45105cf75e511097d7b7e3622c6b80ba8e545097 100644 (file)
 ; CHECK:  %pexp.p_div_q = udiv i64 %polly.indvar, 127
 ; CHECK:  %polly.access.B10 = getelementptr float, float* %B, i64 %pexp.p_div_q
 
-; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d
-; A[p + 127 * floord(-p - 1, 127) + 127]
-; CHECK:  %pexp.fdiv_q.0 = sub nsw i64 %p, 127
-; CHECK:  %pexp.fdiv_q.1 = add nsw i64 %pexp.fdiv_q.0, 1
-; CHECK:  %pexp.fdiv_q.2 = icmp slt i64 %p, 0
-; CHECK:  %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %p
-; CHECK:  %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 127
-; CHECK:  %[[r1:[0-9]*]] = mul nsw i64 127, %pexp.fdiv_q.4
-; CHECK:  %[[r2:[0-9]*]] = sub nsw i64 %p, %[[r1]]
-; CHECK:  %polly.access.A11 = getelementptr float, float* %A, i64 %[[r2]]
+; A[p % 128]
+; CHECK:  %polly.access.A11 = getelementptr float, float* %A, i64 0
 
 ; A[p / 127]
 ; CHECK:  %pexp.div = sdiv exact i64 %p, 127
 ; POW2:  %pexp.p_div_q = udiv i64 %polly.indvar, 128
 ; POW2:  %polly.access.B10 = getelementptr float, float* %B, i64 %pexp.p_div_q
 
-; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d
-; A[p + 128 * floord(-p - 1, 128) + 128]
-; POW2:  %polly.fdiv_q.shr = ashr i64 %p, 7
-; POW2:  %[[r1:[0-9]*]] = mul nsw i64 128, %polly.fdiv_q.shr
-; POW2:  %[[r2:[0-9]*]] = sub nsw i64 %p, %[[r1]]
-; POW2:  %polly.access.A11 = getelementptr float, float* %A, i64 %[[r2]]
+; A[p % 128]
+; POW2:  %polly.access.A11 = getelementptr float, float* %A, i64 0
 
 ; A[p / 128]
 ; POW2:  %pexp.div = sdiv exact i64 %p, 128
index 57bc3046ee354ec0b897f0c245b8ca63a28f4086..773a09b9e97496dd2606f547d93b68d6201f9084 100644 (file)
@@ -17,7 +17,7 @@
 ; CHECK-NEXT:              for (int c5 = 0; c5 <= min(31, nk - 32 * c2 - 1); c5 += 1) {
 ; CHECK-NEXT:                // SIMD
 ; CHECK-NEXT:                for (int c6 = 0; c6 < nj % 4; c6 += 1)
-; CHECK-NEXT:                  Stmt_for_body_6(32 * c0 + c3, -((nj + 4) % 4) + nj + c6, 32 * c2 + c5);
+; CHECK-NEXT:                  Stmt_for_body_6(32 * c0 + c3, -(nj % 4) + nj + c6, 32 * c2 + c5);
 ; CHECK-NEXT:              }
 ; CHECK-NEXT:          }
 ; CHECK-NEXT:        }