[llvm] [InstCombine] Fix type mismatch in `foldICmpBinOpEqualityWithConstant` (PR #119068)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 7 05:11:36 PST 2024
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/119068
Closes https://github.com/llvm/llvm-project/issues/119063.
>From 097ce2f5f0ae0016ce4b43c56a9f6deb8f076416 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sat, 7 Dec 2024 21:08:29 +0800
Subject: [PATCH] [InstCombine] Fix type mismatch in
`foldICmpBinOpEqualityWithConstant`
---
.../InstCombine/InstCombineCompares.cpp | 3 ++-
.../InstCombine/icmp-or-of-select-with-zero.ll | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 56391d320e8b37..f8946bbe86b0af 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 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