[PATCH] D152300: [RISCV] Add early out to generateInstSeq when the initial sequence is 1 or 2 instructions.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 12:13:26 PDT 2023
craig.topper created this revision.
craig.topper added reviewers: reames, jrtc27, asb, luismarques.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
This avoids checking the size of the sequence repeatedly for each
special case. Especially on RV32 where none of the special cases
apply.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152300
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -197,11 +197,18 @@
Res = TmpSeq;
}
+ // If we have a 1 or 2 instruction sequence this is the best we can do. This
+ // will always be true for RV32 and will often be true for RV64.
+ if (Res.size() <= 2)
+ return Res;
+
+ assert(ActiveFeatures[RISCV::Feature64Bit] &&
+ "Expected RV32 to only need 2 instructions");
+
// If the constant is positive we might be able to generate a shifted constant
// with no leading zeros and use a final SRLI to restore them.
- if (Val > 0 && Res.size() > 2) {
- assert(ActiveFeatures[RISCV::Feature64Bit] &&
- "Expected RV32 to only need 2 instructions");
+ if (Val > 0) {
+ assert(Res.size() > 2 && "Expected longer sequence");
unsigned LeadingZeros = llvm::countl_zero((uint64_t)Val);
uint64_t ShiftedVal = (uint64_t)Val << LeadingZeros;
// Fill in the bits that will be shifted out with 1s. An example where this
@@ -244,9 +251,6 @@
// Perform optimization with BCLRI/BSETI in the Zbs extension.
if (Res.size() > 2 && ActiveFeatures[RISCV::FeatureStdExtZbs]) {
- assert(ActiveFeatures[RISCV::Feature64Bit] &&
- "Expected RV32 to only need 2 instructions");
-
// 1. For values in range 0xffffffff 7fffffff ~ 0xffffffff 00000000,
// call generateInstSeqImpl with Val|0x80000000 (which is expected be
// an int32), then emit (BCLRI r, 31).
@@ -299,8 +303,6 @@
// Perform optimization with SH*ADD in the Zba extension.
if (Res.size() > 2 && ActiveFeatures[RISCV::FeatureStdExtZba]) {
- assert(ActiveFeatures[RISCV::Feature64Bit] &&
- "Expected RV32 to only need 2 instructions");
int64_t Div = 0;
unsigned Opc = 0;
RISCVMatInt::InstSeq TmpSeq;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152300.528983.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230606/b6e10ecc/attachment.bin>
More information about the llvm-commits
mailing list