82 Commits

Author SHA1 Message Date
Craig Topper
feedb35e41 [RISCV][GISel] Correct RORIW patterns.
We had two rotl patterns and no rotr pattern. The order was such
that the incorrect rotl pattern was being used.
2024-10-17 09:32:45 -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
Craig Topper
1053b3ea24 [RISCV][GISel] Stop promoting s32 G_SHL/ASHR/LSHR shift amount to s64 on RV64.
There are no SelectionDAG patterns to share. GISel has its own patterns
since it considers s32 a legal type and SDAG does not.
2024-10-01 21:23:01 -07:00
Craig Topper
c62cb1bf1e [RISCV][GISel] Stop promoting s32 G_ROTL/ROTR rotate amount to s64 on RV64.
There are no SelectionDAG patterns to share. GISel has its own patterns
since it considers s32 a legal type and SDAG does not.
2024-10-01 16:07:26 -07:00
Craig Topper
f022111e64 [RISCV][GISel] Restore s32 support on RV64 for DIV, and REM.
This reverts commit 2599d695128381e6932b43f0e95649c533308d6d.

I was was plannig to remove s32 as a legal type on RV64, but
I'm rethinking that.
2024-09-16 16:29:20 -07:00
Craig Topper
f3bf46f530 [RISCV][GISel] Correct registers classes in vector anyext.mir test. NFC 2024-08-21 21:41:06 -07:00
Craig Topper
88636854b0 [RISCV][GISel] Correct registers classes in vector sext/zext.mir tests. NFC
The liveins were always for an LMUL=1 register class even if the
first instruction used a larger regsister class.

