[llvm] f4f6566 - [InstCombine] Fix type mismatch in `foldICmpBinOpEqualityWithConstant` (#119068)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 7 21:21:37 PST 2024
Author: Yingwei Zheng
Date: 2024-12-08T13:21:34+08:00
New Revision: f4f6566e44566f3d8cf9517767d457227125ca93
URL: https://github.com/llvm/llvm-project/commit/f4f6566e44566f3d8cf9517767d457227125ca93
DIFF: https://github.com/llvm/llvm-project/commit/f4f6566e44566f3d8cf9517767d457227125ca93.diff
LOG: [InstCombine] Fix type mismatch in `foldICmpBinOpEqualityWithConstant` (#119068)
Closes https://github.com/llvm/llvm-project/issues/119063.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index b694fde30927f3..54053c4c9e28e8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3622,7 +3622,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 75301ce5d72a78..43afd3c69f7c30 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
+}
More information about the llvm-commits
mailing list