[polly] r234122 - Sign-extend in case of non-matching bitwidth

Tobias Grosser tobias at grosser.es
Sun Apr 5 10:36:42 PDT 2015


Author: grosser
Date: Sun Apr  5 12:36:42 2015
New Revision: 234122

URL: http://llvm.org/viewvc/llvm-project?rev=234122&view=rev
Log:
Sign-extend in case of non-matching bitwidth

This change ensures that we sign-extend integer types in case non-matching
operands are encountered when generating a multi-dimensional access offset.

This fixes http://llvm.org/PR23124

Reported-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

Added:
    polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize-2.ll
    polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize.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=234122&r1=234121&r2=234122&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Sun Apr  5 12:36:42 2015
@@ -130,10 +130,12 @@ Value *IslExprBuilder::createAccessAddre
     if (!IndexOp) {
       IndexOp = NextIndex;
     } else {
-      assert(NextIndex->getType()->getScalarSizeInBits() <=
-                 IndexOp->getType()->getScalarSizeInBits() &&
-             "Truncating the index type may not be save");
-      NextIndex = Builder.CreateIntCast(NextIndex, IndexOp->getType(), true);
+      Type *Ty = getWidestType(NextIndex->getType(), IndexOp->getType());
+
+      if (Ty != NextIndex->getType())
+        NextIndex = Builder.CreateIntCast(NextIndex, Ty, true);
+      if (Ty != IndexOp->getType())
+        IndexOp = Builder.CreateIntCast(IndexOp, Ty, true);
 
       IndexOp =
           Builder.CreateAdd(IndexOp, NextIndex, "polly.access.add." + BaseName);
@@ -153,7 +155,9 @@ Value *IslExprBuilder::createAccessAddre
     if (Ty != IndexOp->getType())
       IndexOp = Builder.CreateSExtOrTrunc(IndexOp, Ty,
                                           "polly.access.sext." + BaseName);
-
+    if (Ty != DimSize->getType())
+      DimSize = Builder.CreateSExtOrTrunc(DimSize, Ty,
+                                          "polly.access.sext." + BaseName);
     IndexOp =
         Builder.CreateMul(IndexOp, DimSize, "polly.access.mul." + BaseName);
   }

Added: polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize-2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize-2.ll?rev=234122&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize-2.ll (added)
+++ polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize-2.ll Sun Apr  5 12:36:42 2015
@@ -0,0 +1,25 @@
+; RUN: opt %loadPolly -polly-codegen-isl -S < %s | FileCheck %s
+; CHECK: polly
+target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
+
+define void @hoge(i16* %arg, i32 %arg1, i16* %arg2) {
+bb:
+  %tmp = alloca i32
+  %tmp3 = load i32, i32* undef
+  br label %bb7
+
+bb7:
+  %tmp8 = phi i32 [ %tmp3, %bb ], [ %tmp13, %bb7 ]
+  %tmp9 = getelementptr inbounds i16, i16* %arg2, i32 0
+  %tmp10 = load i16, i16* %tmp9, align 2
+  %tmp11 = mul nsw i32 %tmp8, %arg1
+  %tmp12 = getelementptr inbounds i16, i16* %arg, i32 %tmp11
+  store i16 undef, i16* %tmp12, align 2
+  %tmp13 = add nsw i32 %tmp8, 1
+  store i32 undef, i32* %tmp
+  br i1 false, label %bb7, label %bb5
+
+bb5:
+  ret void
+
+}

Added: polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize.ll?rev=234122&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize.ll (added)
+++ polly/trunk/test/Isl/CodeGen/multidim-non-matching-typesize.ll Sun Apr  5 12:36:42 2015
@@ -0,0 +1,23 @@
+; RUN: opt %loadPolly -polly-codegen-isl -S < %s | FileCheck %s
+
+target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
+
+; CHECK: polly
+
+define void @hoge(i16* %arg, i32 %arg1) {
+bb:
+  %tmp = alloca i16
+  br label %bb2
+
+bb2:
+  %tmp3 = phi i32 [ %tmp7, %bb2 ], [ 0, %bb ]
+  %tmp4 = mul nsw i32 %tmp3, %arg1
+  %tmp5 = getelementptr inbounds i16, i16* %arg, i32 %tmp4
+  %tmp6 = load i16, i16* %tmp5, align 2
+  store i16 %tmp6, i16* %tmp
+  %tmp7 = add nsw i32 %tmp3, 1
+  br i1 false, label %bb2, label %bb8
+
+bb8:
+  ret void
+}





More information about the llvm-commits mailing list