163 Commits

Author SHA1 Message Date
Michael Maitland
7cfa4c4601
[RISCV][GISEL] Fix legalization for G_MERGE/UNMERGE_VALUES (#75619)
The legalFor check did not work as expected. Use legalIf instead. Also
    do some simplification by removing IdxZeroTy and IdxOneTy.
2023-12-18 19:21:18 -05:00
Michael Liao
2a8f40d462 [RISCV][GISel] Fix a bug exposed from compilation warnings. NFC
- G_MERGE_VALUES and G_UNMERGE_VALUES need type pairs instead of type.
2023-12-18 15:07:12 -05:00
Craig Topper
478d093e1b
[RISCV][GISel] Reverse the operands the buildStore created in legalizeVAStart. (#73989)
We need to store the frame index to the location pointed to by the
VASTART, not the other way around.
2023-12-08 10:45:53 -08:00
Michael Maitland
3a38baa0e7
[GISEL][RISCV] Legalize llvm.vacopy intrinsic (#73066)
In the future, we can consider adding a G_VACOPY opcode instead of going
through the GIntrinsic for all targets. We do the approach in this patch
because that is what other targets do today.
2023-12-08 13:45:32 -05:00
Michael Maitland
6f9cb9a75c
[RISCV][GISEL] Legalize G_VAARG through expansion. (#73065)
G_VAARG can be expanded similiar to SelectionDAG::expandVAArg through
LegalizerHelper::lower. This patch implements the lowering through this
style of expansion.

The expansion gets the head of the va_list by loading the pointer to
va_list. Then, the head of the list is adjusted depending on argument
alignment information. This gives a pointer to the element to be read
out of the va_list. Next, the head of the va_list is bumped to the next
element in the list. The new head of the list is stored back to the
original pointer to the head of the va_list so that subsequent G_VAARG
instructions get the next element in the list. Lastly, the element is
loaded from the alignment adjusted pointer constructed earlier.

This change is stacked on #73062.
2023-12-08 13:24:27 -05:00
Craig Topper
3c5b42acd3
[RISCV] Allocate the varargs GPR save area as a single object. (#74354)
Previously we allocated one object for each GPR. We also allocated the
same offset twice, once to save for VASTART and then again for the first
register in the save loop.

This patch uses a single object for all the registers and shares this
with VASTART. This is more consistent with other targets like AArch64
and ARM.

I've removed the setValue(nullptr) from the memory operand now. Having a
single object makes me a lot more comfortable about alias analysis being
able to see what is going on. This led to the scheduling changes in
push-pop-popret.ll and vararg.ll.
2023-12-05 10:30:01 -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
47fe9fcaf2
[RISCV] Share ArgGPRs array between SelectionDAG and GISel. (#74152)
This will allow us to isolate the EABI from D70401 to this new function.
2023-12-04 11:29:54 -08:00
Craig Topper
26fc26c184
[RISCV] Simplify computation of VarArgsSaveSize. NFC (#74209)
The computation we use for computing the size already returns 0 when all
registers are allocated. We don't need an if to set it to 0.

Use the size being 0 to check for whether we need to spill registers or
not.

I have another change I want to make to this code, but this change
seemed to stand on its own. I left the curly braces since I need them
for the other change.
2023-12-03 20:35:12 -08:00
Craig Topper
7e7aaa53a1
[RISCV][GISel] Support G_ABS with Zbb. (#72939)
We can use neg+max or negw+max.
2023-12-01 11:13:45 -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
Craig Topper
ae485e661f [RISCV][GISel] Use customFor instead of customIf by pulling out a subtarget check. NFC 2023-11-30 11:03:14 -08:00
Craig Topper
306e13e499 [RISCV][GISel] Remove unnecessary Observer notifications from legalizeVAStart.
MIRBuilder already tells the observer when an instruction is created.

No other legalizer code on any target tells the observer when it
erases the instruction it was asked to legalize.
2023-11-30 09:53:37 -08:00
Michael Maitland
12326f5ff0
[RISCV][GISEL] lowerFormalArguments for variadic arguments (#73064)
This is based of the varargs coe in RISCVTargetLowering::LowerFormalArguments.
2023-11-30 12:15:35 -05:00
Michael Maitland
3ccba24c99
[RISCV][GISEL] Legalize G_VASTART using custom legalization (#73063)
The legalization was modeled after SelectionDAG.
2023-11-30 12:05:45 -05: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
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
9e86919626
[RISCV][GISel] Fix 2 indirect call bugs. (#73170)
We can't set MO_PLT on an indirect call.
We need to constrain the register class for the operand to the call
instruction.
2023-11-27 12:59:01 -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
Craig Topper
0a9c6bea6b [RISCV][GISel] Support G_CTTZ/CTLZ with Zbb. 2023-11-23 14:15:11 -08:00
Craig Topper
59e24eea34 [RISCV][GISel] Rename some variables to be more consistent. NFC 2023-11-23 13:06:23 -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
35ad44ebe4 [RISCV][GISel] Allow G_SELECT to have s32 type on RV64. 2023-11-17 17:12:27 -08:00
Craig Topper
181e8065ed [RISCV][GISel] Handle FP instructions in the default case of register bank selection. NFC
Use isPreISelGenericFloatingPointOpcode to to indicate when to use
an FP ValueMapping.
2023-11-15 23:17:08 -08:00
Craig Topper
9e88a2072f [RISCV][GISel] Add isPreISelGenericFloatingPointOpcode and FPConstraints. NFC
This brings us closer to how AArch64 is structured. I plan to use
isPreISelGenericFloatingPointOpcode in another change.
2023-11-15 23:16:50 -08:00
Craig Topper
8630cf218d [RISCV][GISel] Add a default case to map registers to GPRB in register bank selection. NFC
This reduces the number of opcodes we need to list explicitly.
2023-11-15 21:43:50 -08:00
Fangrui Song
103811a27a
[RISCV,GISel] Unconditionally use MO_PLT for calls (#72355)
All known linkers handle R_RISCV_CALL and R_RISCV_CALL_PLT in the same
way (GNU ld since
https://sourceware.org/pipermail/binutils/2020-August/112750.html).

MO_CALL is for R_RISCV_CALL, a deprecated relocation type. We don't
migrate away from MO_CALL yet.
For GISel we don't have the output difference concern and should weigh
more on simplicity.
2023-11-15 15:18:47 -08:00
Michael Maitland
dbd884cd3d [RISCV][GISEL] Add vector RegisterBanks and vector support in getRegBankFromRegClass
Vector Register banks are created for the various register vector
register groupings. getRegBankFromRegClass is implemented to go from
vector TargetRegisterClass to the corresponding vector RegisterBank.
2023-11-15 15:08:29 -08:00
Michael Maitland
725e599637
[RISCV][GISEL] Add support for scalable vector types in lowerReturnVal (#71587)
Scalable vector types from LLVM IR are lowered into physical vector
registers in MIR based on calling convention for return instructions.
2023-11-15 17:30:53 -05:00
Craig Topper
0b8379bff7
[RISCV][GISel] Sink getOperandsMapping call out of the switch in getInstrMapping. (#72326)
Use a SmallVector of `ValueMapping *` that we populate in the switch for
each register operand. The entry in the SmallVector defaults to nullptr
for each operand so we don't need to write explicit `nullptr` in the
cases.

After this we can generically fill in GPR for registers as a default
case and remove some opcodes from the switch.
2023-11-15 14:28:58 -08:00
Craig Topper
c44ac52e7d [RISC][GISel] Consider ABI copies when picking register bank for G_LOAD/STORE.
This is partially based on AArch64, but reduced to handle just the case
we currently have a test for.
2023-11-14 18:57:08 -08:00
Michael Maitland
a4f77f1ca3
[RISCV][GISEL] Use MO_PLT when Callee is a Global or Symbol (#71982)
SelectionDAG does the same thing in 74c83649547c2
2023-11-14 18:55:39 -05:00
Michael Maitland
a7bbcc4690
[RISCV][GISEL] Add support for lowerFormalArguments that contain scalable vector types (#70882)
Scalable vector types from LLVM IR can be lowered to scalable vector
types in MIR according to the RISCVAssignFn.
2023-11-14 13:15:41 -05: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
3161102f10
[RISCV][GISel] Attempt to simplify how we handle type legality for F and D extensions. (#72174)
Add helper that creates a lambda similar to typeIs, but containing the
predicate check for hasStdExtF and hasStdD. We can use this with legalIf
and all to reduce the number of manual lambdas we need to write.
2023-11-13 19:19:56 -08:00
Craig Topper
04107797d9 [RISCV][GISel] Simplify some code. NFC
typeIs and LegalizeMutation::changeTo instead of implementing our own lambdas
that do the same thing.
2023-11-13 15:27:41 -08:00
Craig Topper
05300222ba
[RISCV][GISel] Add really basic support for FP regbank selection for G_LOAD/G_STORE. (#70896)
Coerce the register bank based on the users of the G_LOAD or the
defining instruction for the G_STORE.

s64 on rv32 is handled by forcing the FPRB register bank.
2023-11-13 12:12:16 -08:00