[llvm] [InstCombine] Handle trunc i1 pattern in eq-of-parts fold (PR #112704)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 16 13:16:10 PST 2024
================
@@ -1185,14 +1185,25 @@ static Value *extractIntPart(const IntPart &P, IRBuilderBase &Builder) {
/// (icmp eq X0, Y0) & (icmp eq X1, Y1) -> icmp eq X01, Y01
/// (icmp ne X0, Y0) | (icmp ne X1, Y1) -> icmp ne X01, Y01
/// where X0, X1 and Y0, Y1 are adjacent parts extracted from an integer.
-Value *InstCombinerImpl::foldEqOfParts(ICmpInst *Cmp0, ICmpInst *Cmp1,
- bool IsAnd) {
+Value *InstCombinerImpl::foldEqOfParts(Value *Cmp0, Value *Cmp1, bool IsAnd) {
if (!Cmp0->hasOneUse() || !Cmp1->hasOneUse())
return nullptr;
CmpInst::Predicate Pred = IsAnd ? CmpInst::ICMP_EQ : CmpInst::ICMP_NE;
- auto GetMatchPart = [&](ICmpInst *Cmp,
+ auto GetMatchPart = [&](Value *CmpV,
unsigned OpNo) -> std::optional<IntPart> {
+ Value *X, *Y;
+ // icmp ne (and x, 1), (and y, 1) <=> trunc (xor x, y) to i1
+ // icmp eq (and x, 1), (and y, 1) <=> not (trunc (xor x, y) to i1)
+ if (Pred == CmpInst::ICMP_NE
+ ? match(CmpV, m_Trunc(m_Xor(m_Value(X), m_Value(Y))))
----------------
andjo403 wrote:
maybe nice to have a assert that the trunc is to i1 near here. I thought it was missing before finding the check first in foldBooleanAndOr.
https://github.com/llvm/llvm-project/pull/112704
More information about the llvm-commits
mailing list