1107 Commits

Author SHA1 Message Date
Craig Topper
a90e350954 [RISCV] Use computeVLMax and getVScale to simplify code. NFC 2023-06-08 22:05:20 -07:00
Craig Topper
167f2fa1b6 [RISCV] Fix crash in lowerVECTOR_INTERLEAVE when VecVT is an LMUL=8 type.
If VecVT is an LMUL=8 VT, we can't concatenate the vectors as that
would create an illegal type. Instead we need to split the vectors
and emit two VECTOR_INTERLEAVE operations that can each be lowered.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D152411
2023-06-08 08:41:38 -07:00
Craig Topper
78f1a2ae26 [RISCV] Fix crash in lowerVECTOR_DEINTERLEAVE when VecVT is an LMUL=8 type.
If VecVT is an LMUL=8 VT, we can't concatenate the vectors as that
would create an illegal type. Instead we need to split the vectors
and emit two VECTOR_DEINTERLEAVE operations that can each be lowered.

Reviewed By: luke, rogfer01

Differential Revision: https://reviews.llvm.org/D152402
2023-06-08 08:41:38 -07:00
Craig Topper
b7f5f48973 [RISCV] Use Selection::getElementCount to simplify code. NFC 2023-06-07 17:02:01 -07:00
Craig Topper
d338727737 [RISCV] Pass SDLoc by const reference. NFC 2023-06-07 16:53:30 -07:00
Craig Topper
2b09f53b32 [RISCV] Remove overly restrictive assert from negateFMAOpcode.
It's possible that both multiplicands are being negated. This won't
change the opcode, but we can delete the two negates. Allow this
case to get through negateFMAOpcode.

I think D152260 will also fix this test case, but in the future
it may be possible for an fneg to appear after we've already converted
to RISCVISD opcodes in which case D152260 won't help.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D152296
2023-06-06 18:55:58 -07:00
Craig Topper
8c649231f4 [RISCV] Fix UBSan failure on signed integer overflow. 2023-06-06 18:27:33 -07:00
Florian Mayer
38f7c7eb1a Revert "Revert "[RISCV] Add special case to selectImm for constants that can be created with (ADD (SLLI C, 32), C).""
Revert broke even more stuff.

This reverts commit d5fbec30939f2c9f82475cf42c638619514b5c67.
2023-06-06 17:39:05 -07:00
Florian Mayer
d5fbec3093 Revert "[RISCV] Add special case to selectImm for constants that can be created with (ADD (SLLI C, 32), C)."
Triggers UBSan error.

This reverts commit 58b2d652af49ee9d9ff2af6edd7f67f23b26bfee.
2023-06-06 17:30:07 -07:00
Craig Topper
58b2d652af [RISCV] Add special case to selectImm for constants that can be created with (ADD (SLLI C, 32), C).
Where C is a simm32.

This costs an extra temporary register, but avoids a constant pool.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D152236
2023-06-06 11:59:12 -07:00
Jianjian GUAN
77da27b5e3 [RISCV] Improve selection for vector fpclass.
Since vfclass intruction will only set one single bit in the result, so if we only want to check 1 fp class, we could use vmseq to do it.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151967
2023-06-06 10:24:24 +08:00
NAKAMURA Takumi
ebb02fb275 RISCVISelLowering.cpp: Suppress a warning. (D150824) 2023-06-06 08:55:46 +09:00
Craig Topper
b64ddae8a2 [RISCV] Lower experimental_get_vector_length intrinsic to vsetvli for some cases.
This patch lowers to vsetvli when the AVL is i32 or XLenVT and
the VF is a power of 2 in the range [1, 64]. VLEN=32 is not supported
as we don't have a valid type mapping for that. VF=1 is not supported
with Zve32* only.

The element width is used to set the SEW for the vsetvli if possible.
Otherwise we use SEW=8.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D150824
2023-06-05 15:02:11 -07:00
Craig Topper
4157bfb230 [RISCV] Add RISCVISD nodes for vfwadd/vfwsub.
Add a DAG combine to form these from FADD_VL/FSUB_VL and FP_EXTEND_VL.

This makes it similar to other widening ops and allows us to handle
using the same FP_EXTEND_VL for both operands.

