[llvm] 03a2fe9 - [DAG] visitSUB - update the ABS matching code to use SDPatternMatch and hasOperation.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 02:07:49 PDT 2024
Author: Simon Pilgrim
Date: 2024-06-06T10:06:57+01:00
New Revision: 03a2fe9a7574c0cff724666e713dead7009a9621
URL: https://github.com/llvm/llvm-project/commit/03a2fe9a7574c0cff724666e713dead7009a9621
DIFF: https://github.com/llvm/llvm-project/commit/03a2fe9a7574c0cff724666e713dead7009a9621.diff
LOG: [DAG] visitSUB - update the ABS matching code to use SDPatternMatch and hasOperation.
Avoids the need to explicitly test both commuted variants and doesn't match custom lowering after legalization.
Cleanup for #94504
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 9a5359015439e..02cd125eeff09 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4041,17 +4041,11 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
return DAG.getNode(ISD::ADD, DL, VT, N0, SExt);
}
- // fold Y = sra (X, size(X)-1); sub (xor (X, Y), Y) -> (abs X)
- if (TLI.isOperationLegalOrCustom(ISD::ABS, VT)) {
- if (N0.getOpcode() == ISD::XOR && N1.getOpcode() == ISD::SRA) {
- SDValue X0 = N0.getOperand(0), X1 = N0.getOperand(1);
- SDValue S0 = N1.getOperand(0);
- if ((X0 == S0 && X1 == N1) || (X0 == N1 && X1 == S0))
- if (ConstantSDNode *C = isConstOrConstSplat(N1.getOperand(1)))
- if (C->getAPIntValue() == (BitWidth - 1))
- return DAG.getNode(ISD::ABS, DL, VT, S0);
- }
- }
+ // fold B = sra (A, size(A)-1); sub (xor (A, B), B) -> (abs A)
+ if (hasOperation(ISD::ABS, VT) &&
+ sd_match(N1, m_Sra(m_Value(A), m_SpecificInt(BitWidth - 1))) &&
+ sd_match(N0, m_Xor(m_Specific(A), m_Specific(N1))))
+ return DAG.getNode(ISD::ABS, DL, VT, A);
// If the relocation model supports it, consider symbol offsets.
if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(N0))
More information about the llvm-commits
mailing list