415 Commits

Author SHA1 Message Date
Craig Topper
f58bc72759 Revert "[X86][ARM][RISCV][XCore][M68K] Invert the low bit to get the inverse predicate (NFC) (#151748)"
This reverts commit 518703806286c98bac7b84156738839f8bd55bef.

Failing M68k build bot.
2025-08-04 15:24:52 -07:00
AZero13
5187038062
[X86][ARM][RISCV][XCore][M68K] Invert the low bit to get the inverse predicate (NFC) (#151748)
All these platforms defined their predicate in such a way to allow bit
twiddling to get inverse predicates
2025-08-04 14:45:04 -07:00
Craig Topper
359c04a61c [RISCV] Remove now unused immzero operand type. NFC 2025-07-25 21:16:07 -07:00
Luke Lau
bc2004c2e4
[RISCV] Handle LHS == 0 in isVLKnownLE (#148860)
If a VL is zero then it's known to be less than or equal to every other
VL.

This looks weird on its own since a VL of zero isn't that common. The
test diffs come from a type being split resulting in a VP intrinsic's
EVL being zero.

The motivation for this is to split off part of an upcoming patch I plan
on submitting for RISCVVLOptimizer, which generalizes it to handle
recurrences, and needs to reason about an initial state of demanded VLs
set to zero.
2025-07-16 02:04:13 +08:00
Craig Topper
028dfd7756 [RISCV] Replace tab character. NFC 2025-07-14 21:53:55 -07:00
Sudharsan Veeravalli
0ae1506847
[RISCV] Add ISel patterns for Xqciac QC_SHLADD instruction (#148256)
Add a couple of patterns to generate the Xqciac QC_SHLADD shift left and
add immediate instruction.
2025-07-14 16:43:41 +05:30
UmeshKalappa
032966ff56
[RISCV] Added the MIPS prefetch extensions for MIPS RV64 P8700. (#145647)
the extension enabled with xmipscbop.

Please refer "MIPS RV64 P8700/P8700-F Multiprocessing System
Programmer’s Guide" for more info on the extension at
https://mips.com/wp-content/uploads/2025/06/P8700_Programmers_Reference_Manual_Rev1.84_5-31-2025.pdf
2025-07-03 10:59:10 +02:00
Jim Lin
2dba752f05 [RISCV] Use template version isInt<N> instead. NFC. 2025-07-03 16:22:02 +08:00
Jim Lin
283f53ac6f
[RISCV] Add isel patterns for generating XAndesPerf branch immediate instructions (#145147)
Similar to #139872. This patch adds isel patterns to match
`riscv_brcc` and `riscv_selectcc_frag` to XAndesPerf branch
instructions.
2025-07-03 12:47:53 +08:00
Sudharsan Veeravalli
67b79468fb
[RISCV] Factor out getKillRegState in copyPhysReg (NFC) (#146454)
This is used multiple times in the function.
2025-07-01 17:51:46 +05:30
Jim Lin
96ec1c29f2
[RISCV] Add nds.bfos and nds.bfoz for the short forward branch optimization. (#145836)
This adds nds.bfos and nds.bfoz, which are also supported by Andes
45-series CPUs for short forward branch optimization.
2025-06-27 10:54:41 +08:00
Craig Topper
c8243251cb
[RISCV] Remove separate immediate condition codes from RISCVCC. NFC (#145762)
This wasn't scalable and made the RISCVCC enum effectively just
a different way of spelling the branch opcodes.
    
This patch reduces RISCVCC back down to 6 enum values. The primary user
is select pseudoinstructions which now share the same encoding across
all
vendor extensions. The select opcode and condition code are used to
determine the branch opcode when expanding the pseudo.
    
The Cond SmallVector returned by analyzeBranch now returns the opcode
instead of the RISCVCC. reverseBranchCondition now works directly on
opcodes. getOppositeBranchCondition is also retained.

Stacked on #145622
2025-06-25 23:09:24 -07:00
Craig Topper
cca44e030d
[RISCV] Explicitly check for supported opcodes in optimizeCondBranch. NFC (#145622)
We don't support any of the immediate branches in this function yet so
explicitly exclude them rather than relying on isReg to return false.

Remove use of AnalyzeBranch. It doesn't help us much. Part of the code
was already getting the operands directly and it just complicated
creating a new branch.

I also inlined the modifyBranch function so we could use addReg on
BuildMI.
2025-06-25 21:28:34 -07:00
Craig Topper
c3b160bcaa
[RISCV] Remove -mattr=+no-rvc-hints (#145138)
As far as I know binutils does not have a similar option and I don't
know of a reason we shouldn't accept the RVC hint instructions.

The wording in the spec in the past suggested that maybe these
weren't valid instruction names, but that's been modified recently.
2025-06-25 08:24:24 -07:00
Craig Topper
48a21e6915
[RISCV] Fix a correctness issue in optimizeCondBranch. Prevent optimizing compare with x0. NFC (#145440)
We were incorrectly changing -1 to 0 for unsigned compares in case 1.
The comment incorrectly said UINT64_MAX is bigger than INT64_MAX, but
we were doing a signed compare and UINT64_MAX is smaller than INT64_MAX
in signed space.

Prevent changing 0 constants since we can use x0. The test cases
for these are contrived to use addi rd, x0, 0. We're more likely
to have a COPY from x0 which we already don't optimize for other
reasons.

Check if registers are virtual before calling hasOneUse. The use count
for physical registers is meaningless.
2025-06-24 15:45:06 -07:00
Sam Elliott
a6eb5eee38
[RISCV][NFC] Remove hasStdExtCOrZca (#145139)
As of 20b5728b7b1ccc4509a316efb270d46cc9526d69, C always enables Zca, so
the check `C || Zca` is equivalent to just checking for `Zca`.

This replaces any uses of `HasStdExtCOrZca` with a new `HasStdExtZca`
(with the same assembler description, to avoid changes in error
messages), and simplifies everywhere where C++ needed to check for
either C or Zca.

The Subtarget function is just deprecated for the moment.
2025-06-23 10:49:47 -07:00
Craig Topper
35e3c50731
[RISCV] Simplify macros used for commuting vector multiply-accumulate instructions. NFC (#144169)
Inline some macros that were only instantiated once.
Remove unused macros.
#undef macros when finished with them
2025-06-13 22:19:25 -07:00
Craig Topper
ef265ed230
[RISCV] Simplify macros used by RISCVInstrInfo::convertToThreeAddress. NFC (#144173)
Merge some macros that are only used once by another macro.
Rename macros to remove _MF4 where not needed.

I suspect these are artifacts from FP being split from integer in the
past.
2025-06-13 22:19:04 -07:00
Craig Topper
709ba084c5
[RISCV] Use RISCVII::getVecPolicyOpNum instead of making assumptions. NFC (#144175) 2025-06-13 22:18:12 -07:00
Craig Topper
e37707b1e8 [RISCV] Use unsigned instead of uint16_t for the Opcode argument to getVectorLowDemandedScalarBits. NFC
All the callers pass an unsigned and uint16_t arguments are unusual.
2025-06-13 18:06:03 -07:00
Luke Lau
2b8f82b830
[RISCV] Remove implicit $vl def on vleNff pseudos (#143935)
In #90049 we removed the side effect flag on the vleNff pseudos with the
reasoning that we modelled the effect of setting vl as an output
operand.

This extends this further by removing the implicit def on vl, inserting
it back in RISCVInsertVSETVLI when we also emit the PseudoReadVL.

The motiviation for this is to make it easier to handle vleff in more
places in RISCVVectorPeephole in a follow up patch, which in turn will
make migrating the last vmerge peephole over from RISCVISelDAGToDAG
easier.

Some of these tests claim that the vleff shouldn't be deleted when none
of its values are used, but these are from the initial commit in
3b5430eb0dad5. I'm not sure if these still hold today?

This also moves the fault-only-first predicate to
RISCVInstrPredicates.td since we can't rely on the implicit vl operand
anymore.
2025-06-12 23:40:57 +01:00
Jim Lin
deaf2537c2
[RISCV] Add missing immediate operand type for verifyInstruction. NFC. (#143056)
Those immediate operand type are used by Insn{16,32,48,64}.
2025-06-06 09:23:06 +08:00
Craig Topper
64e9a3f8f0 [RISCV] Use isVLPreservingConfig in isConvertibleToVMV_V_V. NFC 2025-05-30 22:59:22 -07:00
Alex Bradbury
baeec97ebd
[RISCV] Canonicalize beq/bne with x0 as first arg to beqz/bnez (#141781)
This covers similar ground as #139086. Although I think it makes sense
to land both, the practical motivation for #139086 is significantly
reduced here.

This canonicalisation makes no difference to compressibility (we have
compress patterns for the operands in either order), but it does mean
that easier to read assembly is printed, as we don't have aliases
defined for beq/bne with x0 in either position.
2025-05-29 11:28:45 +01:00
Alex Bradbury
76b6bf4789
[RISCV] Add bltu/bgeu zero => bnez/beqz canonicalisation to RISCVInstrInfo::simplifyInstruction (#141775)
We can end up with bltu/bgeu with the zero register as the 0th operand
after tail duplication and then machine copy propagation. Canonicalising
in simplifyInstruction (called from MachineCopyPropagation) both
produces easier to read assembly output, and means it's possible that
the compressed c.beqz/c.bnez forms are produced.
2025-05-29 06:46:46 +01:00
Craig Topper
93dbac706b
[RISCV] Use isVectorConfigInstr in isConvertibleToVMV_V_V. NFC (#141874) 2025-05-28 21:29:26 -07:00
Craig Topper
1695e8b3d1 [RISCV] Fix typo '==' instead of '='. NFC 2025-05-23 14:26:21 -07:00
Craig Topper
cd60ee9d6e
[RISCV] Prevent using dummy_reg_pair_with_x0 in more places. (#141273)
Similar to #141261.

These aren't easy to test without write MIR tests in areas we don't
currently have tests. I'm not sure we use X0_Pair anywhere today.

I'm going to try to migrate RISCVMakeCompressible to use copyToReg so we
can share that code instead of basically duplicating it.

I'm still concerned that target independent code may fold an
extract_subreg operation and get an incorrect register if we do start
using X0_Pair. We may have to special case dummy_reg_pair_with_x0 in the
encoder and printer to be safe.
2025-05-23 13:40:27 -07:00
Craig Topper
4a0ae4f504
[RISCV] Add LD_RV32/SD_RV32 to a few more functions in RISCVInstrInfo. (#140640)
isLoadFromStackSlot/isStoreToStackSlot/getMemOperandsWithOffsetWidth

The first 2 probably requires spills/reloads which we don't use
LD_RV32/SD_RV32 for yet.

I think getMemOperandsWithOffsetWidth is mainly used for load/store
clustering. I think we can assume this just works.
2025-05-20 09:01:03 -07:00
Craig Topper
e9c0840e9b
[RISCV] Add LD_RV32/SD_RV32 to RISCVInstrInfo::canFoldIntoAddrMode. (#140631) 2025-05-19 17:07:57 -07:00
Kazu Hirata
c51417d75b
[RISCV] Use llvm::any_of (NFC) (#140398) 2025-05-17 14:28:55 -07:00
Sudharsan Veeravalli
9a1bfc17d3
[RISCV] Add SEXT_INREG patterns for Xqcibm ext instruction (#140192)
Handle sign_extend_inreg from i1/i8/i16
2025-05-16 12:49:14 +05:30
Sudharsan Veeravalli
dc9171afc4
[RISCV] Add isel patterns for generating Xqcibi branch instructions (#139872)
Add ISEL patterns for generating the Xqcibi branch immediate
instructions. Similar to #135771 adds new CondCodes for the various
branch instructions and uses them to return the appropriate instruction.
2025-05-16 08:45:30 +05:30
Craig Topper
426573332c
[RISCV] Use RISCVRegisterInfo::isRVVRegClass to replace IsScalableVector in storeRegToStackSlot/loadRegFromStackSlot. NFC (#139979) 2025-05-15 08:34:50 -07:00
Craig Topper
8e9227a8c6
[RISCV] Use X9 instead of X27 in RISCVInstrInfo::insertIndirectBranch for RVE (#139214)
Fixes #139168.
2025-05-09 08:41:14 -07:00
Alex Bradbury
52b345d036
[RISCV][TII] Add and use new hook to simplify/canonicalize instructions after MachineCopyPropagation (#137973)
PR #136875 was posted as a draft PR that handled a subset of these
cases, using the CompressPat mechanism. The consensus from that
discussion (and a conclusion I agree with) is that it would be
beneficial doing this optimisation earlier on, and in a way that isn't
limited just to cases that can be handled by instruction compression.

The most common source for instructions that can be
optimized/canonicalized in this way is through tail duplication in
MachineBlockPlacement followed by machine copy propagation. For RISC-V,
choosing a more canonical instruction allows it to be compressed when it
couldn't be before. There is the potential that it would make other
MI-level optimisations easier.

This modifies ~910 instructions across an llvm-test-suite build
including SPEC2017, targeting rva22u64. Looking at the diff, it seems
there's room for eliminating instructions or further propagating after
this.

Coverage of instructions is based on observations from a script written
to find redundant or improperly canonicalized instructions (though I aim
to support all instructions in a 'group' at once, e.g. MUL* even if I
only saw some variants of MUL in practice).
2025-05-08 12:33:14 +01:00
Alex Bradbury
3376071a24 [RISCV][NFC] Add missed // clang-format on
clang-format was turned off for the defines, but there was no matching
`// clang-format on` comment at the end. Ran into this in #137973
2025-05-01 13:37:49 +01:00
Pengcheng Wang
8f75747935
[RISCV][NFC] Convert some predicates to TIIPredicate (#129658)
These predicates can also be used in macro fusion and scheduling
model.
2025-04-30 16:59:05 +08:00
Philip Reames
f2ecd86e34
[Analysis] Remove implicit LocationSize conversion from uint64_t (#133342)
This change removes the uint64_t constructor on LocationSize
preventing implicit conversion, and fixes up the using APIs to adapt to
the change. Note that I'm adding a couple of explicit conversion points
on routines where passing in a fixed offset as an integer seems likely
to have well understood semantics.

We had an unfortunate case which arose if you tried to pass a TypeSize
value to a parameter of LocationSize type. We'd find the implicit
conversion path through TypeSize -> uint64_t -> LocationSize which works
just fine for fixed values, but looses information and fails assertions
if the TypeSize was scalable. This change breaks the first link in that
implicit conversion chain since that seemed to be the easier one.
2025-04-18 07:46:31 -07:00
Craig Topper
23324b8b10
[RISCV] Move checking for constant 3/4 for XTHeadMemPair to the instruction matching stage. (#136165)
This removes a special case from processInstruction and removes an
untested range diagnostic we would print if the constant didn't fit in 3
bits.
2025-04-17 21:03:58 -07:00
Jim Lin
0439a4eca7
[RISCV] Add new CondCode COND_CV_BEQIMM/COND_CV_BNEIMM for CV immediate branch (#135771)
If there is another branch instruction also with immediate operand, but
it is used to specify which bit to be tested is set or clear. We only
check whether operand2 is immediate or not here. There are no way to
distinguish between them.

So add new CondCode COND_CV_BEQIMM/COND_CV_BNEIMM that we can know what
kinds of immediate branch instruction are matched in Select_* Pseudo.
2025-04-16 10:16:31 +08:00
Sudharsan Veeravalli
1d2f5ead05
[RISCV] Add symbol parsing support for Xqcili load large immediate instructions (#134581)
This patch adds support for parsing symbols in the Xqcili load large
immediate instructions. The 32 bit `qc.li` instructions uses the
`R_RISCV_QC_ABS20_U` relocation while the 48 bit `qc.e.li` instruction
uses the `R_RISCV_QC_E_32` relocation and the `InstFormatQC_EAI`
instruction format.

Vendor relocation support will be added in a later patch.
2025-04-08 22:56:26 -07:00
Craig Topper
9069ba183d [RISCV] Rename Spimm to StackAdj in most places. NFC
Spimm in the spec refers to the 2-bit encoded value. All of the code
uses the 0, 16, 32, or 48 adjustment value.

Also remove the decodeZcmpSpimm as its identical to the default
behavior for no custom DecoderMethod.
2025-04-04 12:49:09 -07:00
Alex Bradbury
71a977d0d6
[RISCV] Add shift-add (SH1ADD, ...) to isCopyInstrImpl (#133443)
As with #132002, these do show up in a compilation of llvm-test-suite
(including SPEC 2017). We remove 30-40 static instances so this isn't
anything earth shattering.

rs2 is always added to the other shifted (and potentially extended)
operand unmodified, so rs1==zero is equivalent to a copy.
2025-03-28 15:46:50 +00:00
Alex Bradbury
a481452cd8
[RISCV] Add OR/XOR/SUB to RISCVInstrInfo::isCopyInstrImpl (#132002)
This adds coverage for additional instructions in isCopyInstrImpl, for
now picking just those where I can observe that there is a codegen
difference for SPEC.

This allows MachineCopyPropagation to successfully eliminate no-op moves in this form.
2025-03-28 12:59:18 +00:00
Sam Elliott
75ca080dab
[RISCV][Xqccmp] Correctly Parse/Disassemble pushfp (#133188)
In the `qc.cm.pushfp` instruction, it is like `cm.pushfp` except in one
important way - `qc.cm.pushfp {ra}, -N*16` is not a valid encoding,
because this would update `s0`/`fp`/`x8` without saving it.

This change now correctly rejects this variant of the instruction, both
during parsing and during disassembly. I also implemented validation for
immediates that represent register lists (both kinds), which may help to
catch bugs in the future.
2025-03-27 17:43:26 -07:00
Mikhail R. Gadelha
d8e44a9ab2
[RISCV] Add late optimization pass for riscv (#133256)
This patch is an alternative to PRs #117060, #131684, #131728.

The patch adds a late optimization pass that replaces conditional
branches that can be statically evaluated with an unconditinal branch.

Adding Michael as a co-author as most of the code that evaluates the
condition comes from #131684.

Co-authored-by: Michael Maitland michaeltmaitland@gmail.com
2025-03-27 19:31:38 -03:00
Philip Reames
d584cea064
[RISCV] Use TypeSize instead of uint64_t in getMachineMemOperand interface (#133274)
The primary reason is that if you pass a TypeSize without explicitly
converting to LocationSize, you otherwise implicit convert to uint64_t
to call the respective LocationSize constructor. This means that any
scalable value becomes a runtime assertion failure.

By replacing uint64_t with TypeSize in this API, we avoid the implicit
conversion for TypeSize. uint64_t callers implicit convert to
LocationSize (via the raw constructor) which should have unchanged
behavior.
2025-03-27 11:04:00 -07:00
Philip Reames
8742022ec7
[RISCV] Canonicalize foldable branch conditions in optimizeCondBranch (#132988)
optimizeCondBranch isn't allowed to modify the CFG, but it can rewrite
the branch condition freely. However, If we could fold a conditional
branch to an unconditional one (aside from that restriction), we can
also rewrite it into some canonical conditional branch instead.

Looking at the diffs, the only cases this catches in tree tests are
cases where we could have constant folded during lowering from IR, but
didn't. This is inspired by trying to salvage code from
https://github.com/llvm/llvm-project/pull/131684 which might be useful.
Given the test impact, it's of questionable merits. The main advantage
over only the late cleanup pass is that it kills off the LIs for the
constants early - which can help e.g. register allocation.
2025-03-27 08:12:03 -07:00
Philip Reames
79e82b6f14
[RISCV] Use a precise size for MMO on scalable spill and fill (#133171)
The primary effect of this is that we get proper scalable sizes printed
by the assembler, but this may also enable proper aliasing analysis. I
don't see any test changes resulting from the later.

Getting the size is slightly tricky as we store the scalable size as a
non-scalable quantity in the object size field for the frame index. We
really should remove that hack at some point...

For the synthetic tuple spills and fills, I dropped the size from the
split loads and stores to avoid incorrect (overly large) sizes. We could
also divide by the NF factor if we felt like writing the code to do so.
2025-03-26 18:25:59 -07:00