Differential Revision: https://reviews.llvm.org/D151969
2023-06-05 14:12:47 -07:00
Yeting Kuo
84ee08c6a8 [RISCV] Avoid illegal DAG combination for strict-fp nodes.
Those combines may change the exception behavior and rounding behavior.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151992
2023-06-03 10:29:30 +08:00
Jessica Clarke
a178ba9fbd [RISCV] Lower extern_weak symbols using the GOT for the medany model
Such symbols may be undefined at link time and thus resolve to 0, which
may be further than 2GiB away from PC, causing the immediate to be out
of range for PC-relative addressing. Using the GOT avoids this, and is
the approach taken by AArch64.

Reviewed By: asb, MaskRay, arichardson

Differential Revision: https://reviews.llvm.org/D107280
2023-05-31 18:48:21 +01:00
Jessica Clarke
9b55e5d420 [RISCV] Add new lga pseudoinstruction
This mirrors lla and is always GOT-relative, allowing an explicit
request to use the GOT without having to expand the instruction. This
then means la is just defined in terms of lla and lga in the assembler,
based on whether PIC is enabled, and at the codegen level we replace la
entirely with lga since we only ever use la there when we want to load
from the GOT (and assert that to be the case).

See https://github.com/riscv-non-isa/riscv-asm-manual/issues/50

Reviewed By: asb, MaskRay

Differential Revision: https://reviews.llvm.org/D107278
2023-05-31 18:48:21 +01:00
Kazu Hirata
6eef8d9b2b [RISCV] Fix an unused variable warning
llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:3793:7:
 error: unused variable 'XLenVT' [-Werror,-Wunused-variable]
2023-05-31 08:45:29 -07:00
Philip Reames
e69318138e [RISCV] Use v(f)slide1down for shuffle+insert idiom
This is a follow up to D151468 which added the vslide1down case as a sub-case of vslide1down matching. This generalizes that code into generic mask matching - specifically to point out the sub-vector insert restriction in the original patch. Since the matching logic is basically the same, go ahead and support vslide1up at the same time.

Differential Revision: https://reviews.llvm.org/D151742
2023-05-31 07:53:51 -07:00
LiaoChunyu
548fa1d308 [RISCV] Add special case for (select cc, 1.0, 0.0) to lowerSELECT
Use sint_to_fp instead of select.
Reduce the number of branch instructions and
avoid generating TargetConstantPool for double.

(select cc, 1.0, 0.0) -> (sint_to_fp (zext cc))
https://alive2.llvm.org/ce/z/aoEcd9
https://godbolt.org/z/n543Y9v3e

(select cc, 0.0, 1.0) -> (sint_to_fp (zext (xor cc, 1)))
https://alive2.llvm.org/ce/z/zngvSB

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151719
2023-05-31 15:20:57 +08:00
Jianjian GUAN
62307f6d4e [RISCV] Fix selection for some unmasked vp SDNode.
Make unmasked vp_ftrunc, vp_fceil, vp_floor and vp_fround select to unmasked instruction.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D151676
2023-05-31 09:54:44 +08:00
Craig Topper
454163354b [RISCV] Allow FWMUL formation for an FP extend used twice by the same multiply. 2023-05-30 15:08:08 -07:00
Craig Topper
463f50b436 [RISCV] Add RISCVISD::VFWMUL_VL. Use it to replace isel patterns with a DAG combine.
This is more consistent with how we handle integer widening multiply.

A follow up patch will add support for matching vfwmul when the
multiplicand is being squared.
2023-05-30 14:38:16 -07:00
Philip Reames
544a240ff7 [RISCV] Use v(f)slide1up for shuffle+insert idiom
This is pretty straight forward in the basic form. I did need to move the slideup matching earlier, but that looks generally profitable on it's own.

As follow ups, I plan to explore the v(f)slide1down variants, and see what I can do to canonicalize the shuffle then insert pattern (see _inverse tests at the end of the vslide1up.ll test).

Differential Revision: https://reviews.llvm.org/D151468
2023-05-30 07:37:41 -07:00
Alex Bradbury
c4efcd6970 [RISCV] Generalise shouldExtendTypeInLibcall logic to apply to all <XLEN floats on soft ABIs
This results in improved codegen for half/bf16 libcalls on soft ABIs

Adds a RISCVSubtarget helper method for determining if a soft FP ABI is
being targeted (future bf16 related patches make use of this).

