5260 Commits

Author SHA1 Message Date
Djordje Todorovic
b2e6b98783
[MIPS] Fix argument size in Fast ISel (#180336)
Fix bug where Fast ISel incorrectly set `IncomingArgSize` to `0` for
functions with no arguments, since `MIPS O32` uses _the reserved
argument area_ of 16 bytes even for the functions with no args at all.
2026-02-09 21:36:35 +08:00
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
YunQiang Su
c7e3bddbfd
MIPS: readsWritesFloatRegister, inc Idx for continue (#179932)
Otherwise, the input register will also be treat as write.
2026-02-06 08:15:01 +08:00
YunQiang Su
209ff8bf06
MIPS: Fix unsigned compare with zero in MipsSEInstrInfo::copyPhysReg (#179866)
SrcRegOff >= 0 is not needed at all for unsigned.

This fixes the warning:
```
llvm/lib/Target/Mips/MipsSEInstrInfo.cpp: In member function ‘virtual void llvm::MipsSEInstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineBasicBlock::iterator, const llvm::DebugLoc&, llvm::Register, llvm::Register, bool, bool, bool) const’:
llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:245:48: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
  245 |       if (SrcRegOff == DestRegOff && SrcRegOff >= 0 && SrcRegOff <= 31)
      |                                      ~~~~~~~~~~^~~~
llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:256:48: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
  256 |       if (SrcRegOff == DestRegOff && SrcRegOff >= 0 && SrcRegOff <= 31)
```
2026-02-05 17:09:22 +08:00
Jay Foad
7ea33e6848
[CodeGen] Remove unused first operand of SUBREG_TO_REG (#179690)
The first input operand of SUBREG_TO_REG was an immediate that most
targets set to 0. In practice it had no effect on codegen. Remove it.
2026-02-04 17:35:21 +00:00
Juan Manuel Martinez Caamaño
49bf907c83
[NFC][LLVM] Make MachineInstrBuilder::constrainAllUses return void (#179632)
This function always returns `true`; so we can transform it to return
`void` and simplify the code.

Follow up of https://github.com/llvm/llvm-project/pull/179501 .
2026-02-04 12:06:10 +01:00
Juan Manuel Martinez Caamaño
04c56505f8
[NFC][LLVM] Make constrainSelectedInstRegOperands return void (#179501)
`constrainSelectedInstRegOperands` always returns `true`; so it can be
safely transformed to return `void` instead.

A follow-up patch should update `MachineInstrBuilder::constrainAllUses`.
2026-02-04 08:59:16 +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
Nikita Popov
792670a400
[X86][WinEH] Insert nop after unwinding inline assembly (#176393)
As discussed on https://github.com/llvm/llvm-project/pull/144745, insert
a nop after unwinding inline assembly, as it may end on a call.

While the change itself is trivial, I ended up having to do two
infrastructure changes:
* The unwind flag needs to be propagated to ExtraInfo of the
MachineInstr.
* The MachineInstr needs to be passed through to emitInlineAsmEnd(), and
the method needs to be non-const.

Fixes https://github.com/llvm/llvm-project/issues/157073.
2026-01-19 09:09:04 +01:00
Christudasan Devadasan
9e1606026c
[CodeGen][InlineSpiller] Add SubReg argument to loadRegFromStackSlot for subreg-reload (#175581)
This preparatory patch introduces an additional argument to the target hook
loadRegFromStackSlot. Ths is essential for targets to handle subregister-specific
reload in the future. See how this is used for AMDGPU target with PR #175002.
2026-01-13 08:21:58 +05:30
Trevor Gross
3920bc61ca
[TargetLowering] Change the softPromoteHalfType default to true (#175149)
The default `f16` lowering has some issues that result in incorrect
float behavior, so over time most targets have switched to use
`softPromoteHalfType`. Swap to soft promotion by default and add
overrides for SystemZ and AMDGPU, which are the two remaining backends
that still depend on this behavior.

All basic `f16` op tests now pass on all remaining experimental arches.

Fixes: https://github.com/llvm/llvm-project/issues/97981
Fixes: https://github.com/llvm/llvm-project/issues/97975
2026-01-11 12:48:26 +01:00
yingopq
15564a8394
[Mips] Add MipsPat (MipsGPRel tglobaladdr:$in) to select MipsISD::GPRel TargetGlobalAddress (#165531)
The original logic:
```
SelectionDAG has 17 nodes:
  t0: ch,glue = EntryToken
          t2: i64,ch = CopyFromReg t0, Register:i64 %0
        t11: i32 = truncate t2
      t14: i32 = and t11, Constant:i32<1>
        t20: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str.1> 0 [TF=3]
      t21: i64 = add Register:i64 $gp_64, t20
        t16: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str> 0 [TF=3]
      t18: i64 = add Register:i64 $gp_64, t16
    t7: i64 = select t14, t21, t18
```

When SelectionDAG process visitSELECT, would fold select(cond,
binop(x, y), binop(x, z)) to binop(x, select(cond, y, z)).
As follows:
```
SelectionDAG has 16 nodes:
  t0: ch,glue = EntryToken
            t2: i64,ch = CopyFromReg t0, Register:i64 %0
          t11: i32 = truncate t2
        t14: i32 = and t11, Constant:i32<1>
        t20: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str.1> 0 [TF=3]
        t16: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str> 0 [TF=3]
      t22: i64 = select t14, t20, t16
    t23: i64 = add Register:i64 $gp_64, t22
```

Therefore, the original MipsPat `add GPR64:$gp, (MipsGPRel
tglobaladdr:$in)` is no longer available. And there would be an assert:
```
ISEL: Starting selection on root node: t20: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str.1> 0 [TF=3]
ISEL: Starting pattern match
  Initial Opcode index to 0
  Match failed at index 0
LLVM ERROR: Cannot select: t20: i64 = MipsISD::GPRel TargetGlobalAddress:i64<ptr @.str.1> 0 [TF=3]
```

So we add a new MipsPat `def : MipsPat<(MipsGPRel tglobaladdr:$in),
              (DADDiu ZERO_64, tglobaladdr:$in)>, ISA_MIPS3, ABI_N64;`
to parse MipsISD::GPRel TargetGlobalAddress.


Fix #142060.
2026-01-08 11:31:27 +01:00
YunQiang Su
fdc393f9ee
MIPS: expandDivRem add a NOP after BNE (#174908)
If we compile a C code or IR file directly, the delay slot of BNE emit
by us won't be filled with a NOP.

We should fill it ourself, otherwise, the break instruction may be used
as the delay slot.
2026-01-08 16:36:00 +08:00
willmafh
2eb8ee137f
[NFC] Delete unnecessary apostrophe at the end of its (#173974) 2026-01-04 20:02:40 +08:00
yingopq
eb3bfeed9d
[Mips] Add support for Mips::GPR64Idx in MipsRegisterBankInfo (#173534)
Fix #166002.
2025-12-26 18:49:55 +08:00
YunQiang Su
22c01f6873
MIPSr6: Set FSELECT Legal for f64 (#173591)
FIX: #172459
Since SETCC returns i1 in IR level, and SEL_D needs f64, currently, we
expand FSELECT to:
   MTC1_D64
   SEL
which may generate needless mfc1 and mtc1.

In this patch, we add FGR64CC Register type, and support F32 to F64 in
MipsSEInstrInfo::copyPhysReg.
2025-12-26 18:49:41 +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
016c0b50ce
MIPSr6: Set SETCC CondCode not supported by hardware to Expand (#173541)
With the current custom match rules, we may generate code like
```
  cmp.ueq.s $f0, $f12, $f14
  mfc1 $1, $f0
  not $1, $1
  mtc1 $1, $f0
  sel.s $f0, $f14, $f12
  jrc $ra
```
With Expand, we can get:
```
  cmp.ueq.s $f0, $f12, $f14
  sel.s $f0, $f12, $f14
  jrc $ra
```
2025-12-26 09:16:32 +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
Erik Enikeev
4cbaa40f70
[mips][micromips] Add mayRaiseFPException to appropriate instructions, mark all instructions that read FCSR (FCR31) rounding bits as doing so (#170322) 2025-12-18 23:06:36 +01: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
Nikita Popov
01846a9400 [Mips] Use getSigned() for LwConstant32 immedate 2025-12-16 09:28:33 +01:00
ArielCPU
d901485655
[Mips] Add compact branch patterns for MipsR6 (#171131)
Added patterns for combining set and branch into one compact branch

The patterns are disabled if -mips-compact-branches=never
2025-12-12 20:55:12 +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
Matt Arsenault
0c2701fe7f
CodeGen: Make all targets override pseudos with pointers (#159881)
This eliminates the need to have PointerLikeRegClass handling in
codegen.
2025-11-26 14:57:14 +00:00
Matt Arsenault
1c5b1501ca
CodeGen: Move libcall lowering configuration to subtarget (#168621)
Previously libcall lowering decisions were made directly
in the TargetLowering constructor. Pull these into the subtarget
to facilitate turning LibcallLoweringInfo into a separate analysis
in the future.
2025-11-25 11:59:56 -05: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
Matt Arsenault
4155cdc0f1
Mips: Remove manual libcall name search and table (#168595)
This should really check if the libcall is known supported.
For now mips doesn't configure its RuntimeLibcallsInfo
correctly, and does not have any of the mips16 calls in it.
For now there isn't a way to add them without triggering conflicting
cases in tablegen, so keep parsing the raw name as it was before.
2025-11-18 15:01:30 -05:00
Craig Topper
0845c5a7c4
[Mips] Remove implicit conversions of MCRegister to unsigned. NFC (#167645) 2025-11-12 08:43:55 -08:00
Matt Arsenault
1f3f522866
CodeGen: Remove TRI arguments from stack load/store hooks (#158240)
This is directly available in TargetInstrInfo
2025-11-10 16:24:39 -08:00
Matt Arsenault
55422e804b
CodeGen: Remove TRI argument from getRegClass (#158225)
TargetInstrInfo now directly holds a reference to TargetRegisterInfo
and does not need TRI passed in anywhere.
2025-11-10 15:43:55 -08:00
Matt Arsenault
11ab23c33d
CodeGen: Keep reference to TargetRegisterInfo in TargetInstrInfo (#158224)
Both conceptually belong to the same subtarget, so it should not
be necessary to pass in the context TargetRegisterInfo to any
TargetInstrInfo member. Add this reference so those superfluous
arguments can be removed.

Most targets placed their TargetRegisterInfo as a member
in TargetInstrInfo. A few had this owned by the TargetSubtargetInfo,
so unify all targets to look the same.
2025-11-10 22:40:39 +00:00
Kazu Hirata
d93982347b
[Target] Fix misleading indentation (NFC) (#167206)
Identified with readability-misleading-indentation.
2025-11-09 10:30:37 -08:00
Kazu Hirata
50faea28fb
[llvm] Use conventional enum declarations (NFC) (#166318)
This patch replaces:

  using Foo = enum { A, B, C };

with the more conventional:

  enum Foo { A, B, C };

These two enum declaration styles are not identical, but their
difference does not matter in these .cpp files.  With the "using Foo"
style, the enum is unnamed and cannot be forward-declared, whereas the
conventional style creates a named enum that can be.  Since these
changes are confined to .cpp files, this distinction has no practical
impact here.
2025-11-04 07:12:53 -08:00
Jakub Kuderski
4c21d0cb14
[ADT] Prepare to deprecate variadic StringSwitch::Cases. NFC. (#166020)
Update all uses of variadic `.Cases` to use the initializer list
overload instead. I plan to mark variadic `.Cases` as deprecated in a
followup PR.

For more context, see https://github.com/llvm/llvm-project/pull/163117.
2025-11-02 00:12:33 +00:00
Kazu Hirata
84857775b7
[Target] Add "override" where appropriate (NFC) (#165083)
Note that "override" makes "virtual" redundant.

Identified with modernize-use-override.
2025-10-25 06:23:43 -07: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
yingopq
51eee2010d
[Mips] Fix clang crashes when assembling invalid MIPS beql instructions with --arch=mips (#156413)
From clang version 4, mips append new instruction BeqImm and
BEQLImm, the second operand format of instruction is imm64:$imm.

1.When Mips process `beql $t0, ($t0), 1`, it think the second operand
was an imm, so match success. Then mips backend process expandBranchImm,
check the second operand `$t0` was not imm, reported asserts.
We can strengthen the second operand matching restrictions.

2.Similarly, when Mips process `beql $t0, (1), 1`, it think the second
was an imm. so match success. Then mips backend process expandBranchImm,
check the third operand `1` was not expression, reported asserts. Permit
the third operand of `beql`  to be imm.

Fixes #151453.
2025-10-10 16:40:22 +08: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
yingopq
114b3b8b04
[Mips] Fix atomic min/max generate mips4 instructions when compiling for mips2 (#159717)
Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
https://github.com/llvm/llvm-project/pull/149983 and resubmit this PR.
The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix #145411.
2025-09-25 23:29:13 -04:00
Rahul Joshi
b7908e3841
[NFC][MC][CodeEmitterGen] Extract error reporting into a helper function (#159778)
Extract error reporting code emitted by CodeEmitterGen into
MCCodeEmitter static members functions.
Additionally, remove unused ErrorHandling.h header from several files.
2025-09-23 09:05:10 -07:00