[PATCH] D44063: [InstCombine] Don't blow up in foldICmpWithCastAndCast on vector icmp instructions.
Daniel Neilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 18:02:20 PST 2018
dneilson created this revision.
dneilson added reviewers: apilipenko, fedor.sergeev, mkazantsev, anna.
Presently, InstCombiner::foldICmpWithCastAndCast() implicitly assumes that it is
only invoked with icmp instructions of integer type. If that assumption is broken,
and it is called with an icmp of vector type, then it fails (asserts/crashes).
This patch addresses the deficiency. It allows it to simplify
icmp (ptrtoint x), (ptrtoint/c) of vector type into a compare of the inputs,
much as is done when the type is integer.
Repository:
rL LLVM
https://reviews.llvm.org/D44063
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll
Index: test/Transforms/InstCombine/icmp.ll
===================================================================
--- test/Transforms/InstCombine/icmp.ll
+++ test/Transforms/InstCombine/icmp.ll
@@ -3302,3 +3302,15 @@
ret i1 %cmp
}
+; Don't crash by assuming the compared values are integers.
+define <2 x i1> @PR36583(<2 x i8*>) {
+; CHECK-LABEL: @PR36583(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RES:%.*]] = icmp eq <2 x i8*> %0, zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[RES]]
+;
+entry:
+ %cast = ptrtoint <2 x i8*> %0 to <2 x i64>
+ %res = icmp eq <2 x i64> %cast, zeroinitializer
+ ret <2 x i1> %res
+}
Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3408,8 +3408,15 @@
// Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
// integer type is the same size as the pointer type.
+ const auto& CompatibleSizes = [&](Type* SrcTy, Type* DestTy) -> bool {
+ if (isa<VectorType>(SrcTy)) {
+ SrcTy = cast<VectorType>(SrcTy)->getElementType();
+ DestTy = cast<VectorType>(DestTy)->getElementType();
+ }
+ return DL.getPointerTypeSizeInBits(SrcTy) == DestTy->getIntegerBitWidth();
+ };
if (LHSCI->getOpcode() == Instruction::PtrToInt &&
- DL.getPointerTypeSizeInBits(SrcTy) == DestTy->getIntegerBitWidth()) {
+ CompatibleSizes(SrcTy, DestTy)) {
Value *RHSOp = nullptr;
if (auto *RHSC = dyn_cast<PtrToIntOperator>(ICmp.getOperand(1))) {
Value *RHSCIOp = RHSC->getOperand(0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44063.136890.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180303/6dab49eb/attachment.bin>
More information about the llvm-commits
mailing list