Differential Revision: https://reviews.llvm.org/D151434
2023-05-30 11:04:03 +01:00
Jianjian GUAN
071e9d7bac [RISCV] Fix unmasked vp_abs select.
Make unmasked vp_abs select to umasked instructions.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D151646
2023-05-30 09:57:40 +08:00
Craig Topper
9b9e9abad6 [RISCV] Simplify code in LowerIS_FPCLASS. NFC 2023-05-26 12:16:19 -07:00
Craig Topper
1fea6bd877 [RISCV] Remove extra MVT::Other result from creation of RISCVISD::FCLASS_VL. 2023-05-26 12:01:18 -07:00
Luke Lau
90c4db4a2c [RISCV] Don't scalarize vector stores if volatile
As noted by @reames in https://reviews.llvm.org/D151211#4373404, we shouldn't
scalarize vector stores of constants if the store is volatile, or vector copies
if either the store or load are volatile.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D151500
2023-05-26 09:34:34 +01:00
LiaoChunyu
477d1080cb [RISCV] Custom lower vector llvm.is.fpclass to vfclass.v
After D149063.
This patch adds support for both scalable and fixed-length vector.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151176
2023-05-26 14:44:35 +08:00
Luke Lau
6fdc77e488 [RISCV] Don't reduce vslidedown's VL in rotations
Even though we only need to write to the bottom NumElts - Rotation
elements for the vslidedown.vi, we can save an extra vsetivli toggle if
we just keep the wide VL.

(I may be missing something here: is there a reason why we want to explicitly keep the vslidedown narrow?)

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151390
2023-05-25 09:27:55 +01:00
Shao-Ce SUN
8b90f8e04b [RISCV][CodeGen] Support Zdinx on RV32 codegen
This patch was split from D122918 .

Co-Author: @StephenFan @liaolucy @realqhc

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D149743
2023-05-25 14:13:37 +08:00
Craig Topper
2f3e17566b [RISCV] Add a special caes to performVFMADD_VLCombine to support the multiplicand being the same value.
The one use check will fail if there are two uses in the same
instruction. Add a special case for this.
2023-05-24 17:25:33 -07:00
Philip Reames
9357712b50 [RISCV] Use vfslide1down for build_vectors of non-constant floats
This adds the vfslide1down (and vfslide1up for consistency) nodes. These mostly parallel the existing vslide1down/up nodes. (See note below on instruction semantics.) We then use the vfslide1down in build_vector lowering instead of going through the stack.

The specification is more than a bit vague on the meaning of these instructions. All we're given is "The vfslide1down instruction is defined analogously, but sources its scalar argument from an f register."

We have to combine this with a general note at the beginning of section 10. Vector Arithmetic Instruction Formats which reads: "For floating-point operations, the scalar can be taken from a scalar f register. If FLEN > SEW, the value in the f registers is checked for a valid NaN-boxed value, in which case the least-signicant SEW bits of the f register are used, else the canonical NaN value is used. Vector instructions where any floating-point vector operand’s EEW is not a supported floating-point type width (which includes when FLEN < SEW) are reserved.".

Note that floats are NaN-boxed when D is implemented.

Combining that all together, we're fine as long as the element type matches the vector type - which is does by construction.  We shouldn't have legal vectors which hit the reserved encoding case.  An assert is included, just to be careful.

Differential Revision: https://reviews.llvm.org/D151347
2023-05-24 10:48:26 -07:00
Luke Lau
a8a36ee522 [RISCV] Scalarize constant stores of fixed vectors if small enough
For stores of small fixed-length vector constants, we can store them
with a sequence of lui/addi/sh/sw to avoid the cost of building the
vector and the vsetivli toggle, provided the constant materialization
cost isn't too high.

This subsumes the optimisation for stores of zeroes in
4dc9a2c5b93682c12d7a80bbe790b14ddb301877

(This is a reapply of 0ca13f9d2701e23af2d000a5d8f48b33fe0878b7)

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D151221
2023-05-24 15:55:01 +01:00
Luke Lau
173855f9b0 Revert "[RISCV] Scalarize constant stores of fixed vectors up to 32 bits"
This reverts commit 0ca13f9d2701e23af2d000a5d8f48b33fe0878b7.
2023-05-24 15:52:36 +01:00
Luke Lau
0ca13f9d27 [RISCV] Scalarize constant stores of fixed vectors up to 32 bits
For stores of small fixed-length vector constants, we can store them
with a sequence of lui/addi/sh/sw to avoid the cost of building the
vector and the vsetivli toggle.

