@@ -6405,7 +6405,12 @@ SDValue TargetLowering::BuildSDIV(SDNode *N, SelectionDAG &DAG,
6405
6405
if (VT.isVector ())
6406
6406
WideVT = EVT::getVectorVT (*DAG.getContext (), WideVT,
6407
6407
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)) {
6409
6414
X = DAG.getNode (ISD::SIGN_EXTEND, dl, WideVT, X);
6410
6415
Y = DAG.getNode (ISD::SIGN_EXTEND, dl, WideVT, Y);
6411
6416
Y = DAG.getNode (ISD::MUL, dl, WideVT, X, Y);
@@ -6588,7 +6593,12 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
6588
6593
if (VT.isVector ())
6589
6594
WideVT = EVT::getVectorVT (*DAG.getContext (), WideVT,
6590
6595
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)) {
6592
6602
X = DAG.getNode (ISD::ZERO_EXTEND, dl, WideVT, X);
6593
6603
Y = DAG.getNode (ISD::ZERO_EXTEND, dl, WideVT, Y);
6594
6604
Y = DAG.getNode (ISD::MUL, dl, WideVT, X, Y);
0 commit comments