[PATCH] D31470: [InstCombine] Correct the check for vector GEPs
Matthew Simpson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 29 09:31:09 PDT 2017
mssimpso created this revision.
Some of the GEP combines (e.g., descaling) can't handle vector GEPs. We have an existing check that attempts to bail out if given a vector GEP. However, the check only tests the GEP's pointer operand. A GEP results in a vector of pointers if at least one of its operands is vector-typed (i.e., its pointer operand could be a scalar but its index could be a vector). We should probably just check the type of the GEP itself. This should fix PR32414.
The added test case causes an assertion without this patch.
Reference: https://bugs.llvm.org/show_bug.cgi?id=32414
https://reviews.llvm.org/D31470
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
@@ -931,4 +931,15 @@
ret i32 addrspace(1)* %x
}
+define <2 x i32*> @PR32414(i32** %ptr) {
+; CHECK-LABEL: @PR32414(
+; CHECK-NEXT: [[TMP0:%.*]] = bitcast i32** %ptr to i32*
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], <2 x i64> <i64 0, i64 1>
+; CHECK-NEXT: ret <2 x i32*> [[TMP1]]
+;
+ %tmp0 = bitcast i32** %ptr to i32*
+ %tmp1 = getelementptr inbounds i32, i32* %tmp0, <2 x i64> <i64 0, i64 1>
+ ret <2 x i32*> %tmp1
+}
+
; CHECK: attributes [[NUW]] = { nounwind }
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1655,14 +1655,14 @@
}
}
- // Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
- Value *StrippedPtr = PtrOp->stripPointerCasts();
- PointerType *StrippedPtrTy = dyn_cast<PointerType>(StrippedPtr->getType());
-
// We do not handle pointer-vector geps here.
- if (!StrippedPtrTy)
+ if (GEP.getType()->isVectorTy())
return nullptr;
+ // Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
+ Value *StrippedPtr = PtrOp->stripPointerCasts();
+ PointerType *StrippedPtrTy = cast<PointerType>(StrippedPtr->getType());
+
if (StrippedPtr != PtrOp) {
bool HasZeroPointerIndex = false;
if (ConstantInt *C = dyn_cast<ConstantInt>(GEP.getOperand(1)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31470.93383.patch
Type: text/x-patch
Size: 1647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170329/6d516400/attachment.bin>
More information about the llvm-commits
mailing list