[llvm] [RISCV] Simplify code in decomposeMulByConstant. NFC (PR #100946)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 13:36:26 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
We already checked that the type is a scalar integer, so the constant node should definitely be a ConstantSDNode. We can use cast instead of dyn_cast.
---
Full diff: https://github.com/llvm/llvm-project/pull/100946.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+21-21)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index de9060699e557..9ce669a3122f5 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -21181,37 +21181,37 @@ bool RISCVTargetLowering::shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned)
bool RISCVTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
SDValue C) const {
// Check integral scalar types.
- const bool HasZmmul = Subtarget.hasStdExtZmmul();
if (!VT.isScalarInteger())
return false;
// Omit the optimization if the sub target has the M extension and the data
// size exceeds XLen.
+ const bool HasZmmul = Subtarget.hasStdExtZmmul();
if (HasZmmul && VT.getSizeInBits() > Subtarget.getXLen())
return false;
- if (auto *ConstNode = dyn_cast<ConstantSDNode>(C.getNode())) {
- // Break the MUL to a SLLI and an ADD/SUB.
- const APInt &Imm = ConstNode->getAPIntValue();
- if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
- (1 - Imm).isPowerOf2() || (-1 - Imm).isPowerOf2())
- return true;
+ auto *ConstNode = cast<ConstantSDNode>(C);
+ const APInt &Imm = ConstNode->getAPIntValue();
- // Optimize the MUL to (SH*ADD x, (SLLI x, bits)) if Imm is not simm12.
- if (Subtarget.hasStdExtZba() && !Imm.isSignedIntN(12) &&
- ((Imm - 2).isPowerOf2() || (Imm - 4).isPowerOf2() ||
- (Imm - 8).isPowerOf2()))
- return true;
+ // Break the MUL to a SLLI and an ADD/SUB.
+ if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
+ (1 - Imm).isPowerOf2() || (-1 - Imm).isPowerOf2())
+ return true;
- // Break the MUL to two SLLI instructions and an ADD/SUB, if Imm needs
- // a pair of LUI/ADDI.
- if (!Imm.isSignedIntN(12) && Imm.countr_zero() < 12 &&
- ConstNode->hasOneUse()) {
- APInt ImmS = Imm.ashr(Imm.countr_zero());
- if ((ImmS + 1).isPowerOf2() || (ImmS - 1).isPowerOf2() ||
- (1 - ImmS).isPowerOf2())
- return true;
- }
+ // Optimize the MUL to (SH*ADD x, (SLLI x, bits)) if Imm is not simm12.
+ if (Subtarget.hasStdExtZba() && !Imm.isSignedIntN(12) &&
+ ((Imm - 2).isPowerOf2() || (Imm - 4).isPowerOf2() ||
+ (Imm - 8).isPowerOf2()))
+ return true;
+
+ // Break the MUL to two SLLI instructions and an ADD/SUB, if Imm needs
+ // a pair of LUI/ADDI.
+ if (!Imm.isSignedIntN(12) && Imm.countr_zero() < 12 &&
+ ConstNode->hasOneUse()) {
+ APInt ImmS = Imm.ashr(Imm.countr_zero());
+ if ((ImmS + 1).isPowerOf2() || (ImmS - 1).isPowerOf2() ||
+ (1 - ImmS).isPowerOf2())
+ return true;
}
return false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/100946
More information about the llvm-commits
mailing list