78 Commits

Author SHA1 Message Date
Craig Topper
785b16ad04
[RISCV][GISel] Support G_MERGE_VALUES/G_UNMERGE_VALUES with Zfa. (#120379)
Without Zfa we use pseudos that are lowered to a stack load/store. With
Zfa we have instructions that can move a pair of registers to an FPR. Or
move the high or low half of an FPR to a GPR.

I've used a GINodeEquiv to make use of 3 of the 4 tablegen patterns. The
split case with Zfa requires 2 instructions which I'm doing through
custom isel like we do in SelectionDAG.
2025-01-07 07:50:50 -08:00
Sergei Barannikov
ce393beddf
[RISCV] Pattern-match frameindex (#120917) 2024-12-23 13:19:00 +03:00
Luke Quinn
6ab8401f53
[RISCV][GISel] Port AddiPair optimization (#120463)
Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1),
in which imm = imm0 + imml and both imm0 and imm1 are simm12. We make
imm0 as large as possible and imm1 as small as possible so that we might
be able to use c.addi for the small immediate.
2024-12-20 11:32:27 -08:00
Craig Topper
d78fe84d49
[RISCV][GISel] Port TrailingOnesMask PatLeaf. (#119427) 2024-12-10 22:17:52 -08:00
Craig Topper
37b10af6a0 [RISCV][GISel] Use correct shift width for GIShiftMask32 ComplexOperandMatcher.
We should use 32 instead of XLen. This allows us to remove
'and X, 31' from the shift amount.
2024-12-05 15:52:41 -08:00
Craig Topper
4087b871c5
[RISCV][GISel] Move G_BRJT expansion to legalization (#73711)
Instead of custom selecting a bunch of instructions, we can expand to
generic MIR during legalization.
2024-11-20 13:43:36 -08:00
Kazu Hirata
4048c64306
[llvm] Remove redundant control flow statements (NFC) (#115831)
Identified with readability-redundant-control-flow.
2024-11-12 10:09:42 -08:00
Kazu Hirata
10b80ff0cc
[Target] Migrate away from PointerUnion::{is,get,dyn_cast} (NFC) (#115623)
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-11-09 17:22:57 -08:00
Craig Topper
09b372aa60
[GISel][AArch64][RISCV] Allow G_SEXT_INREG patterns to be imported. (#115576)
SelectionDAG uses VTSDNode to store the extension type. GlobalISel uses
a literal constant operand.

For vectors, SelectionDAG uses a type with the same number of elements
as other operand of the sext_inreg. I assume for GISel we would just use
the scalar size.
2024-11-08 22:26:56 -08:00
Craig Topper
694719a480
[RISCV][GISel] Add G_ZEXT to RISCVInstructionSelector::selectZExtBits. (#115391) 2024-11-07 21:19:50 -08:00
Craig Topper
ae9d0623ad
[RISCV][GISel] Remove s32 input support for G_SITOFP/UITOFP on RV64. (#115236)
I plan to make i32 an illegal type for RV64 to match SelectionDAG and to
remove i32 from the GPR register class.

I've added a sexti32 ComplexPattern to select sext.w+fcvt.s.l as
fcvt.s.w. The recently added zexti32 handles selecting and+fcvt.s.lu as
fcvt.s.wu. There are still some regressions that suggest we should match
g_zero_extend in zexti32.
2024-11-07 13:57:11 -08:00
Craig Topper
da032b7903
[RISCV][GISel] Use maskedValueIsZero in RISCVInstructionSelector::selectZExtBits. (#115244) 2024-11-06 20:14:24 -08:00
Craig Topper
5dc8d61177
[RISCV][GISel] Implement zexti32/zexti16 ComplexPatterns. (#115097) 2024-11-06 08:48:43 -08:00
Michael Maitland
989c437d7f [RISCV][GISEL][NFC] Add break statement to reduce diff on future changes of preISelLower 2024-10-07 07:23:52 -07:00
Michael Maitland
f873fc3ae2
[RISCV][GISEL] instruction-select vmclr (#110782)
This is stacked on #110778. This PR adds and tests renderVLOp too, as
that is needed from vmclr.
2024-10-04 12:51:04 -04:00
Michael Maitland
a3cc4b61a0
[RISCV][GISEL][NFC] Make MRI a member in RISCVInstructionSelector (#110926)
It was requested in
https://github.com/llvm/llvm-project/pull/110782#discussion_r1784939348
that MRI be made a member of RISCVInstructionSelector.

RISCVInstructionSelector is created in the RISCVSubtarget, independent
of MachineFunction. So it cannot be passed by reference during
construction of RISCVInstructionSelector.

The MachineRegisterInfo object belongs to each MachineFunction, so
set it in setupMF.
2024-10-04 09:08:56 -04:00
Craig Topper
715c3033af
[RISCV][GISel] Support G_SEXT_INREG for Zbb. (#102682) 2024-08-14 10:34:49 -07:00
Michael Maitland
9b95d08ef6
[GISel] Make create.*InstructionSelector arguments const (#98243)
The InstructionSelector objects all take these arguments in as `const`.
This function does not modify the object. Therefore we can mark them as
`const` here.
2024-07-10 09:01:27 -04:00
Craig Topper
acd6cb85b3
[RISCV][GISel] Support fcmp and fclass for Zfh. (#96696) 2024-06-26 09:53:13 -07:00
Craig Topper
dff6871cdb [RISCV][GISel] Support G_FCONSTANT for Zfh. 2024-06-25 14:10:25 -07:00
Yingwei Zheng
643e4718af
[RISCV][GISel] Add calling convention support for half (#94110)
This patch adds initial support to the half type on RISC-V.
2024-06-09 03:44:19 +08:00
Yingwei Zheng
76748119bf
[GISel][RISCV] Add irtranslator/legalizer/selector support for G_FREEZE. (#92744)
This patch adds support for G_FREEZE on riscv. It will be selected into
a copy instruction.
 
The ll test is copied from the AArch64 patch:
665da59685.
2024-05-21 23:59:51 +08:00
Hongbin Jin
ed3a60c796
[RISCV][GlobalISel] Fix selectShiftMask when shift mask is created from G_AND (#89602)
This patch fixes cases where G_AND creating the shift mask is eliminated
if one of its source operands is a constant, resulting from an incorrect
predicate.
2024-05-09 09:18:10 -04:00
Evgenii Kudriashov
d365a45cb3
[GlobalISel] Introduce G_TRAP, G_DEBUGTRAP, G_UBSANTRAP (#84941)
Here we introduce three new GMIR instructions to cover a set of trap
intrinsics. The idea behind it is that generic intrinsics shouldn't be
used with G_INTRINSIC opcode.

These new instructions can match perfectly with existing trap ISD nodes.
It allows X86, AArch64, RISCV and Mips to reuse SelectionDAG patterns for
selection and avoid manual selection. However AMDGPU is an exception. It
selects traps during legalization regardless SelectionDAG or GlobalISel.

Since there are not many places where traps are used, this change
attempts to clean up all the usages of G_INTRINSIC with trap intrinsics. So,
there is no stage when both G_TRAP and
G_INTRINSIC_W_SIDE_EFFECTS(@llvm.trap) are allowed.
2024-03-23 13:12:44 +01:00
Jiahan Xie
10c2d5ff7c
[RISCV][GISel] RegBank select and instruction select for vector G_ADD, G_SUB (#74114)
RegisterBank Selection for scalable vector G_ADD and G_SUB by creating
new mappings for different types of vector register banks.
Then implement Instruction Selection for the same operations by choosing
the correct RISC-V vector register class.
2024-02-01 15:06:43 -05:00
Mikhail Gudim
c1f433849b
[GISel][RISCV] Implement selectShiftMask. (#77572)
Implement `selectShiftMask` in `GlobalISel`.
2024-01-17 16:25:43 -05:00
Craig Topper
00d6232d6b
[RISCV][GISel] Don't create generic virtual registers in selectSHXADDOp/selectSHXADD_UWOp. (#78396)
Since we're creating target specific instructions, I think we should be
creating registers with the GPR register class.
2024-01-16 22:22:58 -08:00
Craig Topper
d605d9d7a1
[RISCV][GISel] Support G_ROTL/G_ROTR with Zbb. (#72825) 2023-12-04 13:00:34 -08:00
Craig Topper
f866fde598
[RISCV][GISel] Lower G_FCONSTANT to constant pool load without F or D. (#73034)
I used an IR test because it was easier than constructing different MIR
test for each type of addressing.
2023-12-01 10:24:26 -08:00
Michael Maitland
a6f7278595
[RISCV][GISEL] legalize, regbankselect, and instruction-select G_PTRMASK (#73062)
This is done in instruction-select instead of in legalization for the
sake of alias analysis.
2023-11-30 11:54:01 -05:00
Michael Maitland
dbb9043dea
[RISCV][GISEL] legalize, regbankselect, and instruction-select for G_… (#73061)
…[UN]MERGE_VALUES

When MERGE or UNMERGE s64 on a subtarget that is non-64bit, it must have
the D extension and use FPR in order to be legal.

All other instances of MERGE and UNMERGE that can be made legal should
be narrowed, widend, or replaced by the combiner.
2023-11-30 11:53:25 -05:00
Michael Maitland
6976dac09d
[RISCV][GISEL] regbankselect and instruction-select for G_IMPLICIT_DEF (#73060)
This is similar to the selection of G_IMPLICIT_DEF in AArch64.
Regbankselect may need to be improved in a future patch.
2023-11-30 11:38:02 -05:00
Craig Topper
ffcc5c7796
[RISCV][GISel] Select G_FENCE. (#73184)
Using IR test to make it easier to compare with the SelectionDAG test
output. The constant operands otherwise make it harder to understand.
2023-11-27 20:24:03 -08:00
Craig Topper
b4cf014991
[RISCV][GISel] Select trap and debugtrap. (#73171) 2023-11-27 15:52:15 -08:00
Craig Topper
179a2e0443
[RISCV][GISel] Legalize and select G_BRINDIRECT. (#73059) 2023-11-27 13:09:47 -08:00
Craig Topper
5f31dbd18d
[RISCV] Add register bank and instruction selection support for FP G_SELECT. (#72726)
Try to pick the FP register bank based on surrounding use/defs. Code is
basically copied from AArch64.

Need legalizer changes to make this more useful. Right now we're stuck
with only being able to FP select types less than or equal to XLen.
2023-11-27 10:38:25 -08:00
Craig Topper
4a2db23e6c
[RISCV][GISel] Use setDesc in some cases instead of creating new instructions. (#72769)
Slight memory usage improvement by reusing.
2023-11-27 10:20:10 -08:00
Craig Topper
fe3c421843
[RISCV][GISel] Merge selectGlobalValue and selectJumpTable. NFC (#72759)
We can use addDisp in place of addGlobalAddress/addJumpTableIndex to
copy the existing MachineOperand from the generic instruction.
2023-11-27 09:10:23 -08:00
Craig Topper
75a9ed4246 [RISCV][GISel] Add simplest case of folding add with immediate into load/store address.
This covers the simm12 offset case.
2023-11-25 10:48:35 -08:00
Craig Topper
f995afe7f2 [RISCV][GISel] Add G_FRAME_INDEX support to selectAddrRegImm.
We can fold the G_FRAME_INDEX into a load/store address.
2023-11-24 23:57:54 -08:00
Min-Yih Hsu
7c3c8a1277
[RISCV][GISel] Add support for G_IS_FPCLASS in F and D extensions (#72000)
Add legalizer, regbankselect, and isel supports for floating point
version of G_IS_FPCLASS.
2023-11-22 16:43:20 -08:00
Craig Topper
20f544d047
[RISCV][GISel] Instruction selection for G_JUMP_TABLE and G_BRJT. (#71987) 2023-11-18 12:33:25 -08:00
Craig Topper
e0e0891d74 [RISCV][GISel] Select G_BRCOND and G_ICMP together when possible.
This allows us to fold the G_ICMP operands into the conditional branch.

This reuses the helper function we have for folding a G_ICMP into
G_SELECT.
2023-11-12 15:53:23 -08:00
Craig Topper
4c3206c5d5 [RISCV][GISel] Sink more code into getOperandsForBranch. NFC
Move the m_GICmp match call in and use it to collect the operands.

This code is also needed for G_BRCOND.
2023-11-12 11:52:32 -08:00
Craig Topper
8c53cfd351 [RISCV][GISel] Rename register bank tablegen records to include B suffix to match the MIR name. NFC
GPRRegBank -> GPRBRegBank
FPRRegBank -> FPRBRegBank
2023-11-11 23:14:16 -08:00
Craig Topper
fdbff88196
[RISCV][GISel] Add support for G_FCMP with F and D extensions. (#70624)
We only have instructions for OEQ, OLT, and OLE. We need to convert
other comparison codes into those.

I think we'll likely want to split this up in the future to support
optimizations. Maybe do some of it in the legalizer or in a new post
legalizer lowering pass. So this patch is just enough to get something
working without adding 11 additional patterns to tablegen for each type.
2023-11-09 20:45:35 -08:00
Wang Pengcheng
e179b125fb
[RISCV][NFC] Pass MCSubtargetInfo instead of FeatureBitset in RISCVMatInt (#71770)
The use of `hasFeature` is more descriptive and the callers of
`RISCVMatInt` have no need to call `getFeatureBits()` any more.
2023-11-09 15:15:23 +08:00
Craig Topper
39edac23df [RISCV][GISel] Fix incorrect call to getGlobalAddress in selectGlobalValue.
RISCVII::MO_HI was being passed to the offset argument instead of
the flags argument.

Adjust some other calls to not pass an explicit 0 to the offset argument
since it already has a default value of 0.
2023-11-04 23:44:10 -07:00
Craig Topper
d0f6825da2 [RISCV][GISel] Use ArrayRef version of buildInstr to reduce code. NFC
Avoids the need for explicit addDef and addReg.
2023-11-04 23:05:57 -07:00
Craig Topper
16ddd25b69 Revert "[GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (#68327)"
This reverts commit 28ae42e6625154dfd164803850b15d8a0c296b94.

The assert in getIConstantVRegVal was not updated for this change.
The ValAndVReg->VReg == VReg check fails if any look through happens.

RISC-V was the only target using the lookthrough functionality, but I'm
not sure it was needed so I'm removing that too.
2023-11-04 12:21:06 -07:00