3336 Commits

Author SHA1 Message Date
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
5d501b1091
[GISel][RISCV] Fix several boundary cases in narrow G_SEXT_INREG. (#72719)
This fixes cases when SizeInBits is a multiple of the narrow size.

If SizeBits is equal to NarrowTy size, the first block would create an
illegal G_SEXT_INREG where the the extension size is equal to the type.
I tried to turn it into G_TRUNC+G_SEXT, but that just turned back into
G_SEXT_INREG causing an infinite loop. So punt to the splitting case.

In the for loop we should copy when the part ends on SizeInBits. In that
case there is no G_SEXT_INREG needed for partial. But we should note
that register in PartialExtensionReg for the first full part to use.

If the part starts on SizeInBits then we should do an AShr of
PartialExtensionReg.

We should only get to the G_SEXT_INREG case if the SizeInBits is in the
middle of the part.
2023-11-24 08:39:38 -08:00
Craig Topper
0a9c6bea6b [RISCV][GISel] Support G_CTTZ/CTLZ with Zbb. 2023-11-23 14:15:11 -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
Wang Pengcheng
5973272af7
[RISCV] Add MinimumJumpTableEntries to TuneInfo (#72963)
This is like what AArch64 has done in #71166 except that we don't
handle `HasMinSize` case now.
2023-11-23 14:05:23 +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
Vettel
cae46f6210
[MCP] Enhance MCP copy Instruction removal for special case (#70778)
Machine Copy Propagation Pass may lose some opportunities to further
remove the redundant copy instructions during the ForwardCopyPropagateBlock
procedure. When we Clobber a "Def" register, we also need to remove the record 
from the copy maps that indicates "Src" defined "Def" to ensure the correct semantics
of the ClobberRegister function.

For more information, please see the C++ test case generated code in 
"vector.body" after the MCP Pass: https://gcc.godbolt.org/z/nK4oMaWv5.
2023-11-22 23:57:42 +08:00
Craig Topper
9a6452377b [RISCV] Add more Zbs patterns for -riscv-experimental-rv64-legal-i32. 2023-11-21 23:24:00 -08:00
Yeting Kuo
a756a6b97e
[TargetLowering][RISCV] Introduce shouldFoldSelectWithSingleBitTest and RISC-V implement. (#72978)
DAGCombiner folds (select_cc seteq (and x, y), 0, 0, A) to (and (sra
(shl x)) A) where y has a single bit set. Previously, DAGCombiner relies
on `shouldAvoidTransformToShift` to decide when to do the combine, but
`shouldAvoidTransformToShift` is only about shift cost. This patch
introuduces a specific hook to decide when to do the combine and disable
the combine when Zicond enabled and AndMask <= 1024.
2023-11-22 08:22:14 +08:00
Craig Topper
7a6fd49c8a [RISCV] Use short forward branch for ISD::ABS.
We can use short forward branch to conditionally negate if the
value is negative.
2023-11-21 11:00:06 -08:00
Craig Topper
ce6127433b [RISCV] Add rv32 command line to short-forward-branch-opt.ll. NFC 2023-11-21 11:00:05 -08:00
Brandon Wu
2749f52ec4
[RISCV] Convert all floating point vector type operands to integer vector type (#69559) 2023-11-21 23:19:10 +08:00
Craig Topper
a1de0946ab [RISCV] Fix spelling error in test name. NFC
foward -> forward
2023-11-20 21:50:35 -08:00
Liao Chunyu
9166cd2a71
[RISCV] DAG combine (mul (add x, 1), y) -> vmadd (#71495)
vmadd: (mul (add x, 1), y) -> (add (mul x, y), y)
           (mul x, add (y, 1)) -> (add x, (mul x, y))
    vnmsub: (mul (sub 1, x), y) -> (sub y, (mul x, y))
            (mul x, (sub 1, y)) -> (sub x, (mul x, y))
    
    Comparison with gcc:
    vmadd: https://gcc.godbolt.org/z/xjePx87Y7
    vnsub: https://gcc.godbolt.org/z/b17zG7nT1
2023-11-21 13:43:34 +08:00
Piyou Chen
3494c555c9
[RISCV] postpone removal in initundef pass (#71661)
InitUndef pass need replace the implicit def with Undef pseudo, but
current remove method will make noreg2implicit borken.

This patch postpone the removal until all basicblock be processed.
2023-11-20 11:44:27 +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
0154e53bf3 [RISCV][GISel] Remove the rv32/rv64 subdirectories for legalizer tests. NFC
Add -rv32 -rv64 as suffix to test name. First step towards trying
to merge the content of these tests.
2023-11-18 11:25:09 -08:00
Craig Topper
35ad44ebe4 [RISCV][GISel] Allow G_SELECT to have s32 type on RV64. 2023-11-17 17:12:27 -08:00
Philip Reames
144b2f579e
[RISCV] Start vslide1down sequence with a dependency breaking splat (#72691)
If we are using entirely vslide1downs to initialize an otherwise undef
vector, we end up with an implicit_def as the source of the first
vslide1down. This register has to be allocated, and creates false
dependencies with surrounding code.

Instead, start our sequence with a vmv.v.x in the hopes of creating a
dependency breaking idiom. Unfortunately, it's not clear this will
actually work as due to the VL=0 special case for T.A. the hardware has
to work pretty hard to recognize that the vmv.v.x actually has no source
dependence. I don't think we can reasonable expect all hardware to have
optimized this case, but I also don't see any downside in prefering it.
2023-11-17 12:02:58 -08:00
Sacha Coppey
aeedc07637 [IR] Add GraalVM calling conventions
Adds GraalVM calling conventions. The only difference with the default calling conventions is that GraalVM reserves two registers for the heap base and the thread. Since the registers are then accessed by name, getRegisterByName has to be updated accordingly.

This patch implements the calling conventions only for X86, AArch64 and RISC-V.

For X86, the reserved registers are X14 and X15. For AArch64, they are X27 and X28. For RISC-V, they are X23 and X27.

This patch has been used by the LLVM backend of GraalVM's Native Image project in production for around 4 months with no major issues.

Differential Revision: https://reviews.llvm.org/D151107
2023-11-17 16:30:09 +00:00
Nemanja Ivanovic
227607190e
[RISCV] Fix crash in PEI with empty entry block with Zcmp (#72117)
We check the opcode of the first instruction in the block where the
prologue is inserted without checking if the iterator points to any
instructions. When the basic block is empty, that causes a crash. One
way the prologue block can be empty is when it starts with a call to
__builtin_readcyclecounter on RV32 since that produces a loop.

Co-authored-by: Nemanja Ivanovic <nemanja@synopsys.com>
2023-11-17 16:18:44 +01:00
Nemanja Ivanovic
0765f6451f
[RISCV] Use correct register class for Z[df]inx inline asm (#71872)
Allocate a register of the correct register class for inline asm
constraint "r" when used for FP values with -Zfinx/-Zdinx.

---------

Co-authored-by: Nemanja Ivanovic <nemanja@synopsys.com>
2023-11-17 16:17:48 +01:00
Philip Reames
8f81c605f5
[RISCV] Remove custom instruction selection for VFCVT_RM and friends (#72540)
We already have the pseudo's for lowering these as MI nodes with
rounding mode operands, and the generic FRM insertion pass. Doing the
insertion later in the backend allows SSA level passes to avoid
reasoning about physical register copies, and happens to produce better
code in practice. The later is mostly an accident of our insertion
order; we happen to place the frm write after the vsetvli, and it's very
common for a register to be killed at the vsetvli. End result is that we
get slightly better scalar register allocation.

I'm a bit unclear on the history here. I was surprised to find this code
in ISEL lowering at all, but am also surprised once I found it that all
the patterns and pseudos seem to already exist. My best guess is that
maybe we didn't do all the possible cleanup after introducing the
HasRoundMode mechanism?
2023-11-17 07:07:37 -08:00
Philip Reames
233971b475 [RISCV] Fix typo in a test and regen another to reduce test diff 2023-11-16 14:28:16 -08:00
Philip Reames
1aa493f064 [RISCV] Further expand coverage for insert_vector_elt patterns 2023-11-16 14:14:31 -08:00
Philip Reames
73e963379e [RISCV] Add test coverage for partial buildvecs idioms
Test coverage for an upcoming set of changes
2023-11-16 13:33:12 -08:00
Craig Topper
927f6f1858 [RISCV] Use bset+addi for (not (sll -1, X)).
This is an alternative to #71420 that handles i32 on RV64 safely
by pre-promoting the pattern in DAG combine.
2023-11-16 11:14:53 -08:00
Craig Topper
4eaf986be4 [RISCV] Add test cases for (not (sll -1, X)) for Zbs. NFC
We can use (ADDI (BSET X0, X), -1).
2023-11-16 11:14:53 -08:00
Igor Kirillov
63917e1975
[MachineLICM] Allow hoisting loads from invariant address (#70796)
Sometimes, loads can appear in a loop after the LICM pass is executed
the final time. For example, ExpandMemCmp pass creates loads in a loop,
and one of the operands may be an invariant address.
This patch extends the pre-regalloc stage MachineLICM by allowing to
hoist invariant loads from loops that don't have any stores or calls
and allows load reorderings.
2023-11-16 11:12:10 +00:00
LiaoChunyu
71a7108ee9 [RISCV][MC] MC layer support for xcvmem and xcvelw extensions
This commit is part of a patch-set to upstream the 7 vendor specific extensions of CV32E40P.
Several other extensions have been merged.
Spec:
https://github.com/openhwgroup/cv32e40p/blob/master/docs/source/instruction_set_extensions.rst
Contributors: @CharKeaney, @jeremybennett, @lewis-revill, Nandni Jamnadas, @PaoloS, @simoncook, @xmj, @realqhc, @melonedo, @adeelahmad81299

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D158824
2023-11-16 09:46:11 +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
c281a6add5 [RISCV] Add isel pattern for int_riscv_vfmv_s_f with scalar FP constant operand.
Use vmv_s_x instead of the constant will be materialized in a GPR.

This avoids going from GPR to FPR to vector.

We already did this for RISCVISD::VFMV_S_F_VL and probably we should
just turn int_riscv_vfmv_s_f into RISCVISD::VFMV_S_F_VL, but I'd like
to see some improvements to RISCVInsertVSETVLI first.
2023-11-15 10:51:43 -08:00
Craig Topper
084f5c26a4 [RISCV] Add tests cases to show missed opportunity to turn vfmv.s.f into vmv.s.x when source is FP constant materialized in GPR.
We end up creating the constant in GPR, move to FPR, then move to vector.
We should go directly from GPR to vector.
2023-11-15 10:51:43 -08:00
Craig Topper
1c033aaac9 [RISCV] Add IsSignExtendingOpW to AMO*_W instructions. (#72349) 2023-11-15 09:39:31 -08:00
Craig Topper
e12677db8b [RISCV] Add test cases showing missed opportunity to remove sext.w after amo*.w. NFC
We should tell RISCVOptWInstrs that these instructions sign extend
their results.
2023-11-15 09:37:09 -08:00
Tavian Barnes
75cf672b12
[SDAG] Simplify is-power-of-2 codegen (#72275)
When x is not known to be nonzero, ctpop(x) == 1 is expanded to

    x != 0 && (x & (x - 1)) == 0

resulting in codegen like

    leal    -1(%rdi), %eax
    testl   %eax, %edi
    sete    %cl
    testl   %edi, %edi
    setne   %al
    andb    %cl, %al

But another expression that works is

    (x ^ (x - 1)) > x - 1

which has nicer codegen:

    leal    -1(%rdi), %eax
    xorl    %eax, %edi
    cmpl    %eax, %edi
    seta    %al
2023-11-15 22:26:34 +09: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
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
29d75cb9dc [RISCV][GISel] Update legalize-smin.mir and legalize-smax.mir to test G_SMIN/G_SMAX.
Looks like an incomplete fixup was done after copying the umin/umax tests.
2023-11-13 13:49:14 -08:00
Craig Topper
915e092400 [RISCV] Select zext as sext when sign bit is 0 for -riscv-experimental-rv64-legal-i32
In our default SelectionDAG where i32 isn't legal, the zext will become
and i64 AND and often get optimized out on its own. With i32 legal, we
need to turn it in into sext.w and rely on RISCVOptWInstrs to remove it.
2023-11-13 12:21:36 -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
Craig Topper
70ce047f7e
[RISCV] Legalize G_CTLZ/G_CTLZ_ZERO_UNDEF/G_CTTZ/G_CTTZ_ZERO_UNDEF. (#72014)
The base ISA does not support these operations. A future patch will
enable them for Zbb.
2023-11-13 11:22:48 -08:00
Craig Topper
d8576e4542 [RISCV][GISel] Update RV64 legalize-ctpop.mir to account for constant shift amounts being i64 now.
This changed while the ctpop patch was in review and I forgot to update it.
2023-11-13 10:38:36 -08:00