[PATCH] D23182: [ConstantFolding] Don't create illegal (non-integral) inttoptrs
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 5 12:31:23 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277854: [ConstantFolding] Don't create illegal (non-integral) inttoptrs (authored by sanjoy).
Changed prior to commit:
https://reviews.llvm.org/D23182?vs=66881&id=66992#toc
Repository:
rL LLVM
https://reviews.llvm.org/D23182
Files:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
Index: llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
+++ llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
@@ -0,0 +1,20 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i8 addrspace(4)* @f_0() {
+; CHECK-LABEL: @f_0(
+; CHECK: ret i8 addrspace(4)* getelementptr (i8, i8 addrspace(4)* null, i64 50)
+ %result = getelementptr i8, i8 addrspace(4)* null, i64 50
+ ret i8 addrspace(4)* %result
+}
+
+define i8 addrspace(3)* @f_1() {
+; inttoptr is fine here since addrspace(3) is integral.
+
+; CHECK-LABEL: @f_1(
+; CHECK: ret i8 addrspace(3)* inttoptr (i64 50 to i8 addrspace(3)*)
+ %result = getelementptr i8, i8 addrspace(3)* null, i64 50
+ ret i8 addrspace(3)* %result
+}
Index: llvm/trunk/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp
@@ -828,17 +828,18 @@
}
}
- if (Ptr->isNullValue() || BasePtr != 0) {
+ auto *PTy = cast<PointerType>(Ptr->getType());
+ if ((Ptr->isNullValue() || BasePtr != 0) &&
+ !DL.isNonIntegralPointerType(PTy)) {
Constant *C = ConstantInt::get(Ptr->getContext(), Offset + BasePtr);
return ConstantExpr::getIntToPtr(C, ResTy);
}
// Otherwise form a regular getelementptr. Recompute the indices so that
// we eliminate over-indexing of the notional static type array bounds.
// This makes it easy to determine if the getelementptr is "inbounds".
// Also, this helps GlobalOpt do SROA on GlobalVariables.
- Type *Ty = Ptr->getType();
- assert(Ty->isPointerTy() && "Forming regular GEP of non-pointer type");
+ Type *Ty = PTy;
SmallVector<Constant *, 32> NewIdxs;
do {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23182.66992.patch
Type: text/x-patch
Size: 1996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160805/56b35bb6/attachment.bin>
More information about the llvm-commits
mailing list