@@ -1930,9 +1930,11 @@ static bool isDivRemLibcallAvailable(SDNode *Node, bool isSigned,
1930
1930
return TLI.getLibcallName (LC) != 0 ;
1931
1931
}
1932
1932
1933
- // / UseDivRem - Only issue divrem libcall if both quotient and remainder are
1933
+ // / useDivRem - Only issue divrem libcall if both quotient and remainder are
1934
1934
// / needed.
1935
- static bool UseDivRem (SDNode *Node, bool isSigned, bool isDIV) {
1935
+ static bool useDivRem (SDNode *Node, bool isSigned, bool isDIV) {
1936
+ // The other use might have been replaced with a divrem already.
1937
+ unsigned DivRemOpc = isSigned ? ISD::SDIVREM : ISD::UDIVREM;
1936
1938
unsigned OtherOpcode = 0 ;
1937
1939
if (isSigned)
1938
1940
OtherOpcode = isDIV ? ISD::SREM : ISD::SDIV;
@@ -1946,7 +1948,7 @@ static bool UseDivRem(SDNode *Node, bool isSigned, bool isDIV) {
1946
1948
SDNode *User = *UI;
1947
1949
if (User == Node)
1948
1950
continue ;
1949
- if (User->getOpcode () == OtherOpcode &&
1951
+ if (( User->getOpcode () == OtherOpcode || User-> getOpcode () == DivRemOpc) &&
1950
1952
User->getOperand (0 ) == Op0 &&
1951
1953
User->getOperand (1 ) == Op1)
1952
1954
return true ;
@@ -3092,7 +3094,7 @@ void SelectionDAGLegalize::ExpandNode(SDNode *Node) {
3092
3094
Tmp3 = Node->getOperand (1 );
3093
3095
if (TLI.isOperationLegalOrCustom (DivRemOpc, VT) ||
3094
3096
(isDivRemLibcallAvailable (Node, isSigned, TLI) &&
3095
- UseDivRem (Node, isSigned, false ))) {
3097
+ useDivRem (Node, isSigned, false ))) {
3096
3098
Tmp1 = DAG.getNode (DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue (1 );
3097
3099
} else if (TLI.isOperationLegalOrCustom (DivOpc, VT)) {
3098
3100
// X % Y -> X-X/Y*Y
@@ -3120,7 +3122,7 @@ void SelectionDAGLegalize::ExpandNode(SDNode *Node) {
3120
3122
SDVTList VTs = DAG.getVTList (VT, VT);
3121
3123
if (TLI.isOperationLegalOrCustom (DivRemOpc, VT) ||
3122
3124
(isDivRemLibcallAvailable (Node, isSigned, TLI) &&
3123
- UseDivRem (Node, isSigned, true )))
3125
+ useDivRem (Node, isSigned, true )))
3124
3126
Tmp1 = DAG.getNode (DivRemOpc, dl, VTs, Node->getOperand (0 ),
3125
3127
Node->getOperand (1 ));
3126
3128
else if (isSigned)
0 commit comments