[polly] r281303 - GPGPU: Extend types when array sizes have smaller types

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 01:02:15 PDT 2016


Author: grosser
Date: Tue Sep 13 03:02:14 2016
New Revision: 281303

URL: http://llvm.org/viewvc/llvm-project?rev=281303&view=rev
Log:
GPGPU: Extend types when array sizes have smaller types

This prevents a compiler crash.

Added:
    polly/trunk/test/GPGPU/size-cast.ll
Modified:
    polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp

Modified: polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp?rev=281303&r1=281302&r2=281303&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp Tue Sep 13 03:02:14 2016
@@ -713,6 +713,8 @@ Value *GPUNodeBuilder::getArraySize(gpu_
     }
 
     Value *NumElements = ExprBuilder.create(Res);
+    if (NumElements->getType() != ArraySize->getType())
+      NumElements = Builder.CreateSExt(NumElements, ArraySize->getType());
     ArraySize = Builder.CreateMul(ArraySize, NumElements);
   }
   isl_ast_build_free(Build);

Added: polly/trunk/test/GPGPU/size-cast.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/GPGPU/size-cast.ll?rev=281303&view=auto
==============================================================================
--- polly/trunk/test/GPGPU/size-cast.ll (added)
+++ polly/trunk/test/GPGPU/size-cast.ll Tue Sep 13 03:02:14 2016
@@ -0,0 +1,65 @@
+; RUN: opt %loadPolly -polly-codegen-ppcg -polly-acc-dump-code \
+; RUN: -disable-output < %s | \
+; RUN: FileCheck -check-prefix=CODE %s
+
+; RUN: opt %loadPolly -polly-codegen-ppcg -S < %s | \
+; RUN: FileCheck %s -check-prefix=IR
+
+; REQUIRES: pollyacc
+
+; This test case ensures that we properly sign-extend the types we are using.
+
+; CODE: Code
+; CODE-NEXT: ====
+; CODE-NEXT: # host
+; CODE-NEXT: if (arg >= 1 && arg1 == 0) {
+; CODE-NEXT:   cudaCheckReturn(cudaMemcpy(dev_MemRef_arg3, MemRef_arg3, (arg) * sizeof(double), cudaMemcpyHostToDevice));
+; CODE-NEXT:   {
+; CODE-NEXT:     dim3 k0_dimBlock(32);
+; CODE-NEXT:     dim3 k0_dimGrid(arg >= 1048546 ? 32768 : floord(arg + 31, 32));
+; CODE-NEXT:     kernel0 <<<k0_dimGrid, k0_dimBlock>>> (dev_MemRef_arg3, dev_MemRef_arg2, arg, arg1);
+; CODE-NEXT:     cudaCheckKernel();
+; CODE-NEXT:   }
+
+; CODE:   cudaCheckReturn(cudaMemcpy(MemRef_arg2, dev_MemRef_arg2, (arg) * sizeof(double), cudaMemcpyDeviceToHost));
+; CODE-NEXT: }
+
+; CODE: # kernel0
+; CODE-NEXT: for (int c0 = 0; c0 <= (arg - 32 * b0 - 1) / 1048576; c0 += 1)
+; CODE-NEXT:   if (arg >= 32 * b0 + t0 + 1048576 * c0 + 1)
+; CODE-NEXT:     Stmt_bb6(0, 32 * b0 + t0 + 1048576 * c0);
+
+; IR:        call i8* @polly_initContext()
+; IR-NEXT:   sext i32 %arg to i64
+; IR-NEXT:   mul i64
+; IR-NEXT:   @polly_allocateMemoryForDevice
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @hoge(i32 %arg, i32 %arg1, [1000 x double]* %arg2, double* %arg3) {
+bb:
+  br label %bb4
+
+bb4:                                              ; preds = %bb13, %bb
+  br label %bb6
+
+bb5:                                              ; preds = %bb13
+  ret void
+
+bb6:                                              ; preds = %bb6, %bb4
+  %tmp = phi i64 [ 0, %bb4 ], [ %tmp10, %bb6 ]
+  %tmp7 = getelementptr inbounds double, double* %arg3, i64 %tmp
+  %tmp8 = load double, double* %tmp7, align 8
+  %tmp9 = getelementptr inbounds [1000 x double], [1000 x double]* %arg2, i64 0, i64 %tmp
+  store double undef, double* %tmp9, align 8
+  %tmp10 = add nuw nsw i64 %tmp, 1
+  %tmp11 = zext i32 %arg to i64
+  %tmp12 = icmp ne i64 %tmp10, %tmp11
+  br i1 %tmp12, label %bb6, label %bb13
+
+bb13:                                             ; preds = %bb6
+  %tmp14 = zext i32 %arg1 to i64
+  %tmp15 = icmp ne i64 0, %tmp14
+  br i1 %tmp15, label %bb4, label %bb5
+}




More information about the llvm-commits mailing list