[llvm] [DAG] fold avgu(zext(x), zext(y)) -> zext(avgu(x, y)) (PR #95134)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 08:41:44 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: None (c8ef)
<details>
<summary>Changes</summary>
close: #<!-- -->86301
---
Full diff: https://github.com/llvm/llvm-project/pull/95134.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+15)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 4fcbe08e4b2b9..0a78803357410 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -5236,6 +5236,21 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
return DAG.getNode(ISD::SRL, DL, VT, X,
DAG.getShiftAmountConstant(1, VT, DL));
+ // fold avgu(zext(x), zext(y)) -> zext(avgu(x, y))
+ SDValue A;
+ SDValue B;
+ if (hasOperation(ISD::AVGFLOORU, VT) &&
+ sd_match(N, m_c_BinOp(ISD::AVGFLOORU, m_ZExt(m_Value(A)),
+ m_ZExt(m_Value(B))))) {
+ SDValue AvgFloorU = DAG.getNode(ISD::AVGFLOORU, DL, A.getValueType(), A, B);
+ return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, AvgFloorU);
+ }
+ if (hasOperation(ISD::AVGCEILU, VT) &&
+ sd_match(N, m_c_BinOp(ISD::AVGCEILU, m_ZExt(m_Value(A)),
+ m_ZExt(m_Value(B))))) {
+ SDValue AvgCeilU = DAG.getNode(ISD::AVGCEILU, DL, A.getValueType(), A, B);
+ return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, AvgCeilU);
+ }
return SDValue();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95134
More information about the llvm-commits
mailing list