Note that this only handles vectors that are 32 bits or smaller, but
could be expanded to 64 bits if we know that the constant
materialization cost isn't too high.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D151221
2023-05-24 15:32:22 +01:00
Luke Lau
28b21c4c74 [RISCV] Scalarize small fixed vector copies < XLEN
For small fixed-length vector copies like
vsetivli   zero, 2, e16, m1, ta, ma
vle16.v    v8, (a0)
vse16.v    v8, (a1)

We can scalarize them if the total vector size < XLEN:
lw a0, 0(a0)
sw a0, 0(a1)

This patch adds a DAG combine to do so, reusing much of the existing
logic in https://reviews.llvm.org/D150717

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D151103
2023-05-24 10:25:40 +01:00
Craig Topper
1f7c1741d6 [RISCV] Expand rotate by non-constant for XTHeadBb during lowering.
Avoids multi instruction isel patterns and enables mask optimizations
on shift amount.

Reviewed By: philipp.tomsich

Differential Revision: https://reviews.llvm.org/D151263
2023-05-23 16:31:22 -07:00
Nitin John Raj
991ecfb83d [RISCV][GlobalISel] Add lowerReturn for calling conv
Add minimal support to lower return, and introduce an OutgoingValueHandler and an OutgoingValueAssigner for returns.

Supports return values with integer, pointer and aggregate types.

(Update of D69808 - avoiding commandeering that revision)

Co-authored By: lewis-revill

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D117318
2023-05-23 11:24:54 -07:00
Jianjian GUAN
c6d3347e13 [RISCV][NFC] Simplify code.
Reduce scope of if-else statements.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D151178
2023-05-23 14:37:14 +08:00
Amaury Séchet
87bf2bff05 [NFC][DAG] Simplify a giant expression in visitMul. 2023-05-18 18:58:07 +00:00
Amaury Séchet
6f28b0bb0a [NFC] Flatten the logic in RISCVTargetLowering::decomposeMulByConstant 2023-05-18 14:45:00 +00:00
Sergei Barannikov
01a7967447 [CodeGen] Replace CCState's getNextStackOffset with getStackSize (NFC)
The term "next stack offset" is misleading because the next argument is
not necessarily allocated at this offset due to alignment constrains.
It also does not make much sense when allocating arguments at negative
offsets (introduced in a follow-up patch), because the returned offset
would be past the end of the next argument.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D149566
2023-05-17 21:51:45 +03:00
Philip Reames
4dc9a2c5b9 [RISCV] Use scalar stores for splats of zero to memory up to XLen
The direct motivation here is to undo an unprofitable vectorization performed by SLP, but the transform seems generally useful as well. If we are storing a zero to memory, we can use a single scalar store (from X0) for all power of two sizes up to XLen.

Differential Revision: https://reviews.llvm.org/D150717
2023-05-17 07:30:27 -07:00
Jay Foad
d8229e2f14 [KnownBits] Define and use intersectWith and unionWith
Define intersectWith and unionWith as two complementary ways of
combining KnownBits. The names are chosen for consistency with
ConstantRange.

Deprecate commonBits as a synonym for intersectWith.

Differential Revision: https://reviews.llvm.org/D150443
2023-05-16 09:23:51 +01:00
Craig Topper
f2a05c64e3 [RISCV] Add RISCVISD nodes for VWFMADD_VL.
Use it to replace isel patterns with a DAG combine of FP_EXTEND_VL+VFMADD_VL.

This makes it similar to how other widening operations are handled.

I plan to use this to make it easier to form tail undisturbed vfwmacc.
2023-05-14 22:35:47 -07:00
Craig Topper
9ad9380fbc [LegalizeVectorOps][AArch64][RISCV][X86] Use OpVT for ISD::SETCC in LegalizeVectorOps.
Previously, LegalizeVectorOps used the result VT while LegalizeDAG
used the operand VT. This patch makes them both use the operand VT.

This also makes it consistent with how the default cost model works.

I've hacked the AArch64 cost model to maintain old behavior for some
f16 vectors.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D149572
2023-05-13 23:33:00 -07:00
Craig Topper
39fe48b74e [RISCV] Move VFMADD_VL DAG combine to a function. NFC
This is preparation for an additional combine.
2023-05-12 12:34:23 -07:00
Qihan Cai
773b0aaa49 [RISCV][CodeGen] Support Zhinx and Zhinxmin
This patch was split from D122918.

Co-Author: @liaolucy @sunshaoce

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D149811
2023-05-12 18:31:35 +10:00