Skip to content

Commit f4f6566

Browse files
authored
[InstCombine] Fix type mismatch in foldICmpBinOpEqualityWithConstant (llvm#119068)
Closes llvm#119063.
1 parent 118f7b9 commit f4f6566

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3622,7 +3622,8 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
36223622
m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel),
36233623
m_Select(m_Value(Cond), m_Value(TV),
36243624
m_Value(FV))),
3625-
m_Value(Other))))) {
3625+
m_Value(Other)))) &&
3626+
Cond->getType() == Cmp.getType()) {
36263627
const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
36273628
// Easy case is if eq/ne matches whether 0 is trueval/falseval.
36283629
if (Pred == ICmpInst::ICMP_EQ

llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll

+17
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,20 @@ define i1 @src_tv_ne_invert(i1 %c1, i8 %a, i8 %b, i8 %x, i8 %yy) {
293293
call void @use.i8(i8 %sel_other)
294294
ret i1 %r
295295
}
296+
297+
; Make sure we don't crash on this case.
298+
299+
define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {
300+
; CHECK-LABEL: @pr119063(
301+
; CHECK-NEXT: entry:
302+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <4 x i32> splat (i32 1), <4 x i32> zeroinitializer
303+
; CHECK-NEXT: [[OR:%.*]] = or <4 x i32> [[SEL]], [[X:%.*]]
304+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <4 x i32> [[OR]], zeroinitializer
305+
; CHECK-NEXT: ret <4 x i1> [[CMP]]
306+
;
307+
entry:
308+
%sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer
309+
%or = or <4 x i32> %sel, %x
310+
%cmp = icmp ne <4 x i32> %or, zeroinitializer
311+
ret <4 x i1> %cmp
312+
}

0 commit comments

Comments
 (0)