Skip to content

Commit a99f4a3

Browse files
committed
[SelectionDAG] Fold (avg x, 0) -> x >> 1
1 parent c0d03d2 commit a99f4a3

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
@@ -5083,7 +5083,13 @@ SDValue DAGCombiner::visitAVG(SDNode *N) {
50835083
if (N0 == N1 && Level >= AfterLegalizeTypes)
50845084
return N0;
50855085

5086-
// TODO If we use avg for scalars anywhere, we can add (avgfl x, 0) -> x >> 1
5086+
// fold (avgfloor x, 0) -> x >> 1
5087+
if (isNullOrNullSplat(N1)) {
5088+
if (Opcode == ISD::AVGFLOORS)
5089+
return DAG.getNode(ISD::SRA, DL, VT, N0, DAG.getConstant(1, DL, VT));
5090+
if (Opcode == ISD::AVGFLOORU)
5091+
return DAG.getNode(ISD::SRL, DL, VT, N0, DAG.getConstant(1, DL, VT));
5092+
}
50875093

50885094
return SDValue();
50895095
}

0 commit comments

Comments
 (0)