[llvm] Matched some basic ISD::AVGFLOORU patterns (PR #84903)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 12 15:41:47 PDT 2024
================
@@ -2821,6 +2821,38 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) {
return SDValue();
}
+// Attempt to form ext(avgflooru(A, B)) from add(and(A, B), lshr(xor(A, B), 1))
+static SDValue combineFixedwidthToAVG(SDNode *N, SelectionDAG &DAG) {
+ assert(N->getOpcode() == ISD::ADD && "ADD node is required here");
+ SDValue And = N->getOperand(0);
+ SDValue Lshr = N->getOperand(1);
+ if (And.getOpcode() != ISD::AND || Lshr.getOpcode() != ISD::SRL)
----------------
RKSimon wrote:
This is the kind of thing I had in mind:
```cpp
if (TLI.isOperationLegal(ISD::AVGFLOORU, VT)) {
SDValue A, B;
if (sd_match(N, m_Add(m_And(m_Value(A), m_Value(B)),
m_Srl(m_Xor(m_Deferred(A), m_Deferred(B)),
m_SpecificInt(1))))) {
return DAG.getNode(ISD::AVGFLOORU, DL, VT, A, B);
}
}
```
https://github.com/llvm/llvm-project/pull/84903
More information about the llvm-commits
mailing list