[polly] r231592 - Add sign-extension during codegen of index expressions

Tobias Grosser tobias at grosser.es
Sun Mar 8 08:08:33 PDT 2015


Author: grosser
Date: Sun Mar  8 10:08:32 2015
New Revision: 231592

URL: http://llvm.org/viewvc/llvm-project?rev=231592&view=rev
Log:
Add sign-extension during codegen of index expressions

When code generating array index expressions the types of the different
components of the index expressions may not always match. We extend the type of
the index expression (if possible) and assert otherwise.

Added:
    polly/trunk/test/Isl/CodeGen/alias-check-multi-dim.ll
Modified:
    polly/trunk/lib/CodeGen/IslExprBuilder.cpp

Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=231592&r1=231591&r2=231592&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Sun Mar  8 10:08:32 2015
@@ -127,11 +127,17 @@ Value *IslExprBuilder::createAccessAddre
     assert(NextIndex->getType()->isIntegerTy() &&
            "Access index should be an integer");
 
-    if (!IndexOp)
+    if (!IndexOp) {
       IndexOp = NextIndex;
-    else
+    } else {
+      assert(NextIndex->getType()->getScalarSizeInBits() <=
+                 IndexOp->getType()->getScalarSizeInBits() &&
+             "Truncating the index type may not be save");
+      NextIndex = Builder.CreateIntCast(NextIndex, IndexOp->getType(), true);
+
       IndexOp =
           Builder.CreateAdd(IndexOp, NextIndex, "polly.access.add." + BaseName);
+    }
 
     // For every but the last dimension multiply the size, for the last
     // dimension we can exit the loop.

Added: polly/trunk/test/Isl/CodeGen/alias-check-multi-dim.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/alias-check-multi-dim.ll?rev=231592&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/alias-check-multi-dim.ll (added)
+++ polly/trunk/test/Isl/CodeGen/alias-check-multi-dim.ll Sun Mar  8 10:08:32 2015
@@ -0,0 +1,25 @@
+; RUN: opt %loadPolly -polly-codegen-isl -polly-delinearize -S < %s | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: sext i32 %indvar.init to i64
+
+define void @foo(double* %A, double* %B, i32 %p, i32 %indvar.init) {
+preheader:
+  br label %for.body
+
+for.body:
+  %indvar = phi i32 [ %indvar.next, %for.body ], [ %indvar.init, %preheader ]
+  %B.ptr0 = getelementptr inbounds double, double* %B, i64 0
+  %tmp1 = load double, double* %B.ptr0
+  %A.ptr = getelementptr inbounds double, double* %A, i64 0
+  store double undef, double* %A.ptr
+  %idxprom1329 = sext i32 %indvar to i64
+  %B.ptr1 = getelementptr inbounds double, double* %B, i64 %idxprom1329
+  store double 0.000000e+00, double* %B.ptr1
+  %indvar.next = add nsw i32 %indvar, %p
+  br i1 false, label %for.body, label %exit
+
+exit:
+  ret void
+}





More information about the llvm-commits mailing list