[llvm] [RISCV] Add freeze when expanding mul by constant to two or more uses (PR #89290)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 11:41:21 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Philip Reames (preames)
<details>
<summary>Changes</summary>
topperc pointed this out in review of https://github.com/llvm/llvm-project/pull/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.
---
Full diff: https://github.com/llvm/llvm-project/pull/89290.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+12-11)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index b0deb1d2669952..b48033956acf3e 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -13430,10 +13430,11 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
if (ScaleShift >= 1 && ScaleShift < 4) {
unsigned ShiftAmt = Log2_64((MulAmt & (MulAmt - 1)));
SDLoc DL(N);
- SDValue Shift1 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
- DAG.getConstant(ShiftAmt, DL, VT));
- SDValue Shift2 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
- DAG.getConstant(ScaleShift, DL, VT));
+ SDValue X = DAG.getFreeze(N->getOperand(0));
+ SDValue Shift1 =
+ DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ShiftAmt, DL, VT));
+ SDValue Shift2 =
+ DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ScaleShift, DL, VT));
return DAG.getNode(ISD::ADD, DL, VT, Shift1, Shift2);
}
}
@@ -13464,13 +13465,13 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
if (ScaleShift >= 1 && ScaleShift < 4) {
unsigned ShiftAmt = Log2_64(((MulAmt - 1) & (MulAmt - 2)));
SDLoc DL(N);
- SDValue Shift1 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
- DAG.getConstant(ShiftAmt, DL, VT));
- SDValue Shift2 = DAG.getNode(ISD::SHL, DL, VT, N->getOperand(0),
- DAG.getConstant(ScaleShift, DL, VT));
- return DAG.getNode(
- ISD::ADD, DL, VT, Shift1,
- DAG.getNode(ISD::ADD, DL, VT, Shift2, N->getOperand(0)));
+ SDValue X = DAG.getFreeze(N->getOperand(0));
+ SDValue Shift1 =
+ DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ShiftAmt, DL, VT));
+ SDValue Shift2 =
+ DAG.getNode(ISD::SHL, DL, VT, X, DAG.getConstant(ScaleShift, DL, VT));
+ return DAG.getNode(ISD::ADD, DL, VT, Shift1,
+ DAG.getNode(ISD::ADD, DL, VT, Shift2, X));
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/89290
More information about the llvm-commits
mailing list