1787 Commits

Author SHA1 Message Date
anjenner
4af249fe6e
Add usub_cond and usub_sat operations to atomicrmw (#105568)
These both perform conditional subtraction, returning the minuend and
zero respectively, if the difference is negative.
2024-09-06 16:19:20 +01:00
Craig Topper
093b8bfe6b
[RISCV] Separate the calling convention handlers into their own file. NFC (#107484)
These are used by both SelectionDAG and GlobalISel and are separate from
RISCVTargetLowering.

Having a separate file is how other targets are structured. Though other
targets generate most of their calling convention code through tablegen.

I moved the `CC_RISV` functions from the `llvm::RISCV` namespace to
`llvm::`. That's what the tablegen code on other targets does and the
functions already have RISCV in their name. `RISCVCCAssignFn` is moved
from `RISCVTargetLowering` to the `llvm` namespace.
2024-09-05 22:29:23 -07:00
Craig Topper
13013bdc6a
[RISCV] Don't cost Fmv for Zfinx in isFPImmLegal. (#107361)
There is no Fmv with Zfinx.
2024-09-05 08:42:13 -07:00
Brandon Wu
1465e23985
[RISCV][llvm] Handle ptr element type in lowerDeinterleaveIntrinsicToLoad and lowerInterleaveIntrinsicToStore (#107079)
Resolve https://github.com/llvm/llvm-project/issues/106970

currently it returns 0 fixed size for `ptr` element type. The `ptr`
element size should depend on `XLen` which is 64 in riscv64 and 32 in
riscv32 respectively.
2024-09-05 12:46:20 +08:00
Craig Topper
c82a5496c8
[RISCV] Support fixed vector VP_LOAD/STORE for bf16 and f16 without Zvfh. (#107297)
This allows odd sized vector load/store to be legalized to a
VP_LOAD/STORE using EVL.

I changed the bf16 tests in fixed-vectors-load.ll and
fixed-vectors-store.ll to use an illegal type to be consistent with the
intent of these files. A legal type is already tested in
fixed-vectors-load-store.ll
2024-09-04 17:49:50 -07:00
Craig Topper
d21e731c42 [RISCV] Fix typos in comment. NFC 2024-09-04 13:02:33 -07:00
Craig Topper
36c210bb34
[RISCV] Remove pre-assignment of mask vectors during call lowering. NFC (#107192)
The first mask vector operand is supposed to be assigned to V0. No other
vector types will be assigned to V0. We don't need to pre-assign, we can
just try V0 first for any mask vectors in the normal processing.
2024-09-04 11:14:31 -07:00
Craig Topper
7deda4ed0c [RISCV] Use MCRegister for variables returned from AllocateReg. NFC
Avoids a cast from Register to MCRegister for the CCValAssign
functions.
2024-09-03 23:14:49 -07:00
Craig Topper
41402c6a8a
[RISCV][GISel] Use CCValAssign::getCustomReg for converting f16/f32<->GPR. (#105700)
This gives us much better control of the generated code for GISel. I've
tried to closely match the current gisel code, but it looks like we had
2 layers of G_ANYEXT in some cases before.

SelectionDAG now checks needsCustom() instead of detecting the special
cases in the Bitcast handler.

Unfortunately, IRTranslator for bitcast still generates copies between
register classes of different sizes. Because of this we can't handle
i16<->f16 bitcasts without crashing. Not sure if I should teach
RISCVInstrInfo::copyPhysReg to allow copies between FPR16 and GPR or if
I should convert the copies to instructions in GISel.
2024-09-03 22:49:02 -07:00
Craig Topper
3e798476de
[LegalizeDAG][RISCV] Don't promote f16 vector ISD::FNEG/FABS/FCOPYSIGN to f32 when we don't have Zvfh. (#106652)
The fp_extend will canonicalize NaNs which is not the semantics of
FNEG/FABS/FCOPYSIGN.

For fixed vectors I'm scalarizing due to test changes on other targets
where the scalarization is expected. I will try to address in a follow
up.

For scalable vectors, we bitcast to integer and use integer logic ops.
2024-09-03 22:44:49 -07:00
Craig Topper
a5ce66423b [RISCV] Remove RISCVISD::FP_ROUND_BF16.
Use isel patterns on regular FP_ROUND. For double->bf16 we need
to emit two instructions. Note the double->bf16 conversion does
double rounding, but I don't know a good way to fix that.
2024-09-03 20:18:01 -07:00
Craig Topper
ff0f2011e4
[RISCV] Bitcast fixed length bf16/f16 build_vector to i16 with Zvfbfmin/Zvfhmin+Zfbfmin/Zfhmin. (#106637)
Previously, if Zfbfmin/Zfhmin were enabled, we only handled
build_vectors that could be turned into splat_vectors. We promoted them
to f32 splats by extending in the scalar domain and narrowing in the
vector domain.

This patch fixes a crash where we failed to account for whether the f32
vector type fit in LMUL<=8.

Because the new lowering occurs after type legalization, we have to be
careful to use XLenVT for the scalar integer type and use custom cast
nodes.
2024-09-03 17:50:04 -07:00
Craig Topper
1c874bbbd6
[RISCV] Don't promote f16/bf16 SELECT with Zfhmin/Zfbfmin. (#107138)
Select only needs branches and moves so we don't need to promote it.
Promoting would canonicalize NaNs which select shouldn't do.
2024-09-03 16:04:51 -07:00
Craig Topper
db3792b87a
[RISCV] Custom promote f16/bf16 fp_to_(s/u)int to reduce isel patterns that emit two instructions. (#107011)
All of the test changes are because integer type legalization prefers to promote
fp_to_uint to fp_to_sint if neither is "Legal".
2024-09-03 15:34:25 -07:00
Craig Topper
ec8e1c623a
[RISCV] Custom promote f16/bf16 (s/u)int_to_fp. (#107026)
This avoids having isel patterns that emit two instrutions. It also
allows us to remove sext.w and slli+srli pairs by using fcvt.s.w(u) on
RV64.
2024-09-03 13:33:14 -07:00
Craig Topper
9a1eded9b9
[RISCV] Custom legalize f16/bf16 FCOPYSIGN with Zfhmin/Zbfmin. (#107039)
The LegalizeDAG expansion will go through memory since i16 isn't a legal
type. Avoid this by using FMV nodes.

Similar to what we did for #106886 for FNEG and FABS. Special care is
needed to handle the Sign operand being a different type.
2024-09-02 22:04:09 -07:00
Craig Topper
55eb93b268
[RISCV] Remove RISCVISD::FP_EXTEND_BF16. (#106939)
I don't think we need this node. We can isel fp_extend directly.
fp_extend to f64 requires two instructions, but we can emit them with an
isel pattern.

I have not removed RISCVISD::FP_ROUND_BF16 because f64->bf16 needs more
work to fix the double rounding.
2024-09-02 10:14:04 -07:00
Craig Topper
357bd61744 [RISCV] Custom promote f16 (l)lround/(l)lrint with Zfhmin/Zhinxmin instead of using isel patterns. 2024-09-01 13:44:52 -07:00
Craig Topper
3bdec31316
[RISCV] Custom legalize f16/bf16 FNEG/FABS with Zfhmin/Zbfmin. (#106886)
The LegalizeDAG expansion will go through memory since i16 isn't a legal
type. Avoid this by using FMV nodes.
2024-08-31 23:57:40 -07:00
Craig Topper
6f682c26b0 [RISCV] Merge similar code for legalizing i16<->f16 and i<->bf16 bitcasts. NFC 2024-08-31 20:01:06 -07:00
Craig Topper
2afa975928 [RISCV] Use MCRegister for vectors in CC_RISCV_FastCC. NFC 2024-08-31 10:51:39 -07:00
Craig Topper
6d9c6f0ca5 [RISCV] Use MCRegister for return value from allocateRVVReg. NFC 2024-08-31 10:30:44 -07:00
Jie Fu
1061c6da53 [RISCV] Fix -Wunused-variable in RISCVISelLowering.cpp (NFC)
/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:21558:14: error: unused variable 'ValLMUL' [-Werror,-Wunused-variable]
    unsigned ValLMUL =
             ^
/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:21561:14: error: unused variable 'PartLMUL' [-Werror,-Wunused-variable]
    unsigned PartLMUL =
             ^
2 errors generated.
2024-08-31 22:18:59 +08:00
Brandon Wu
22f98740b6
[llvm][RISCV] Support RISCV vector tuple CodeGen and Calling Convention (#97995)
This patch handles target lowering and calling convention.

For target lowering, the vector tuple type represented as multiple
scalable vectors is now changed to a single `MVT`, each `MVT` has a
corresponding register class.

The load/store of vector tuples are handled as the same way but need
another vector insert/extract instructions to get sub-register group.

Inline assembly constraint for vector tuple type can directly be modeled
as "vr" which is identical to normal vector registers.

For calling convention, it no longer needs an alternative algorithm to
handle register allocation, this makes the code easier to maintain and
read.

Stacked on https://github.com/llvm/llvm-project/pull/97994
2024-08-31 19:28:36 +08:00
Brandon Wu
db67a66e8e
Revert "[RISCV] RISCV vector calling convention (2/2)" (#97994)
This reverts commit 91dd844aa499d69c7ff75bf3156e2e3593a88057.

Stacked on https://github.com/llvm/llvm-project/pull/97993
2024-08-31 19:02:35 +08:00
Craig Topper
c25293c6dd
[LegalizeVectorOps][RISCV] Don't promote VP_FABS/FNEG/FCOPYSIGN. (#106659)
Promoting canonicalizes NaNs which changes the semantics. Bitcast to
integer and use logic ops instead.
2024-08-30 09:44:51 -07:00
Craig Topper
688843bda8
[RISCV] Add constant folding combine for FMV_X_ANYEXTW/H. (#106653) 2024-08-30 09:43:42 -07:00
Craig Topper
a9ffb719bc
[RISCV] Don't promote f16 FNEG/FABS with Zfhmin/Zhinxmin. (#106474)
fneg/fabs are not supposed to canonicalize nans. Promoting to f32 will
go through an fp_extend which will canonicalize. The generic Promote
handler needs to be removed from LegalizeDAG.

We need to use integer bit manip to clear the bit instead.

Unfortunately, this is going through the stack due to i16 not being a
legal type. Fixing that will require custom legalization or some other
generic SelectionDAG change.
2024-08-29 09:07:51 -07:00
Luke Lau
3b64ede096
[RISCV] Decompose LMUL > 1 reverses into LMUL * M1 vrgather.vv (#104574)
As far as I'm aware, vrgather.vv is quadratic in LMUL on most
microarchitectures today due to each output register needing to read
from each input register in the group.

For example, the reciprocal throughput for vrgather.vv on the
spacemit-x60 is listed on
https://camel-cdr.github.io/rvv-bench-results/bpi_f3 as:

    LMUL1   LMUL2   LMUL4   LMUL8
    4.0	16.0	64.0	256.1

Vector reverses are commonly emitted by the loop vectorizer and are
lowered as vrgather.vvs, but since the loop vectorizer uses LMUL 2 by
default they end up being quadratic.

The output registers in a reverse only need to read from one input
register though, so we can decompose this into LMUL * M1 vrgather.vvs to
get linear performance.

This gives a 0.43% runtime improvement on 526.blender_r at rva22u64_v O3
on the Banana Pi F3.
2024-08-29 14:32:41 +08:00
Craig Topper
0ef8e71874 [RISCV] Custom legalize vXbf16 BUILD_VECTOR without Zfbfmin.
By default, type legalization will try to promote the build_vector,
but that generic type legalizer doesn't support that. Bitcast to
vXi16 instead. Same as what we do for vXf16 without Zfhmin.

Fixes #100846.
2024-08-26 21:58:26 -07:00
Craig Topper
f54ae6d48b [RISCV] Merge duplicate switch cases. NFC 2024-08-26 21:06:42 -07:00
Craig Topper
296ffc1b38 [RISCV] Don't check hasStdExtZfh and hasStdExtZfhmin. NFC
hasStdExtZfh implies hasStdExtZfhmin so it is sufficient to check
only hasStdExtZfhmin.

Similar for Zhinx and Zhinxmin.
2024-08-26 17:20:04 -07:00
Craig Topper
32acf1e95b [RISCV] Use XLenVT as LocVT for f16/f32/f164 with Zfinx in CC_RISCV_FastCC.
This is need to make sure we create FMV_X_W/FMV_X_H/bitcast nodes
that match up with what return lowering will do.
2024-08-26 16:34:12 -07:00
Craig Topper
4b0c0ec6b8
[CodeGen] Use MCRegister for CCState::AllocateReg and CCValAssign::getReg. NFC (#106032) 2024-08-26 11:40:25 -07:00
Philip Reames
ae48affd25 [RISCV] Minor style fixes in lowerVectorMaskVecReduction [nfc]
Reuse existing routine to avoid duplication, and reduce variable scopes.
2024-08-21 10:47:17 -07:00
YunQiang Su
2b84fe6f16
RISC-V: Add fminimumnum and fmaximumnum support (#104411)
Since 2.2, `fmin.s/fmax.s` instructions follow the IEEE754-2019, if F
extension is avaiable; and `fmin.d/fmax.d` also follow the IEEE754-2019
if D extension is avaiable.

So, let's mark them as Legal.
2024-08-21 09:10:55 +08:00
Craig Topper
e6ceb29ab6 [RISCV] Use getAllOnesConstant/getSignedConstant. 2024-08-17 00:18:41 -07:00
Craig Topper
d8c9d58393
[RISCV] Don't support TRUNCATE_SSAT_U. (#104468)
RISC-V doesn't have an instruction for this. We were treating it the
same as TRUNCATE_USAT_U.
2024-08-16 08:42:36 -07:00
Luke Lau
ac92dcc756
[RISCV] Lower fixed reverse vector_shuffles through vector_reverse (#104461)
This teaches lowerVECTOR_REVERSE to handle fixed length vectors, and
then lowers reverse vector_shuffles through it.

The motiviation for this is to allow fixed length vectors to share a
potential optimization on vector_reverse in an upcoming patch (splitting
up LMUL > 1 vrgathers.vv)
2024-08-16 13:26:30 +08:00
Philip Reames
039a86d057
[RISCV] Use significant bits helpers in narrowing of build vectors [nfc] (#104511) 2024-08-15 16:46:19 -07:00
Luke Lau
11c2da8fb7
[RISCV] Narrow indices to e16 for LMUL > 1 when lowering vector_reverse (#104427)
The vector_shuffle lowering already does this to reduce register
pressure, so also do it here.
2024-08-15 23:18:03 +08:00
LiqinWeng
abaa53199e
[RISCV] Implement RISCVTTIImpl::shouldConsiderAddressTypePromotion for RISCV (#102560)
This optimization helps reduce repeated calculations of base addresses
by extracting type extensions when the same base address is accessed
multiple times but its offset is a constant.
2024-08-15 10:37:04 +08:00
Craig Topper
4f7ce107de [RISCV] Don't combine (sext_inreg (fmv_x_anyexth X), i16) with Zhinx.
With Zfh and Zfhmin this combine creates a fmv_x_signexth node so we can
remember that the result is sign extended. This become a fmv.x.h
instruction which sign extends its result.

With Zhinx, fmv_x_signexth becomes a COPY_TO_REGCLASS. In order for
this to guarantee the result is properly sign extended we need all
producers of a GPRF16 register class to guarantee the rest of the
GPR is sign extended. I don't think we've done that. bitcasts from i16
to f16 definitely don't do it.

The safest thing to do is to not do this combine so the sign_extend_inreg
will emit a shift pair. This is also consistent with the code generated
for Zfinx on RV64, we don't assume the upper 32 bits are sign extended.
2024-08-14 15:18:10 -07:00
hanbeom
0d074ba197
[DAG] Support saturated truncate (#99418)
A truncate is considered saturated if no additional conversion is required between the target and return values. If the target is saturated when attempting to truncate from a vector, there is an opportunity to optimize it.

Previously, each architecture had its own attempt at optimization, leading to redundant code. This patch implements common logic by introducing three new ISDs:

`ISD::TRUNCATE_SSAT_S`: When the operand is a signed value and  the range of values matches the range of signed values of the  destination type.

`ISD::TRUNCATE_SSAT_U`: When the operand is a signed value and the range of values matches the range of unsigned values of the destination type.

`ISD::TRUNCATE_USAT_U`: When the operand is an unsigned value and the range of values matches the range of unsigned values of the destination type.

These ISDs indicate a saturated truncate.

Fixes https://github.com/llvm/llvm-project/issues/85903
2024-08-14 09:52:36 +01:00
Craig Topper
51bad732dc [SelectionDAG] Replace EVTToAPFloatSemantics with MVT/EVT::getFltSemantics. (#103001) 2024-08-13 11:35:28 -07:00
Craig Topper
c772f5d53a
[RISCV] Disable fixed vectors in getOptimalMemOpType if minimum VLEN is 32. (#102974)
This is needed to match #102405 which disabled fixed to scalable vector
lowering for VLEN=32.

Fixes #102566 and #102568.
2024-08-12 20:55:13 -07:00
Craig Topper
8fd1484e30
[LegalizeTypes][RISCV] Use signed promotion for UADDSAT if that's what the target prefers. (#102842)
As noted in #102781 we can promote UADDSAT if we use sign extend instead
of zero extend.

The custom handler for RISC-V was using SIGN_EXTEND when the Zbb
extension was enabled. With this change we no longer need the custom
code.
2024-08-12 09:34:51 -07:00
Hassnaa Hamdi
3176f255c9
[IA][AArch64]: Construct (de)interleave4 out of (de)interleave2 (#89276)
- [AArch64]: TargetLowering is updated to spot load/store (de)interleave4 like sequences using PatternMatch,
   and emit equivalent sve.ld4 and sve.st4 intrinsics.
2024-08-12 17:23:00 +01:00
Craig Topper
257c479b91
[LegalizeTypes][RISCV] Use SExtOrZExtPromotedOperands to promote operands for USUBSAT. (#102781)
It doesn't matter which extend we use to promote the operands. Use
whatever is the most efficient.

The custom handler for RISC-V was using SIGN_EXTEND when the Zbb
extension is enabled so we no longer need that.
2024-08-11 10:22:31 -07:00
Craig Topper
ca7ad38ca0
[RISCV] Remove riscv-experimental-rv64-legal-i32. (#102509)
This has received no development work in a while and is slowly bit
rotting as new extensions are added.

At the moment, I don't think this is viable without adding a new
invariant that 32 bit values are always in sign extended form like
Mips64 does. We are very dependent on computeKnownBits and
ComputeNumSignBits in SelectionDAG to remove sign extends created for
ABI reasons. If we can't propagate sign bit information through 64-bit
values in SelectionDAG, we can't effectively clean up those extends.
2024-08-09 11:48:48 -07:00