1336 Commits

Author SHA1 Message Date
Craig Topper
72f30acfed [RISCV] Disable Zbs special case in performTRUNCATECombine with -riscv-experimental-rv64-legal-i32. 2023-11-09 10:19:28 -08:00
Craig Topper
679cc16c99 [RISCV] Disable early promotion for Zbs in performANDCombine with riscv-experimental-rv64-legal-i32
We can match this directly in isel with the i32 type being legal.

The generic DAG combine will unpromote part of the pattern and
prevent it from being matched in isel.
2023-11-09 09:51:31 -08:00
Wang Pengcheng
e179b125fb
[RISCV][NFC] Pass MCSubtargetInfo instead of FeatureBitset in RISCVMatInt (#71770)
The use of `hasFeature` is more descriptive and the callers of
`RISCVMatInt` have no need to call `getFeatureBits()` any more.
2023-11-09 15:15:23 +08:00
Jianjian Guan
d36eb79ccc
[RISCV] Support Strict FP arithmetic Op when only have Zvfhmin (#68867)
Include: STRICT_FADD, STRICT_FSUB, STRICT_FMUL, STRICT_FDIV,
STRICT_FSQRT and STRICT_FMA.
2023-11-09 09:55:48 +08:00
Craig Topper
90f768440d
[VP][RISCV] Add llvm.experimental.vp.reverse. (#70405)
This is similar to vector.reverse, but only reverses the first EVL
elements.

I extracted this code from our downstream. Some of it may have come from
https://repo.hca.bsc.es/gitlab/rferrer/llvm-epi/ originally.
2023-11-05 22:39:27 -08:00
Craig Topper
ae49bf5a7b [RISCV] Fix stale comments in lowerShift*Parts. NFC
This comment was not updated when we changed from xor back to sub.
2023-11-02 22:20:49 -07:00
Craig Topper
5570d3250f [RISCV] Don't promote i32 and/or/xor with -riscv-experimental-rv64-legal-i32.
Some test improvements, but also some regressions that need to be
fixed.
2023-11-01 11:36:46 -07:00
Craig Topper
8912200966
[RISCV] Add experimental support for making i32 a legal type on RV64 in SelectionDAG. (#70357)
This will select i32 operations directly to W instructions without
custom nodes. Hopefully this can allow us to be less dependent on
hasAllNBitUsers to recover i32 operations in RISCVISelDAGToDAG.cpp.

This support is enabled with a command line option that is off by
default.

Generated code is still not optimal.

I've duplicated many test cases for this, but its not complete. Enabling this runs all existing lit tests without crashing.
2023-11-01 09:36:41 -07:00
Min-Yih Hsu
87f671756d
[RISCV] Use FLI + FNEG to materialize some negative FP constants (#70825)
Most of the FP constants supported by FLI are positive. For negative FP
constants X whose positive values is supported by FLI, we can use `(FNEG
(FLI -X))` to materialize X.
2023-10-31 17:52:50 -07:00
Craig Topper
4d80e93039
[RISCV] Remove RISCVISD opcodes for LGA, LA_TLS_IE, and LA_TLS_GD. (#70137)
This effectively reverts f912d21e673b0

This was originally done for consistency with RISCVISD::ADD_LO so that
all nodes were emitted as RISCVISD nodes.

I've received feedback a couple times that its not worth it. So I'm
putting it back.
2023-10-25 11:29:20 -07:00
Min-Yih Hsu
e696379c0d
[RISCV][GISel] Falling back to SDISel for scalable vector type values (#70133)
This patch also tests the fallback of unsupported formal arguments.
2023-10-25 09:02:34 -07:00
Philip Reames
25da9bb7d4
[RISCV] Allow swapped operands in reduction formation (#68634)
Very straight forward, but worth landing on it's own in advance of a
more complicated generalization.
2023-10-23 10:37:56 -07:00
Craig Topper
44d4f975e4 [RISCV] Replace RISCV -> RISC-V in comments. NFC
I did this once previously, but more uses have crept in.
2023-10-21 10:52:24 -07:00
Luke Lau
b4729f79ed
[RISCV] Use LMUL=1 for vmv_s_x_vl with non-undef passthru (#66659)
We currently shrink the type of vmv_s_x_vl to LMUL=1 when its passthru
is
undef to avoid constraining the register allocator since it ignores
LMUL.
This patch relaxes it for non-undef passthrus, which occurs when
lowering
insert_vector_elt.
2023-10-20 14:19:04 -04:00
Ramkumar Ramachandra
98c90a13c6
ISel: introduce vector ISD::LRINT, ISD::LLRINT; custom RISCV lowering (#66924)
The issue #55208 noticed that std::rint is vectorized by the
SLPVectorizer, but a very similar function, std::lrint, is not.
std::lrint corresponds to ISD::LRINT in the SelectionDAG, and
std::llrint is a familiar cousin corresponding to ISD::LLRINT. Now,
neither ISD::LRINT nor ISD::LLRINT have a corresponding vector variant,
and the LangRef makes this clear in the documentation of llvm.lrint.*
and llvm.llrint.*.

This patch extends the LangRef to include vector variants of
llvm.lrint.* and llvm.llrint.*, and lays the necessary ground-work of
scalarizing it for all targets. However, this patch would be devoid of
motivation unless we show the utility of these new vector variants.
Hence, the RISCV target has been chosen to implement a custom lowering
to the vfcvt.x.f.v instruction. The patch also includes a CostModel for
RISCV, and a trivial follow-up can potentially enable the SLPVectorizer
to vectorize std::lrint and std::llrint, fixing #55208.

The patch includes tests, obviously for the RISCV target, but also for
the X86, AArch64, and PowerPC targets to justify the addition of the
vector variants to the LangRef.
2023-10-19 13:05:04 +01:00
Yeting Kuo
5341d5465d
[RISCV] Combine (and (select cond, x, -1), c) to (select cond, x, (and x, c)) with Zicond. (#69563)
It's only beneficial when cond is setcc with integer equality condition
code. For other case, it has same instruction count as the original.
2023-10-19 16:11:11 +08:00
Craig Topper
d51855f700
[RISCV] Fix assertion failure from performBUILD_VECTORCombine when the binop is a shift. (#69349)
The RHS of a shift can have a different type than the LHS. If there are
undefs in the vector, we need the undef added to the RHS to match the
type of any shift amounts that are also added to the vector.

For now just don't add shifts if their RHS and LHS don't match.
2023-10-18 21:40:28 -07:00
Wang Pengcheng
654a3a3cbc
[OpenCL][RISCV] Support SPIR_KERNEL calling convention (#69282)
X86 supports this calling convention but I don't find any special
handling, so I think we can just handle it via CC_RISCV.

This should fix #69197.
2023-10-19 11:00:39 +08:00
Craig Topper
040df124a2
[RISCV] Don't let performBUILD_VECTORCombine form a division or remainder with undef elements. (#69482)
Division/remainder by undef is immediate UB across the entire vector.
2023-10-18 13:51:22 -07:00
Craig Topper
7f34355754
[RISCV] Use separate CCValAssign for both parts of f64 with ilp32. (#69129)
Mark any registers as CustomReg and any stack slot as CustomMem.
    
This allows us to more directly emit the register or memory access for
the high part. Previously we needed a memory access if the low register
was X17 and we assumed the stack offset was 0. If the low part wasn't
X17, we assumed the high register was the next register after the low
register.
    
This is another part of supporting FP arguments with GISel.
2023-10-17 08:29:50 -07:00
Jianjian Guan
b0eba8e209
[RISCV] Support STRICT_FP_ROUND and STRICT_FP_EXTEND when only have Zvfhmin (#68559)
This patch supports STRICT_FP_ROUND and STRICT_FP_EXTEND when we only
have Zvfhmin but no Zvfh.
2023-10-17 10:10:19 +08:00
Michael Maitland
c319c74146 [RISCV] Improve performCONCAT_VECTORCombine stride matching
If the load ptrs can be decomposed into a common (Base + Index) with a
common constant stride, then return the constant stride.
2023-10-16 16:45:26 -07:00
Luke Lau
182a65adcf
[RISCV] Refactor performCONCAT_VECTORSCombine. NFC (#69068)
Instead of doing a forward pass for positive strides and a reverse pass
for
negative strides, we can just do one pass by negating the offset if the
pointers do happen to be in reverse order.

We can extend getPtrDiff later in #68726 to handle more constant offset
sequences.
2023-10-16 12:56:32 -04:00
Craig Topper
58c9ef5a2d
[RISCV] Use f64 for LocVT for ilp32 when whole f64 is passed on the stack. NFC (#69118)
This removes the special case from unpackF64OnRV32DSoftABI. We can use
the default MemLoc handling.

This also allows us to remove a isRegLoc() check from LowerCall.

This part of preparation for supporting FP arguments with GISel.
2023-10-15 21:35:14 -07:00
Craig Topper
514381840c [RISCV] Move hasOneUse() call after opcode check.
hasOneUse can be more expensive for nodes with multiple outputs.
It's better to check the opcode first to skip nodes with multiple
outputs.

I have not seen an issue from this, just noticed while reviewing
code for a possible enhancement.
2023-10-13 22:38:48 -07:00
Sacha Coppey
776889bc1c [RISCV] Add Stackmap/Statepoint/Patchpoint support without targets
This patch adds stackmap support for RISC-V without targets (i.e. the nop patchable forms).

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D123496
2023-10-11 09:18:55 +05:30
Philip Reames
3a6cc52fe3 Revert "[RISCV] Shrink vslideup's LMUL when lowering fixed insert_subvector (#65997)"
This reverts commit b5ff71e261b637ab7088fb5c3314bf71d6e01da7.  As described in
https://github.com/llvm/llvm-project/issues/68730, this appears to have exposed
an existing liveness issue.  Revert to green until we can figure out how to
address the root cause.

Note: This was not a clean revert.  I ended up doing it by hand.
2023-10-10 15:13:57 -07:00
Philip Reames
08b20d8385
[RISCV] Generaize reduction tree matching to fp sum reductions (#68599)
This builds on the transform introduced in f0505c3, and generalizes to
all integer operations in 45a334d. This change adds support for floating
point sumation.

A couple of notes:
* I chose to leave fmaxnum and fminnum unhandled for the moment. They
have a slightly different set of legality rules.
* We could form strictly sequenced FADD reductions for FADDs without
fast math flags. As the ordered reductions are more expensive, I left
thinking about this as a future exercise.
* This can't yet match the full vector reduce + start value idiom. That
will be an upcoming set of changes.
2023-10-09 11:31:41 -07:00
Jianjian Guan
76fc871552
[RISCV] Support fptoi like ops for fp16 vectors input when only have Zvfhmin (#67532)
This patch supports FP_TO_SINT, FP_TO_UINT, VP_FP_TO_SINT and
VP_FP_TO_UINT for fp16 vectors input when we only have Zvfhmin but no
Zvfh.
2023-10-08 10:44:19 +08:00
Brandon Wu
70368eaeb8
[RISCV] Support VLS for VCIX (#67289) 2023-10-07 01:29:51 +08:00
Philip Reames
3aa2bac64a [RISCV] Use early return to simplify isFPImmLegal [nfc]
Minor comment and readability change only.
2023-10-05 10:44:11 -07:00
Alexey Bataev
e22818d5c9 [IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst.
Need to add NumSrcElts param to is..Mask functions in
ShuffleVectorInstruction class for better mask analysis. Mask.size() not
always matches the sizes of the permuted vector(s). Allows to better
estimate the cost in SLP and fix uses of the functions in other cases.

Differential Revision: https://reviews.llvm.org/D158449
2023-10-05 06:17:07 -07:00
Arthur Eubanks
07389535a7 Revert "[IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst."
This reverts commit b186f1f68be11630355afb0c08b80374a6d31782.

Causes crashes, see https://reviews.llvm.org/D158449.
2023-10-04 14:37:16 -07:00
Luke Lau
3b0b84fd00
[RISCV] Fix illegal build_vector when lowering double id buildvec on RV32 (#67017)
When lowering a constant build_vector sequence of doubles on RV32, if
the
addend wasn't zero, or the step/denominator wasn't one, it would crash
trying
to emit an illegal build_vector of <n x i64> with i32 operands, e.g:

t15: v2i64 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>

This patch fixes this by lowering the splats with
SelectionDAG::getConstant
with the vector type, which handles making it legal via
splat_vector_parts.
2023-10-04 21:28:44 +01:00
Michael Maitland
92da28aae8
[RISCV][ISel] Fix comment to match direction of predicate in code. NFC. (#68248)
The comment says something different than what is happening in the code.
This patch aligns the comment with the code.
2023-10-04 15:17:38 -04:00
Philip Reames
45a334d31c [RISCV] Generaize reduction tree matching to all integer reductions (#68014) (reapply)
This was reverted in 824251c9b349d859a9169196cd9533c619a715ce exposed by this change in a previous patch.  Fixed in 199cbec987ee68d70611db8e7961b43c3dbad83e.  Original commit message follows.

This builds on the transform introduced in
https://github.com/llvm/llvm-project/pull/67821, and generalizes it for
all integer reduction types.

A couple of notes:
* This will only form smax/smin/umax/umin reductions when zbb is
enabled. Otherwise, we lower the min/max expressions early. I don't care
about this case, and don't plan to address this further.
* This excludes floating point. Floating point introduces concerns about
associativity. I may or may not do a follow up patch for that case.
* The explodevector test change is mildly undesirable from a clarity
perspective. If anyone sees a good way to rewrite that to stablize the
test, please suggest.
2023-10-04 10:41:29 -07:00
Philip Reames
199cbec987 [RISCV] Don't try to form VECREDUCE without vector instructions
This fixes a bug in f0505c which wasn't noticed until 7a0b9da had landed.  This triggered a revert of 7a0b9da, which will be reapplied after this fix.
2023-10-04 10:29:27 -07:00
Alexey Bataev
b186f1f68b [IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst.
Need to add NumSrcElts param to is..Mask functions in
ShuffleVectorInstruction class for better mask analysis. Mask.size() not
always matches the sizes of the permuted vector(s). Allows to better
estimate the cost in SLP and fix uses of the functions in other cases.

Differential Revision: https://reviews.llvm.org/D158449
2023-10-04 07:53:30 -07:00
Alex Bradbury
824251c9b3 Revert "[RISCV] Generaize reduction tree matching to all integer reductions (#68014)"
This reverts commit 7a0b9daac9edde4293d2e9fdf30d8b35c04d16a6 and
63bbc250440141b1c51593904fba9bdaa6724280.

I'm seeing issues (e.g. on the GCC torture suite) where
combineBinOpOfExtractToReduceTree is called when the V extensions aren't
enabled and triggers a crash due to RISCVSubtarget::getElen asserting.

I'll aim to follow up with a minimal reproducer. Although it's pretty
obvious how to avoid this crash with some extra gating, there are a few
options as to where that should be inserted so I think it's best to
revert and agree the appropriate fix separately.
2023-10-04 12:51:01 +01:00
Alexey Bataev
1129dec778 Revert "[IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst."
This reverts commit 6f43d28f3452b3ef598bc12b761cfc2dbd0f34c9 to fix
a crash reported in https://reviews.llvm.org/D158449.
2023-10-03 13:02:16 -07:00
Alexey Bataev
6f43d28f34 [IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst.
Need to add NumSrcElts param to is..Mask functions in
ShuffleVectorInstruction class for better mask analysis. Mask.size() not
always matches the sizes of the permuted vector(s). Allows to better
estimate the cost in SLP and fix uses of the functions in other cases.

Differential Revision: https://reviews.llvm.org/D158449
2023-10-03 10:26:11 -07:00
Luke Lau
169c20584d
[RISCV] Relax some Zvbb patterns and lowerings to Zvkb (#68115)
vandn, vrev8 and vro{l,r} are now part of Zvkb, which Zvbb now implies.
This
patch updates the predicates to check for Zvkb instead of Zvbb in the
tablegen
patterns for the SD and VL nodes, as well as some of the lowering logic
in
RISCVISelLowering.
2023-10-03 17:42:40 +01:00
Philip Reames
63bbc25044 [RISCV] Remove a stray semi-colon [nfc]
Noticed by a smallish subset of the build bots.  Interestingly, most compilers appear to accept a stray semi-colon between function bodies.
2023-10-03 09:10:40 -07:00
Philip Reames
7a0b9daac9
[RISCV] Generaize reduction tree matching to all integer reductions (#68014)
This builds on the transform introduced in
https://github.com/llvm/llvm-project/pull/67821, and generalizes it for
all integer reduction types.

A couple of notes:
* This will only form smax/smin/umax/umin reductions when zbb is
enabled. Otherwise, we lower the min/max expressions early. I don't care
about this case, and don't plan to address this further.
* This excludes floating point. Floating point introduces concerns about
associativity. I may or may not do a follow up patch for that case.
* The explodevector test change is mildly undesirable from a clarity
perspective. If anyone sees a good way to rewrite that to stablize the
test, please suggest.
2023-10-03 07:34:39 -07:00
Craig Topper
3c0990c188
[RISCV] Generalize the (ADD (SLLI X, 32), X) special case in constant materialization. (#66931)
We don't have to limit ourselves to a shift amount of 32. We can support
other shift amounts that make the upper 32 bits line up.
2023-10-02 13:03:06 -07:00
Craig Topper
8f4ffbbaf7
[RISCV] Create new build vector instead of relying on getNode constan… (#67944)
…t folding.

We want to create a build_vector with narrower elements here. Normally
getNode on the ISD::TRUNCATE will constant fold this to a new
BUILD_VECTOR. If it doesn't constant fold, we end up with a cycle in the
DAG because we truncate the node we are replacing. Constant folding can
fail if one of the elements is an opaque constant.

The failing case I saw involved an opaque constant created by a memset
that was expanded. Not sure exactly what happened after that.

This patch creates a new BUILD_VECTOR with the new type directly.
2023-10-02 09:13:33 -07:00
Philip Reames
0e8f924fc5 [RISCV] Combine two reduction lowering utility functions into one [nfc] 2023-10-02 08:32:15 -07:00
Philip Reames
f0505c3dbe
[RISCV] Form vredsum from explode_vector + scalar (left) reduce (#67821)
This change adds two related DAG combines which together will take a
left-reduce scalar add tree of an explode_vector, and will incrementally
form a vector reduction of the vector prefix. If the entire vector is
reduced, the result will be a reduction over the entire vector.

Profitability wise, this relies on vredsum being cheaper than a pair of
extracts and scalar add. Given vredsum is linear in LMUL, and the
vslidedown required for the extract is *also* linear in LMUL, this is
clearly true at higher index values. At N=2, it's a bit questionable,
but I think the vredsum form is probably a better canonical form
anyways.

Note that this only matches left reduces. This happens to be the
motivating example I have (from spec2017 x264). This approach could be
generalized to handle right reduces without much effort, and could be
generalized to handle any reduce whose tree starts with adjacent
elements if desired. The approach fails for a reduce such as (A+C)+(B+D)
because we can't find a root to start the reduce with without scanning
the entire associative add expression. We could maybe explore using
masked reduces for the root node, but that seems of questionable
profitability. (As in, worth questioning - I haven't explored in any
detail.)

This is covering up a deficiency in SLP. If SLP encounters the scalar
form of reduce_or(A) + reduce_sum(a) where a is some common
vectorizeable tree, SLP will sometimes fail to revisit one of the
reductions after vectorizing the other. Fixing this in SLP is hard, and
there's no good reason not to handle the easy cases in the backend.

Another option here would be to do this in VectorCombine or generic DAG.
I chose not to as the profitability of the non-legal typed prefix cases
is very target dependent. I think this makes sense as a starting point,
even if we move it elsewhere later.

This is currently restructed only to add reduces, but obviously makes
sense for any associative reduction operator. Once this is approved, I
plan to extend it in this manner. I'm simply staging work in case we
decide to go in another direction.
2023-10-01 17:42:07 -07:00
Alexey Bataev
ebcb5d59fc Revert "[IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst."
This reverts commit 9f5960e004ff54082ccfa9396522e07358f5b66b to fix
buildbots reported here https://lab.llvm.org/buildbot/#/builders/230/builds/19412.
2023-09-29 15:03:46 -07:00
Alexey Bataev
9f5960e004 [IR]Add NumSrcElts param to is..Mask static function in ShuffleVectorInst.
Need to add NumSrcElts param to is..Mask functions in
ShuffleVectorInstruction class for better mask analysis. Mask.size() not
always matches the sizes of the permuted vector(s). Allows to better
estimate the cost in SLP and fix uses of the functions in other cases.

Differential Revision: https://reviews.llvm.org/D158449
2023-09-29 13:16:03 -07:00