diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 56391d320e8b3..f8946bbe86b0a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3604,7 +3604,8 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant( m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel), m_Select(m_Value(Cond), m_Value(TV), m_Value(FV))), - m_Value(Other))))) { + m_Value(Other)))) && + Cond->getType() == Cmp.getType()) { const SimplifyQuery Q = SQ.getWithInstruction(&Cmp); // Easy case is if eq/ne matches whether 0 is trueval/falseval. if (Pred == ICmpInst::ICMP_EQ diff --git a/llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll b/llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll index 75301ce5d72a7..43afd3c69f7c3 100644 --- a/llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll +++ b/llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll @@ -293,3 +293,20 @@ define i1 @src_tv_ne_invert(i1 %c1, i8 %a, i8 %b, i8 %x, i8 %yy) { call void @use.i8(i8 %sel_other) ret i1 %r } + +; Make sure we don't crash on this case. + +define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) { +; CHECK-LABEL: @pr119063( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <4 x i32> splat (i32 1), <4 x i32> zeroinitializer +; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[SEL]], [[X:%.*]] +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <4 x i32> [[OR]], zeroinitializer +; CHECK-NEXT: ret <4 x i1> [[CMP]] +; +entry: + %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer + %or = or <4 x i32> %sel, %x + %cmp = icmp ne <4 x i32> %or, zeroinitializer + ret <4 x i1> %cmp +}