Skip to content

Commit 92fbc96

Browse files
authored
[AMDGPU] Always lower s/udiv64 by constant to MUL (#100723)
Solves #100383
1 parent 9dadb1f commit 92fbc96

File tree

7 files changed

+1923
-1542
lines changed

7 files changed

+1923
-1542
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6405,7 +6405,12 @@ SDValue TargetLowering::BuildSDIV(SDNode *N, SelectionDAG &DAG,
64056405
if (VT.isVector())
64066406
WideVT = EVT::getVectorVT(*DAG.getContext(), WideVT,
64076407
VT.getVectorElementCount());
6408-
if (isOperationLegalOrCustom(ISD::MUL, WideVT)) {
6408+
// Some targets like AMDGPU try to go from SDIV to SDIVREM which is then
6409+
// custom lowered. This is very expensive so avoid it at all costs for
6410+
// constant divisors.
6411+
if ((isOperationExpand(ISD::SDIV, VT) &&
6412+
isOperationCustom(ISD::SDIVREM, VT.getScalarType())) ||
6413+
isOperationLegalOrCustom(ISD::MUL, WideVT)) {
64096414
X = DAG.getNode(ISD::SIGN_EXTEND, dl, WideVT, X);
64106415
Y = DAG.getNode(ISD::SIGN_EXTEND, dl, WideVT, Y);
64116416
Y = DAG.getNode(ISD::MUL, dl, WideVT, X, Y);
@@ -6588,7 +6593,12 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
65886593
if (VT.isVector())
65896594
WideVT = EVT::getVectorVT(*DAG.getContext(), WideVT,
65906595
VT.getVectorElementCount());
6591-
if (isOperationLegalOrCustom(ISD::MUL, WideVT)) {
6596+
// Some targets like AMDGPU try to go from UDIV to UDIVREM which is then
6597+
// custom lowered. This is very expensive so avoid it at all costs for
6598+
// constant divisors.
6599+
if ((isOperationExpand(ISD::UDIV, VT) &&
6600+
isOperationCustom(ISD::UDIVREM, VT.getScalarType())) ||
6601+
isOperationLegalOrCustom(ISD::MUL, WideVT)) {
65926602
X = DAG.getNode(ISD::ZERO_EXTEND, dl, WideVT, X);
65936603
Y = DAG.getNode(ISD::ZERO_EXTEND, dl, WideVT, Y);
65946604
Y = DAG.getNode(ISD::MUL, dl, WideVT, X, Y);

0 commit comments

Comments
 (0)