[polly] r174894 - [isl-codegen]: Fix off by one in getNumberOfIterations

Tobias Grosser grosser at fim.uni-passau.de
Mon Feb 11 09:52:36 PST 2013


Author: grosser
Date: Mon Feb 11 11:52:36 2013
New Revision: 174894

URL: http://llvm.org/viewvc/llvm-project?rev=174894&view=rev
Log:
[isl-codegen]: Fix off by one in getNumberOfIterations

We need to remove one dimension. Any is correct as long as it exists. We have
choosen for whatever reason the dimension #dims - 2. This is incorrect if
there is just one dimension. For CLooG this case did never happen. For isl
however, the case can happen and causes undefined behavior including crashes.
We choose now always the last dimension #dims - 1. We could have choosen
dimension '0' but the last dimension is what we remove conceptionally in the
algorithm, so it seems better to actually program it that way.

While at it remove another piece of undefined behavior.

Added:
    polly/trunk/test/Isl/CodeGen/20130211-getNumberOfIterations.ll
Modified:
    polly/trunk/include/polly/CodeGen/CodeGeneration.h

Modified: polly/trunk/include/polly/CodeGen/CodeGeneration.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/CodeGeneration.h?rev=174894&r1=174893&r2=174894&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/CodeGeneration.h (original)
+++ polly/trunk/include/polly/CodeGen/CodeGeneration.h Mon Feb 11 11:52:36 2013
@@ -34,13 +34,15 @@ namespace polly {
     // and output dimension not related.
     //  [i0, i1, i2, i3] -> [i0, i1, i2, o0]
     isl_space *Space = isl_set_get_space(Domain);
-    Space = isl_space_drop_outputs(Space, Dim - 2, 1);
+    Space = isl_space_drop_outputs(Space, Dim - 1, 1);
     Space = isl_space_map_from_set(Space);
     isl_map *Identity = isl_map_identity(Space);
     Identity = isl_map_add_dims(Identity, isl_dim_in, 1);
     Identity = isl_map_add_dims(Identity, isl_dim_out, 1);
 
-    isl_map *Map = isl_map_from_domain_and_range(isl_set_copy(Domain), Domain);
+    isl_map *Map = isl_map_from_domain_and_range(isl_set_copy(Domain),
+                                                 isl_set_copy(Domain));
+    isl_set_free(Domain);
     Map = isl_map_intersect(Map, Identity);
 
     isl_map *LexMax = isl_map_lexmax(isl_map_copy(Map));

Added: polly/trunk/test/Isl/CodeGen/20130211-getNumberOfIterations.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/20130211-getNumberOfIterations.ll?rev=174894&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/20130211-getNumberOfIterations.ll (added)
+++ polly/trunk/test/Isl/CodeGen/20130211-getNumberOfIterations.ll Mon Feb 11 11:52:36 2013
@@ -0,0 +1,29 @@
+; RUN: opt %loadPolly -polly-codegen-isl -polly-vectorizer=polly < %s
+; RUN: opt %loadPolly -polly-codegen-isl -polly-vectorizer=bb < %s
+
+; This test case checks that the polly vectorizer does not crash when
+; calculating the number of iterations.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at b = external global [2048 x i64], align 16
+
+define void @foo(i64 %n) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.body, %entry
+  %indvar = phi i64 [ 0, %entry ], [ %inc, %for.body ]
+  %cmp = icmp slt i64 %indvar, %n
+  br i1 %cmp, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %arrayidx = getelementptr inbounds [2048 x i64]* @b, i64 0, i64 %indvar
+  store i64 1, i64* %arrayidx
+  %inc = add nsw i64 %indvar, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
+





More information about the llvm-commits mailing list