[llvm] r316302 - Fix invalid ptrtoint in InstCombine
Yichao Yu via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 13:28:18 PDT 2017
Author: yuyichao
Date: Sun Oct 22 13:28:17 2017
New Revision: 316302
URL: http://llvm.org/viewvc/llvm-project?rev=316302&view=rev
Log:
Fix invalid ptrtoint in InstCombine
Summary:
It's unclear if this is the only thing we can do but at least this is consistent with the check
of address space agreement in `isBitCastable`.
The code is used at least in both instcombine and jumpthreading though
I could only find a way to trigger the invalid cast in instcombine.
Reviewers: loladiro, sanjoy, majnemer
Reviewed By: sanjoy
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34335
Modified:
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=316302&r1=316301&r2=316302&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Sun Oct 22 13:28:17 2017
@@ -2877,12 +2877,15 @@ bool CastInst::isBitCastable(Type *SrcTy
bool CastInst::isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy,
const DataLayout &DL) {
+ // ptrtoint and inttoptr are not allowed on non-integral pointers
if (auto *PtrTy = dyn_cast<PointerType>(SrcTy))
if (auto *IntTy = dyn_cast<IntegerType>(DestTy))
- return IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy);
+ return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
+ !DL.isNonIntegralPointerType(PtrTy));
if (auto *PtrTy = dyn_cast<PointerType>(DestTy))
if (auto *IntTy = dyn_cast<IntegerType>(SrcTy))
- return IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy);
+ return (IntTy->getBitWidth() == DL.getPointerTypeSizeInBits(PtrTy) &&
+ !DL.isNonIntegralPointerType(PtrTy));
return isBitCastable(SrcTy, DestTy);
}
Modified: llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll?rev=316302&r1=316301&r2=316302&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/non-integral-pointers.ll Sun Oct 22 13:28:17 2017
@@ -46,3 +46,47 @@ entry:
store i8 addrspace(3)* %val, i8 addrspace(3)** %ptr1
ret void
}
+
+define i64 @g(i8 addrspace(4)** %gp) {
+ ; CHECK-LABEL: @g(
+ ; CHECK: load
+ %.pre = load i8 addrspace(4)*, i8 addrspace(4)** %gp, align 8
+ %v74 = call i8 addrspace(4)* @alloc()
+ %v75 = addrspacecast i8 addrspace(4)* %v74 to i8*
+ %v76 = bitcast i8* %v75 to i8 addrspace(4)**
+ %v77 = getelementptr i8 addrspace(4)*, i8 addrspace(4)** %v76, i64 -1
+ ; CHECK: store
+ store i8 addrspace(4)* %.pre, i8 addrspace(4)** %v77, align 8
+ %v80 = bitcast i8 addrspace(4)** %v77 to i64*
+ ; CHECK: load
+ ; CHECK-NOT: ptrtoint
+ %v81 = load i64, i64* %v80, align 8
+ ret i64 %v81
+}
+
+define i64 @g2(i8* addrspace(4)* %gp) {
+ ; CHECK-LABEL: @g2(
+ ; CHECK: load
+ %.pre = load i8*, i8* addrspace(4)* %gp, align 8
+ %v74 = call i8 addrspace(4)* @alloc()
+ %v76 = bitcast i8 addrspace(4)* %v74 to i8* addrspace(4)*
+ %v77 = getelementptr i8*, i8* addrspace(4)* %v76, i64 -1
+ ; CHECK: store
+ store i8* %.pre, i8* addrspace(4)* %v77, align 8
+ %v80 = bitcast i8* addrspace(4)* %v77 to i64 addrspace(4)*
+ ; CHECK-NOT: store
+ %v81 = load i64, i64 addrspace(4)* %v80, align 8
+ ret i64 %v81
+}
+
+declare i8 addrspace(4)* @alloc()
+
+define i64 @f_4(i8 addrspace(4)* %v0) {
+ ; CHECK-LABEL: @f_4(
+ ; CHECK-NOT: ptrtoint
+ %v5 = bitcast i64 (i64)* @f_5 to i64 (i8 addrspace(4)*)*
+ %v6 = call i64 %v5(i8 addrspace(4)* %v0)
+ ret i64 %v6
+}
+
+declare i64 @f_5(i64)
More information about the llvm-commits
mailing list