Skip to content

Commit 06317df

Browse files
committed
[SelectionDAG] Fold (avg x, 0) -> x >> 1
1 parent cceedc9 commit 06317df

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5135,7 +5135,13 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
51355135
if (N0 == N1 && Level >= AfterLegalizeTypes)
51365136
return N0;
51375137

5138-
// TODO If we use avg for scalars anywhere, we can add (avgfl x, 0) -> x >> 1
5138+
// fold (avgfloor x, 0) -> x >> 1
5139+
if (isNullOrNullSplat(N1)) {
5140+
if (Opcode == ISD::AVGFLOORS)
5141+
return DAG.getNode(ISD::SRA, DL, VT, N0, DAG.getConstant(1, DL, VT));
5142+
if (Opcode == ISD::AVGFLOORU)
5143+
return DAG.getNode(ISD::SRL, DL, VT, N0, DAG.getConstant(1, DL, VT));
5144+
}
51395145

51405146
return SDValue();
51415147
}

0 commit comments

Comments
 (0)