935 Commits

Author SHA1 Message Date
Djordje Todorovic
15c9c77ccf
[MIPS] Do not silently ignore musttail (#178310)
Do not silently ignore musttail markings if UseMipsTailCalls is false.
2026-02-07 08:18:35 +01:00
Rick Gaiser
f4b593a792
[Mips] Add r5900 (PlayStation 2 Emotion Engine) CPU support (#176666)
This PR adds basic support for the MIPS R5900 CPU, the Emotion Engine
processor used in the PlayStation 2.

**LLVM changes:**
- Add r5900 CPU definition (with soft float support for now)
- Disable instructions not supported by r5900 (64-bit multiply/divide,
LL/SC atomics, COP3)
- Add r5900 specific short loop delay slot fix (hardware errata
workaround)
- Set ISA extension `AFL_EXT_5900` in ELF flags for proper ABI
identification

**Clang changes:**
- Add r5900 as a valid CPU target for `-mcpu=r5900`
- Add r5900 to CPU test coverage
2026-01-28 04:32:59 -05:00
Djordje Todorovic
bdfe03bbce
[MIPS][ISel] Fix musttail (#161860)
Properly handle clang::musttail attribute on MIPS backend.

It fixes: https://github.com/llvm/llvm-project/issues/161193
2026-01-27 19:55:22 +01:00
Sam Elliott
7184229fea
[NFC][MI] Tidy Up RegState enum use (2/2) (#177090)
This Change makes `RegState` into an enum class, with bitwise operators.
It also:
- Updates declarations of flag variables/arguments/returns from
`unsigned` to `RegState`.
- Updates empty RegState initializers from 0 to `{}`.

If this is causing problems in downstream code:
- Adopt the `RegState getXXXRegState(bool)` functions instead of using a
ternary operator such as `bool ? RegState::XXX : 0`.
- Adopt the `bool hasRegState(RegState, RegState)` function instead of
using a bitwise check of the flags.
2026-01-23 00:19:03 -08:00
Matt Arsenault
2c9cc88e25
FastISel: Thread LibcallLoweringInfo through (#176799)
Boilerplate change to prepare to take LibcallLoweringInfo from
an analysis. For now, it just sets it from the copy inside of
TargetLowering.
2026-01-19 20:44:48 +00:00
willmafh
2eb8ee137f
[NFC] Delete unnecessary apostrophe at the end of its (#173974) 2026-01-04 20:02:40 +08:00
Erik Enikeev
a910b2e28b
[Mips] Mark function calls as possibly changing FCSR (FCR31) (#170314)
This patch does the same changes as D143001 for AArch64 and #160699 for
ARM.
2025-12-26 16:32:03 +08:00
YunQiang Su
c907d7d031
Mips: Improve MipsAsmParser::expandDivRem (#172967)
Fixes: #172965

In fact MipsAsmParser::expandDivRem is in a so bad status:
1. Div may not execute at all in most case
```
   .set    reorder
   bnez    $3, $tmp0
   div     $zero, $2, $3
   break   7
$tmp0:
```

`.set reorder` may insert a nop after bnez, which will skip `div` if $3
is not zero.

2. `break   6` is wrong here.
2025-12-23 08:23:35 +08:00
Frederik Harwath
6ad41bcc49
[CodeGen] expand-fp: Change frem expansion criterion (#158285)
The existing condition for checking whether or not to expand an frem
instruction in expand-fp is not sufficiently precise.
The expansion on other targets than AMDGPU - which is the only intended
user right now - is only prevented due to the interaction with the
MaxLegalFpConvertBitWidth check.  Relying on this is conceptually wrong
and limits the use of the pass for other targets and further expansions
(e.g. merging with the similar ExpandLargeDivRem pass).

Change the expansion criterion to always expand frem of a given type
for targets that use "Expand" as the legalization action for the 
underlying scalar type and use this to exit the pass early for targets 
which do not require any expansions. This requires to change the
frem legalization action for all targets which do not want frem to 
be expanded in this pass from "Expand" to "LibCall".

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-12-16 17:31:26 +01:00
yingopq
64dfc26237
[Mips] Support "$sp" named register (#171793)
Because previous pr:
https://github.com/llvm/llvm-project/pull/136821 has test failures on
builder llvm-clang-x86_64-expensive-checks-ubuntu when enable
`-verify-machineinstrs`. So revert that pr.

This new pr change:
1. add `-verify-machineinstrs` in RUN command.
2. wirte register before reading to avoid error `Bad machine code: Using
an undefined physical register`.

Fix #47656.
2025-12-12 16:11:29 +08:00
YunQiang Su
9f7fff19a1 Revert "[Mips] Support "$sp" named register (#136821)"
This reverts commit 13012fe20816c7ce7a4eec62b325a131b6570593.
2025-12-09 16:59:28 +08:00
yingopq
13012fe208
[Mips] Support "$sp" named register (#136821)
Fix #47656.
2025-12-09 16:25:00 +08:00
Sergei Barannikov
3ea796e023
[Mips] TableGen-erate SDNode descriptions (#168307)
This allows SDNodes to be validated against their expected type profiles
and reduces the number of changes required to add a new node.

Many DSP nodes were failing validation, this is fixed as part of this
PR.

Part of #119709.

Pull Request: https://github.com/llvm/llvm-project/pull/168307
2025-12-05 14:53:14 +00:00
Erik Enikeev
9c2d5e2994
[Mips] Set custom lowering for STRICT_FSETCC/STRICT_FSETCCS ops. (#168303) 2025-11-25 00:02:37 -05:00
Erik Enikeev
f0bb5cfda7
[Mips] Add instruction selection for strict FP (#168870)
This consists of marking the various strict opcodes as legal, and
adjusting instruction selection patterns so that 'op' is 'any_op'. The
changes are similar to those in D114946 for AArch64 and #160696 for ARM.
Only Mips32/64 FPU instructions are affected.

Added lowering for for STRICT_FP_TO_UINT and STRICT_FP_TO_SINT ops.
2025-11-24 22:07:57 -05:00
Matt Arsenault
a757c4e74e
CodeGen: Add subtarget to TargetLoweringBase constructor (#168620)
Currently LibcallLoweringInfo is defined inside of TargetLowering,
which is owned by the subtarget. Pass in the subtarget so we can
construct LibcallLoweringInfo with the subtarget. This is a temporary
step that should be revertable in the future, after LibcallLoweringInfo
is moved out of TargetLowering.
2025-11-19 19:18:13 +00:00
Kazu Hirata
96cf20658d
[llvm] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163702)
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]],
introduced as part of C++17.
2025-10-16 06:52:28 -07:00
AZero13
d95f8ffee4
[ARM][TargetLowering] Combine Level should not be a factor in shouldFoldConstantShiftPairToMask (NFC) (#156949)
This should be based on the type and instructions, and only thumb uses
combine level anyway.
2025-10-11 10:58:48 +09:00
Davide Mor
9630b321a5
[MIPS][float] Fixed SingleFloat codegen on N32/N64 targets (#140575)
This patch aims at making the combination of single-float and N32/N64
ABI properly work.

Right now when both options are enabled the compiler chooses an
incorrect ABI and in some cases even generates wrong instructions.

The floating point behavior on MIPS is controlled through 3 flags:
soft-float, single-float, fp64. This makes things complicated because
fp64 indicates the presence of 64bit floating point registers, but
cannot be easily disabled (the mips3 feature require it, but mips3 CPUs
with only 32bit floating point exist). Also if fp64 is missing it
doesn't actually disable 64bit floating point operations, because
certain MIPS1/2 CPUs support 64bit floating point with 32bit registers,
hence the single-float option.

I'm guessing that originally single-float was only intended for the
latter case, and that's the reason why it doesn't properly work on 64bit
targets.

So this patch does the following:
- Make single-float a "master disable", even if fp64 is enabled this
should completely disable generation of 64bit floating point operations,
making it available on targets which hard require fp64.
- Add proper calling conventions for N32/N64 single-float combinations.
- Fixup codegen to not generate certain 64bit floating point operations,
apparently not assigning a register class to f64 values is not enough to
prevent them from showing up.
- Add tests for the new calling conventions and codegen.
2025-09-28 10:49:40 +08:00
Nikita Popov
b2fae5b3c7
[Mips] Remove custom "original type" handling (#154082)
Replace Mips custom logic for retaining information about original types
in calling convention lowering by directly querying the OrigTy that is
now available.

There is one change in behavior here: If the return type is a struct
containing fp128 plus additional members, the result is now different,
as we no longer special case to a single fp128 member. I believe this is
fine, because this is a fake ABI anyway: Such cases should actually use
sret, and as such are a frontend responsibility, and Clang will indeed
emit these as sret, not as a return value struct. So this only impacts
manually written IR tests.
2025-08-19 09:26:38 +02:00
Nikita Popov
238c3dcd0d
[CodeGen][Mips] Remove fp128 libcall list (#153798)
Mips requires fp128 args/returns to be passed differently than i128. It
handles this by inspecting the pre-legalization type. However, for soft
float libcalls, the original type is currently not provided (it will
look like a i128 call). To work around that, MIPS maintains a list of
libcalls working on fp128.

This patch removes that list by providing the original, pre-softening
type to calling convention lowering. This is done by carrying additional
information in CallLoweringInfo, as we unfortunately do need both types
(we want the un-softened type for OrigTy, but we need the softened type
for the actual register assignment etc.)

This is in preparation for completely removing all the custom
pre-analysis code in the Mips backend and replacing it with use of
OrigTy.
2025-08-18 09:22:41 +02:00
Nikita Popov
01bc742185
[CodeGen] Give ArgListEntry a proper constructor (NFC) (#153817)
This ensures that the required fields are set, and also makes the
construction more convenient.
2025-08-15 18:06:07 +02:00
Nikita Popov
e92b7e9641
[CodeGen] Provide original IR type to CC lowering (NFC) (#152709)
It is common to have ABI requirements for illegal types: For example,
two i64 argument parts that originally came from an fp128 argument may
have a different call ABI than ones that came from a i128 argument.

The current calling convention lowering does not provide access to this
information, so backends come up with various hacks to support it (like
additional pre-analysis cached in CCState, or bypassing the default
logic entirely).

This PR adds the original IR type to InputArg/OutputArg and passes it
down to CCAssignFn. It is not actually used anywhere yet, this just does
the mechanical changes to thread through the new argument.
2025-08-11 08:57:53 +02:00
Kazu Hirata
5ebb22de6a
[Mips] Remove an unnecessary cast (NFC) (#152837)
getZExtValue() already returns uint64_t.
2025-08-09 06:58:06 -07:00
Prabhu Rajasekaran
17ccb849f3
[llvm] Extract and propagate callee_type metadata
Update MachineFunction::CallSiteInfo to extract numeric CalleeTypeIds
from callee_type metadata attached to indirect call instructions.

Reviewers: nikic, ilovepi

Reviewed By: ilovepi

Pull Request: https://github.com/llvm/llvm-project/pull/87575
2025-07-30 14:56:39 -07:00
Nikita Popov
525090e83c
Revert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773)
Reverts llvm/llvm-project#139829.

We can't just randomly change the value of constants during lowering.

Fixes https://github.com/llvm/llvm-project/issues/149295.
2025-07-28 10:36:40 +02:00
Boyao Wang
697beb3f17
[TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to take LLVM Context (#147664)
Add LLVM Context to getOptimalMemOpType and findOptimalMemOpLowering. So
that we can use EVT::getVectorVT to generate EVT type in
getOptimalMemOpType.

Related to [#146673](https://github.com/llvm/llvm-project/pull/146673).
2025-07-10 11:11:09 +08:00
Dominik Steenken
acdf1c7526
[DAG] Add generic expansion for ISD::FCANONICALIZE nodes (#142105)
This PR takes the work previously done by @pawan-nirpal-031 on X86 in
#106370, and makes it available in common code. This should enable all
targets to use `__builtin_canonicalize` for all `f(16|32|64|128)` data
types.

Canonicalization is implemented here as multiplication by `1.0`, as
suggested in [the
docs](https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic).
2025-07-08 16:12:17 +01:00
Matt Arsenault
d8ef156379
DAG: Remove verifyReturnAddressArgumentIsConstant (#147240)
The intrinsic argument is already marked with immarg so non-constant
values are rejected by the IR verifier.
2025-07-07 16:28:47 +09:00
Matt Arsenault
48155f93dd
CodeGen: Emit error if getRegisterByName fails (#145194)
This avoids using report_fatal_error and standardizes the error
message in a subset of the error conditions.
2025-06-23 16:33:35 +09:00
anbbna
019d7694df
[MIPS]Fix QNaNs in the MIPS legacy NaN encodings (#139829)
The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN
encodings, and one for sNaNs.

Fix #100495
2025-05-14 05:25:47 -04:00
YunQiang Su
02139b140b
MIPSr6: Set FMAXNUM and FMINNUM as Legal (#139009)
Now we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0.
MIPSr6's fmax/fmin just follow this rules full.

FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once:
1. Fixes FMAXNUM/FMINNUM for all targets
2. The use of FMAXNUM_IEEE/FMINNUM_IEEE are not used by middle end
anymore.
2025-05-09 07:40:02 +08:00
anbbna
69f3552d5e
[MIPS]Remove unnecessary SLL instructions on MIPS64el (#109386)
Optimize ((signext (xor (trunc X), imm)) to (xor (X, imm)).

Fix https://github.com/llvm/llvm-project/issues/99783
2025-05-07 03:42:47 -04:00
yingopq
e676866368
[Mips] Fix clang crashes when compiling a variadic function while targeting mips3 (#130558)
issue reason:
Because mips3 has the feature 'FeatureGP64Bit', when target mips3
process function `writeVarArgRegs`, the result of `getGPRSizeInBytes` is
8 and the result of `GetVarArgRegs` is `Mips::A0, Mips::A1, Mips::A2,
Mips::A3`. This would generate `gpr64 = COPY $a1` which should be `gpr64
= COPY $a1_64`.

Also when process `CC_Mips_FixedArg`, mips would CCDelegateTo
    `CC_MipsO32_FP`. In fact, it should CCDelegateTo `CC_MipsN`.

Fix #98716.
2025-04-16 10:56:06 +08:00
YunQiang Su
2218587b5b
MIPS: Support isLegalICmpImmediate and isLegalAddImmediate (#133400)
Set it to true only if isInt<16>.
By default implemention defines them to true always. For most cases,
MIPS uses 16bit IMM, and for microMIPS, ICMP and ADDiu have 16bit IMM
flavors.
2025-03-28 23:03:52 +08:00
Fangrui Song
0c5d709301 Move MIPS-specific GPRel32Directive and EK_GPRel32BlockAddress from generic code to Mips/
Follow-up to 60486292b79885b7800b082754153202bef5b1f0
gprel/gprel64 functions can now be moved from MCTargetStreamer
to MipsTargetStreamer.
2025-03-02 15:37:55 -08:00
yingopq
af1e2a374e
[Mips] Support llvm.readcyclecounter intrinsic (#127553)
The llvm.readcyclecounter intrinsic can be implemented via the `rdhwr
$2, $hwr_cc` instruction.
$hwr_cc: High-resolution cycle counter. This register provides read
access to the coprocessor 0 Count Register.

Fix #106318.
2025-02-18 11:57:23 +08:00
YunQiang Su
0d8d354b0c Revert "[Mips] Support llvm.readcyclecounter intrinsic (#114953)"
This reverts commit 9cc7ee16e3bb849fb3c0155a843bfe349a2d2175.
2025-02-11 14:37:17 +08:00
yingopq
9cc7ee16e3
[Mips] Support llvm.readcyclecounter intrinsic (#114953)
The llvm.readcyclecounter intrinsic can be implemented via the `rdhwr
$3, $hwr_cc` instruction.
$hwr_cc: High-resolution cycle counter. This register provides read
access to the coprocessor 0 Count Register.

Fix #106318.
2025-02-11 08:47:50 +08:00
Nikita Popov
88b1d16c4a [Mips] Use getSignedConstant() in or combine
Fixes https://github.com/llvm/llvm-project/issues/125954.
2025-02-06 16:27:42 +01:00
Alexander Richardson
213a939a79
[LegalizeDAG] Use Base+Offset instead of Offset+Base for jump tables
This is needed for architectures that actually use strict pointer
arithmetic instead of integers such as AArch64 with FEAT_CPA (see
https://github.com/llvm/llvm-project/pull/105669) or CHERI. Using an
index as the first operand of pointer arithmetic may result in an
invalid output.

While there are quite a few codegen changes here, these only change the
order of registers in add instructions. One MIPS combine had to be
updated to handle the new node order.

Reviewed By: topperc

Pull Request: https://github.com/llvm/llvm-project/pull/125279
2025-01-31 14:05:34 -08:00
Hervé Poussineau
26b87aad9e
[Mips] Handle declspec(dllimport) on mipsel-windows-* triples (#120912)
On Windows, imported symbols must be searched with '__imp_' prefix.
Support imported global variables and imported functions.
2025-01-21 16:18:02 +08:00
yingopq
754ed95b66
[Mips] Fix compiler crash when returning fp128 after calling a functi… (#117525)
…on returning { i8, i128 }

Fixes https://github.com/llvm/llvm-project/issues/96432.
2025-01-20 16:47:40 +08:00
Sergei Barannikov
beea456118
[Mips] Fix result type of MAdd/MSub nodes (#117455)
They have one "untyped" result in `MipsInstrInfo.td`, and this type is
used in DAG patterns.
2024-12-09 16:43:26 +08:00
Craig Topper
b076fbb844
[TargetLowering] Use Type* instead of EVT in shouldSignExtendTypeInLibCall. (#118587)
I want to use this function for GISel too so Type * is a better common
interface. All of the callers already convert EVT to Type * as needed
by calling lowering anyway.
2024-12-03 22:06:55 -08:00
Nikita Popov
3fc5bb601e
[Mips] Use getSignedConstant() for signed values (#116405)
This also adds a getSignedTargetConstant() helper, as these seem to be
fairly common in general.
2024-11-18 10:06:13 +01:00
Kazu Hirata
73e89cf66d
[Mips] Remove unused includes (NFC) (#116499)
Identified with misc-include-cleaner.
2024-11-16 12:13:26 -08:00
yingopq
debc325bb1
[MIPS] Fix failing to legalize load+call with vector of non-p2 integer (#109625)
Add a condition to check whether the vector element type is a power of 2.

Fixes #102870.
2024-09-24 09:38:38 +02:00
yingopq
1ad84d7961
[Mips] Optimize or (and $src1, mask), (shl $src2, shift) to ins (#103017)
Optimize `$dst = or (and $src1, (2**size0 - 1)), (shl $src2, size0)` to
`ins $src1, $src2, pos, size`,
where `pos = size0, size = 32 - pos`.

Fix #90325
2024-09-13 00:05:54 +08:00
YunQiang Su
c641b611f8
MIPSr6: Add llvm.is.fpclasss intrinsic support (#107857)
MIPSr6 has class.s/class.d instructions.
Let's use them for llvm.is.fpclass intrinsic.
2024-09-11 09:37:12 +08:00