[llvm] 5df3872 - [DAG] visitAND - refactor "and (sub 0, ext(bool X)), 1 --> zext(bool X)" to use SDPatternMatch.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 06:30:36 PST 2024
Author: Simon Pilgrim
Date: 2024-11-05T14:30:21Z
New Revision: 5df387227ea39cb1b0ff7e7f9930744e663ed41c
URL: https://github.com/llvm/llvm-project/commit/5df387227ea39cb1b0ff7e7f9930744e663ed41c
DIFF: https://github.com/llvm/llvm-project/commit/5df387227ea39cb1b0ff7e7f9930744e663ed41c.diff
LOG: [DAG] visitAND - refactor "and (sub 0, ext(bool X)), 1 --> zext(bool X)" to use SDPatternMatch.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 42232bd195a651..129e869b7f748c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7399,16 +7399,13 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
//
// Note: the SimplifyDemandedBits fold below can make an information-losing
// transform, and then we have no way to find this better fold.
- if (N1C && N1C->isOne() && N0.getOpcode() == ISD::SUB) {
- if (isNullOrNullSplat(N0.getOperand(0))) {
- SDValue SubRHS = N0.getOperand(1);
- if (SubRHS.getOpcode() == ISD::ZERO_EXTEND &&
- SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
- return SubRHS;
- if (SubRHS.getOpcode() == ISD::SIGN_EXTEND &&
- SubRHS.getOperand(0).getScalarValueSizeInBits() == 1)
- return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, SubRHS.getOperand(0));
- }
+ if (sd_match(N, m_And(m_Sub(m_Zero(), m_Value(X)), m_One()))) {
+ if (X.getOpcode() == ISD::ZERO_EXTEND &&
+ X.getOperand(0).getScalarValueSizeInBits() == 1)
+ return X;
+ if (X.getOpcode() == ISD::SIGN_EXTEND &&
+ X.getOperand(0).getScalarValueSizeInBits() == 1)
+ return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, X.getOperand(0));
}
// fold (and (sign_extend_inreg x, i16 to i32), 1) -> (and x, 1)
More information about the llvm-commits
mailing list