One test in zext.mir used the wrong class for the first instruction.
2024-08-21 20:37:37 -07:00
Craig Topper
2599d69512
[RISCV][GISel] Remove s32 support on RV64 for DIV, and REM. (#102519)
Based on experience with SelectionDAG and experimental-rv64-legal-i32, I
don't believe making s32 a legal type is viable without introducing an
invariant that s32 values are always sign extended like Mips64 does.
Mips64 does this with a separate 32-bit register class.

`experimental-rv64-legal-i32` was removed in ##102509.

This patch is part of a series to remove s32 support so we can remove
the isel patterns that SelectionDAG is no longer using. To restore code
quality, we will need to add custom W nodes like SelectionDAG.
2024-08-20 13:10:20 -07:00
Craig Topper
6b27a57d02 [RISCV][GISel] Add missing tests for G_CTLZ/CTTZ instruction selection. NFC 2024-08-09 12:10:34 -07:00
Craig Topper
868fae1f2e [RISCV][GISel] Support G_FPEXT/FPTRUNC with ZFh. 2024-06-26 11:11:05 -07:00
Craig Topper
581fd2fa57
[RISCV][GISel] Support fptoi and itofp for Zfh. (#96707) 2024-06-26 09:53:37 -07:00
Craig Topper
acd6cb85b3
[RISCV][GISel] Support fcmp and fclass for Zfh. (#96696) 2024-06-26 09:53:13 -07:00
Craig Topper
19183691f3
[RISCV][GISel] Add missing fclass tests. NFC (#96694)
We were only testing f32 on rv32 and f64 on rv64. We need to test f32
and f64 on both rv32 and rv64.
2024-06-26 09:07:18 -07:00
Craig Topper
dff6871cdb [RISCV][GISel] Support G_FCONSTANT for Zfh. 2024-06-25 14:10:25 -07:00
Craig Topper
dddef9d1c9
[RISCV] Add FPR16 regbank and start legalizing f16 operations for Zfh. (#96582) 2024-06-25 08:18:37 -07:00
Craig Topper
41f8e6d3ea [RISCV][GISel] Fix test case order in fp-arith.mir. NFC
The fadd_f64 test was in the middle of some f32 tests.
2024-06-24 23:45:53 -07: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
Michael Maitland
63c925ca80 [RISCV][GISEL] Instruction selection for G_ZEXT, G_SEXT, and G_ANYEXT with scalable vector type 2024-04-03 15:56:08 -07:00
Michael Maitland
35a9393a3f [RISCV][GISEL] Instruction selection for G_ICMP 2024-04-03 15:47:34 -07:00
Michael Maitland
54a9f0e441
[RISCV][GISEL] Legalize, regbankselect, and instruction-select G_VSCALE (#85967)
G_VSCALE should be lowered using VLENB. If the type is not sXLen it
should be lowered using a G_VSCALE on the narrow type and a G_MUL.
regbank select and instruction select are straightforward so we really
only need to add tests to show it works.
2024-03-26 20:17:22 -04:00
Michael Maitland
8b9c3b57b1 Revert "[RISCV][GISEL] Add instruction select tests for G_VSCALE"
This reverts commit c00a5ab8c4be14f63735ec61c5c9245c233cbcfc. It is not
consistent with SelectionDAG.
2024-03-25 11:50:57 -07:00
Michael Maitland
c00a5ab8c4 [RISCV][GISEL] Add instruction select tests for G_VSCALE 2024-03-25 10:44:59 -07:00
Michael Maitland
05840c8714 [RISCV][GISEL] Instruction select for scalable G_SELECT
SelectionDAG has SELECT and VSELECT

SELECT restricts the condition operand to an i1 and the true and false operands
can be vectors. The result of a SELECT has the same type as the true and
false operands.

VSELECT has a vector condition operand and the true and false operands
must be vectors. The result of a VSELECT has a vector result.

GlobalISel has G_SELECT which has condition operand that is an i1 if the
true and false operands are scalar and a vector type with i1 elements if
the true and false operands are vector.

A G_SELECT acts like a ISD::SELECT when the operands are all scalar, and
an ISD::VSELECT when the operands are are scalar. A G_SELECT cannot act
like a ISD::SELECT with an i1 condition and vector operands because the
type system.

In this patch, we would like to take advantage of the patterns written
for SELECT and VSELECT, so we mark G_SELECT equivalent to both SELECT
and VSELECT to reuse the patterns. Since we cannot write a `G_SELECT (s1),
(vector-ty), (vector-ty)`, we don't have to worry about accidently
matching the SDAG patterns of that nature.

We will probably need a way to represent an i1 condition with vector
true and false operands in the future. That can be the topic of another
patch.
2024-03-25 10:35:22 -07: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
Mikhail Gudim
ba3ef331b4
[RISCV][GlobalISel] Zbkb support for G_BSWAP (#77050)
This instructions is legal in the presence of Zbkb extension.
2024-01-05 23:19:46 -05:00
Mikhail Gudim
69bc371835
[RISCV][GlobalISel] Zbkb support for G_ROTL and G_ROTR (#76599)
These instructions are legal in the presence of Zbkb extension.
2023-12-30 00:45:18 -05:00
Craig Topper
d605d9d7a1
[RISCV][GISel] Support G_ROTL/G_ROTR with Zbb. (#72825) 2023-12-04 13:00:34 -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
d345cfb55c [RISCV][GISel] Support s64 G_SELECT on RV32 with D extension.
We have to force the register bank to FPRB if the type is s64 and
the GPR is 32 bits.
2023-11-28 23:36:51 -08:00
Craig Topper
35db35b7cf [RISCV][GISel] Support G_FCOPYSIGN with F and D extension. 2023-11-28 21:50:04 -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
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
564ff80e22 [RISCV][GISel] Test G_FRAME_INDEX folding into store address. NFC 2023-11-25 10:48:31 -08:00
Craig Topper
26cf3aab83 [RISCV][GISel] Add more G_SEXTLOAD instruction selection tests. NFC 2023-11-24 23:58:11 -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
Craig Topper
5bb03d25f7 [RISCV][GISel] Support G_CTPOP with Zbb. 2023-11-23 13:06:23 -08:00
Craig Topper
1343d96ec1 [RISCV][GISel] Suppport G_BSWAP with Zbb. 2023-11-23 00:39:42 -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
8ad4df8327 [RISCV][GISel] Add s32 G_SELECT instruction select test for RV64. NFC 2023-11-18 12:29:04 -08:00
Craig Topper
028ed6125f
[RISCV][GISel] Support G_UMIN/UMAX/SMIN/SMAX legal with Zbb. (#72182) 2023-11-13 20:57:38 -08:00
Craig Topper
0a459dd4e9 [RISCV] Add tests for selecting G_BRCOND+G_ICMP. NFC
These should have been part of e0e0891d741588684b0803d7724e5080f9c75537
2023-11-13 15:29:34 -08:00
Craig Topper
bab2cf2d01 [RISCV][GISel] Promote s32 constant shift amounts to s64 on RV64.
This allows us to reuse isel patterns from SelectionDAG.

This is similar to what is done on AArch64.
2023-11-10 23:07:00 -08:00
Craig Topper
647c490f8a [RISCV] Add an add.uw pattern using zext for -riscv-experimental-rv64-legal-i32 and global isel 2023-11-10 21:36:29 -08:00