@@ -21181,37 +21181,37 @@ bool RISCVTargetLowering::shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned)
21181
21181
bool RISCVTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
21182
21182
SDValue C) const {
21183
21183
// Check integral scalar types.
21184
- const bool HasZmmul = Subtarget.hasStdExtZmmul();
21185
21184
if (!VT.isScalarInteger())
21186
21185
return false;
21187
21186
21188
21187
// Omit the optimization if the sub target has the M extension and the data
21189
21188
// size exceeds XLen.
21189
+ const bool HasZmmul = Subtarget.hasStdExtZmmul();
21190
21190
if (HasZmmul && VT.getSizeInBits() > Subtarget.getXLen())
21191
21191
return false;
21192
21192
21193
- if (auto *ConstNode = dyn_cast<ConstantSDNode>(C.getNode())) {
21194
- // Break the MUL to a SLLI and an ADD/SUB.
21195
- const APInt &Imm = ConstNode->getAPIntValue();
21196
- if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
21197
- (1 - Imm).isPowerOf2() || (-1 - Imm).isPowerOf2())
21198
- return true;
21193
+ auto *ConstNode = cast<ConstantSDNode>(C);
21194
+ const APInt &Imm = ConstNode->getAPIntValue();
21199
21195
21200
- // Optimize the MUL to (SH*ADD x, (SLLI x, bits)) if Imm is not simm12.
21201
- if (Subtarget.hasStdExtZba() && !Imm.isSignedIntN(12) &&
21202
- ((Imm - 2).isPowerOf2() || (Imm - 4).isPowerOf2() ||
21203
- (Imm - 8).isPowerOf2()))
21204
- return true;
21196
+ // Break the MUL to a SLLI and an ADD/SUB.
21197
+ if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
21198
+ (1 - Imm).isPowerOf2() || (-1 - Imm).isPowerOf2())
21199
+ return true;
21205
21200
21206
- // Break the MUL to two SLLI instructions and an ADD/SUB, if Imm needs
21207
- // a pair of LUI/ADDI.
21208
- if (!Imm.isSignedIntN(12) && Imm.countr_zero() < 12 &&
21209
- ConstNode->hasOneUse()) {
21210
- APInt ImmS = Imm.ashr(Imm.countr_zero());
21211
- if ((ImmS + 1).isPowerOf2() || (ImmS - 1).isPowerOf2() ||
21212
- (1 - ImmS).isPowerOf2())
21213
- return true;
21214
- }
21201
+ // Optimize the MUL to (SH*ADD x, (SLLI x, bits)) if Imm is not simm12.
21202
+ if (Subtarget.hasStdExtZba() && !Imm.isSignedIntN(12) &&
21203
+ ((Imm - 2).isPowerOf2() || (Imm - 4).isPowerOf2() ||
21204
+ (Imm - 8).isPowerOf2()))
21205
+ return true;
21206
+
21207
+ // Break the MUL to two SLLI instructions and an ADD/SUB, if Imm needs
21208
+ // a pair of LUI/ADDI.
21209
+ if (!Imm.isSignedIntN(12) && Imm.countr_zero() < 12 &&
21210
+ ConstNode->hasOneUse()) {
21211
+ APInt ImmS = Imm.ashr(Imm.countr_zero());
21212
+ if ((ImmS + 1).isPowerOf2() || (ImmS - 1).isPowerOf2() ||
21213
+ (1 - ImmS).isPowerOf2())
21214
+ return true;
21215
21215
}
21216
21216
21217
21217
return false;
0 commit comments