From e9fc79bb13e833644548416f5aece0571f8c175d Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 21 Jul 2016 21:56:00 +0000 Subject: [PATCH] [InstSimplify] don't crash handling a pointer or aggregate type llvm-svn: 276345 --- llvm/lib/Analysis/InstructionSimplify.cpp | 3 +++ llvm/test/Transforms/InstSimplify/select.ll | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 7e4148c..c7e1724 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3412,6 +3412,9 @@ static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *TrueVal, Value *FalseVal, bool TrueWhenUnset) { unsigned BitWidth = TrueVal->getType()->getScalarSizeInBits(); + if (!BitWidth) + return nullptr; + APInt MinSignedValue; Value *X; if (match(CmpLHS, m_Trunc(m_Value(X))) && (X == TrueVal || X == FalseVal)) { diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll index eafab25..6ddaaba 100644 --- a/llvm/test/Transforms/InstSimplify/select.ll +++ b/llvm/test/Transforms/InstSimplify/select.ll @@ -389,3 +389,16 @@ define i64 @select_icmp_x_and_8_ne_0_y64_and_not_8(i32 %x, i64 %y) { ret i64 %and1.y } +; Don't crash on a pointer or aggregate type. + +define i32* @select_icmp_pointers(i32* %x, i32* %y) { +; CHECK-LABEL: @select_icmp_pointers( +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32* %x, null +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32* %x, i32* %y +; CHECK-NEXT: ret i32* [[SEL]] +; + %cmp = icmp slt i32* %x, null + %sel = select i1 %cmp, i32* %x, i32* %y + ret i32* %sel +} + -- 2.7.4