[llvm] 7a969ec - [PatternMatch] Use m_Not instead of m_c_Xor with m_AllOnes() (#96837)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 01:14:49 PDT 2024
Author: AtariDreams
Date: 2024-06-27T10:14:45+02:00
New Revision: 7a969ec1e114b6674c08e82ca048a3c4576bf0dd
URL: https://github.com/llvm/llvm-project/commit/7a969ec1e114b6674c08e82ca048a3c4576bf0dd
DIFF: https://github.com/llvm/llvm-project/commit/7a969ec1e114b6674c08e82ca048a3c4576bf0dd.diff
LOG: [PatternMatch] Use m_Not instead of m_c_Xor with m_AllOnes() (#96837)
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 526b7258b8ab7..d4e355431a27a 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2309,6 +2309,22 @@ m_UnordFMin(const LHS &L, const RHS &R) {
return MaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>(L, R);
}
+/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
+/// NOTE: we first match the 'Not' (by matching '-1'),
+/// and only then match the inner matcher!
+template <typename ValTy>
+inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
+m_Not(const ValTy &V) {
+ return m_c_Xor(m_AllOnes(), V);
+}
+
+template <typename ValTy>
+inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
+ true>
+m_NotForbidPoison(const ValTy &V) {
+ return m_c_Xor(m_AllOnesForbidPoison(), V);
+}
+
//===----------------------------------------------------------------------===//
// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
// Note that S might be matched to other instructions than AddInst.
@@ -2343,13 +2359,13 @@ struct UAddWithOverflow_match {
return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
Value *Op1;
- auto XorExpr = m_OneUse(m_Xor(m_Value(Op1), m_AllOnes()));
- // (a ^ -1) <u b
+ auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
+ // (~a) <u b
if (Pred == ICmpInst::ICMP_ULT) {
if (XorExpr.match(ICmpLHS))
return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
}
- // b > u (a ^ -1)
+ // b > u (~a)
if (Pred == ICmpInst::ICMP_UGT) {
if (XorExpr.match(ICmpRHS))
return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
@@ -2659,22 +2675,6 @@ m_NSWNeg(const ValTy &V) {
return m_NSWSub(m_ZeroInt(), V);
}
-/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
-/// NOTE: we first match the 'Not' (by matching '-1'),
-/// and only then match the inner matcher!
-template <typename ValTy>
-inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
-m_Not(const ValTy &V) {
- return m_c_Xor(m_AllOnes(), V);
-}
-
-template <typename ValTy>
-inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
- true>
-m_NotForbidPoison(const ValTy &V) {
- return m_c_Xor(m_AllOnesForbidPoison(), V);
-}
-
/// Matches an SMin with LHS and RHS in either order.
template <typename LHS, typename RHS>
inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index b9148999ff395..f917e93493950 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -30557,7 +30557,7 @@ static std::pair<Value *, BitTestKind> FindSingleBitChange(Value *V) {
bool Not = false;
// Check if we have a NOT
Value *PeekI;
- if (match(I, m_c_Xor(m_Value(PeekI), m_AllOnes())) ||
+ if (match(I, m_Not(m_Value(PeekI))) ||
match(I, m_Sub(m_AllOnes(), m_Value(PeekI)))) {
Not = true;
I = dyn_cast<Instruction>(PeekI);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 06b434857c657..38f8a41214b68 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -216,7 +216,7 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
// ((1 << MaskShAmt) - 1)
auto MaskA = m_Add(m_Shl(m_One(), m_Value(MaskShAmt)), m_AllOnes());
// (~(-1 << maskNbits))
- auto MaskB = m_Xor(m_Shl(m_AllOnes(), m_Value(MaskShAmt)), m_AllOnes());
+ auto MaskB = m_Not(m_Shl(m_AllOnes(), m_Value(MaskShAmt)));
// (-1 l>> MaskShAmt)
auto MaskC = m_LShr(m_AllOnes(), m_Value(MaskShAmt));
// ((-1 << MaskShAmt) l>> MaskShAmt)
More information about the llvm-commits
mailing list