[PATCH] D12946: Avoid pointer truncation by InstCombine with IntToPtr combining

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 18:36:45 PDT 2015


rampitec removed rL LLVM as the repository for this revision.
rampitec updated this revision to Diff 35053.
rampitec added a comment.

Changed per Mehdi's comments.


http://reviews.llvm.org/D12946

Files:
  lib/Transforms/InstCombine/InstCombineCasts.cpp
  test/Transforms/InstCombine/combine-func-ptr.ll

Index: test/Transforms/InstCombine/combine-func-ptr.ll
===================================================================
--- test/Transforms/InstCombine/combine-func-ptr.ll
+++ test/Transforms/InstCombine/combine-func-ptr.ll
@@ -0,0 +1,16 @@
+; RUN: opt -O3 -S %s | FileCheck %s
+;
+; The 64 bit function pointer should not be truncated even with 32 bit pointer size in address space 0
+;
+; CHECK-NOT: trunc
+
+target datalayout = "e-p:32:64-p1:64:64"
+
+define spir_kernel void @combine_func_ptr(i8 addrspace(1)* %ptr) {
+entry:
+  %0 = ptrtoint i8 addrspace(1)* %ptr to i64
+  %1 = inttoptr i64 %0 to i32 ()*
+  %call = tail call spir_func i32 %1()
+  ret void
+}
+
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1447,7 +1447,9 @@
   // cast to be exposed to other transforms.
   unsigned AS = CI.getAddressSpace();
   if (CI.getOperand(0)->getType()->getScalarSizeInBits() !=
-      DL.getPointerSizeInBits(AS)) {
+      DL.getPointerSizeInBits(AS) &&
+      // The size of a pointer to function is not defined by a DataLayout
+      !CI.getType()->getPointerElementType()->isFunctionTy()) {
     Type *Ty = DL.getIntPtrType(CI.getContext(), AS);
     if (CI.getType()->isVectorTy()) // Handle vectors of pointers.
       Ty = VectorType::get(Ty, CI.getType()->getVectorNumElements());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12946.35053.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150918/a45d1108/attachment.bin>


More information about the llvm-commits mailing list