[llvm] [InstCombine] Improve `foldAndOrOfICmpsUsingRanges` (PR #67327)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 11 11:33:52 PDT 2023
================
@@ -1273,23 +1273,46 @@ Value *InstCombinerImpl::foldAndOrOfICmpsUsingRanges(ICmpInst *ICmp1,
ICmpInst::Predicate Pred1, Pred2;
Value *V1, *V2;
const APInt *C1, *C2;
- if (!match(ICmp1, m_ICmp(Pred1, m_Value(V1), m_APInt(C1))) ||
- !match(ICmp2, m_ICmp(Pred2, m_Value(V2), m_APInt(C2))))
- return nullptr;
-
- // Look through add of a constant offset on V1, V2, or both operands. This
- // allows us to interpret the V + C' < C'' range idiom into a proper range.
const APInt *Offset1 = nullptr, *Offset2 = nullptr;
- if (V1 != V2) {
- Value *X;
- if (match(V1, m_Add(m_Value(X), m_APInt(Offset1))))
- V1 = X;
- if (match(V2, m_Add(m_Value(X), m_APInt(Offset2))))
- V2 = X;
+ bool Matched = false;
+
+ if (match(ICmp1, m_ICmp(Pred1, m_Value(V1), m_APInt(C1))) &&
+ match(ICmp2, m_ICmp(Pred2, m_Value(V2), m_APInt(C2)))) {
+ // Look through add of a constant offset on V1, V2, or both operands. This
+ // allows us to interpret the V + C' < C'' range idiom into a proper range.
+ if (V1 != V2) {
+ Value *X;
+ if (match(V1, m_Add(m_Value(X), m_APInt(Offset1))))
+ V1 = X;
+ if (match(V2, m_Add(m_Value(X), m_APInt(Offset2))))
+ V2 = X;
+ }
+
+ Matched = V1 == V2;
}
- if (V1 != V2)
+ if (!Matched) {
+ Value *A = nullptr, *B = nullptr, *C = nullptr, *D = nullptr, *E = nullptr;
+ // Match (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E)
+ auto MaskPair =
+ getMaskedTypeForICmpPair(A, B, C, D, E, ICmp1, ICmp2, Pred1, Pred2);
+ // Match (icmp(A & B) ==/!= C1) &/| (icmp(A & B) ==/!= C2)
+ if (MaskPair && B == D && match(C, m_APIntAllowUndef(C1)) &&
+ match(E, m_APIntAllowUndef(C2)) &&
+ (match(ICmp1->getOperand(0),
+ m_CombineAnd(m_Value(V1),
+ m_c_And(m_Specific(A), m_Specific(B)))) ||
+ match(ICmp2->getOperand(0),
+ m_CombineAnd(m_Value(V1),
+ m_c_And(m_Specific(A), m_Specific(D)))))) {
+ V2 = V1;
+ Matched = true;
+ }
+ }
+
+ if (!Matched)
return nullptr;
+ assert(V1 == V2);
----------------
goldsteinn wrote:
nit: assert msg
https://github.com/llvm/llvm-project/pull/67327
More information about the llvm-commits
mailing list