[PATCH] D33361: [InstCombine] Fix inbounds gep for addrspacecasts
Sven van Haastregt via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 4 09:49:41 PDT 2018
svenvh updated this revision to Diff 140981.
svenvh edited the summary of this revision.
svenvh added a comment.
Updated patch to just bail out if address spaces don't match.
https://reviews.llvm.org/D33361
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/getelementptr.ll
Index: test/Transforms/InstCombine/getelementptr.ll
===================================================================
--- test/Transforms/InstCombine/getelementptr.ll
+++ test/Transforms/InstCombine/getelementptr.ll
@@ -942,4 +942,17 @@
ret <2 x i32*> %tmp1
}
+; Test that inbounds inference does not crash in the presence of addrspacecasts.
+define i8 addrspace(42)* @gep_inbounds_addrspace() {
+; CHECK-LABEL: @gep_inbounds_addrspace
+; CHECK: addrspacecast
+; CHECK: getelementptr
+; CHECK: ret
+ %A = alloca <8 x half>, align 16
+ %B = bitcast <8 x half>* %A to i8*
+ %C = addrspacecast i8* %B to i8 addrspace(42)*
+ %gep = getelementptr i8, i8 addrspace(42)* %C, i64 12
+ ret i8 addrspace(42)* %gep
+}
+
; CHECK: attributes [[$NUW]] = { nounwind }
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2034,6 +2034,7 @@
}
}
+ // Try to infer inbounds on GEPs of allocas.
if (!GEP.isInBounds()) {
unsigned IdxWidth =
DL.getIndexSizeInBits(PtrOp->getType()->getPointerAddressSpace());
@@ -2045,7 +2046,8 @@
if (GEP.accumulateConstantOffset(DL, BasePtrOffset) &&
BasePtrOffset.isNonNegative()) {
APInt AllocSize(IdxWidth, DL.getTypeAllocSize(AI->getAllocatedType()));
- if (BasePtrOffset.ule(AllocSize)) {
+ if (BasePtrOffset.ule(AllocSize) && GEP.getAddressSpace() ==
+ PtrOp->getType()->getPointerAddressSpace()) {
return GetElementPtrInst::CreateInBounds(
PtrOp, makeArrayRef(Ops).slice(1), GEP.getName());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33361.140981.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180404/2ed2d7c7/attachment.bin>
More information about the llvm-commits
mailing list