Skip to content

Commit 9a35951

Browse files
authored
[RISCV] Add freeze when expanding mul by constant to two or more uses (#89290)
topperc pointed this out in review of #88791, but I believe the problem applies here as well. Worth noting is that the code I introduced with this bug was mostly copied from other targets - which also have this bug.
1 parent 2834e8a commit 9a35951

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13430,10 +13430,11 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
1343013430
if (ScaleShift >= 1 && ScaleShift < 4) {
1343113431
unsigned ShiftAmt = Log2_64((MulAmt & (MulAmt - 1)));
1343213432
SDLoc DL(N);
13433-
SDValue Shift1 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
13434-
DAG.getConstant(ShiftAmt, DL, VT));
13435-
SDValue Shift2 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
13436-
DAG.getConstant(ScaleShift, DL, VT));
13433+
SDValue X = DAG.getFreeze(N->getOperand(0));
13434+
SDValue Shift1 =
13435+
DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ShiftAmt, DL, VT));
13436+
SDValue Shift2 =
13437+
DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ScaleShift, DL, VT));
1343713438
return DAG.getNode(ISD::ADD, DL, VT, Shift1, Shift2);
1343813439
}
1343913440
}
@@ -13464,13 +13465,13 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
1346413465
if (ScaleShift >= 1 && ScaleShift < 4) {
1346513466
unsigned ShiftAmt = Log2_64(((MulAmt - 1) & (MulAmt - 2)));
1346613467
SDLoc DL(N);
13467-
SDValue Shift1 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
13468-
DAG.getConstant(ShiftAmt, DL, VT));
13469-
SDValue Shift2 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
13470-
DAG.getConstant(ScaleShift, DL, VT));
13471-
return DAG.getNode(
13472-
ISD::ADD, DL, VT, Shift1,
13473-
DAG.getNode(ISD::ADD, DL, VT, Shift2, N->getOperand(0)));
13468+
SDValue X = DAG.getFreeze(N->getOperand(0));
13469+
SDValue Shift1 =
13470+
DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ShiftAmt, DL, VT));
13471+
SDValue Shift2 =
13472+
DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ScaleShift, DL, VT));
13473+
return DAG.getNode(ISD::ADD, DL, VT, Shift1,
13474+
DAG.getNode(ISD::ADD, DL, VT, Shift2, X));
1347413475
}
1347513476
}
1347613477

0 commit comments

Comments
 (0)