4307 Commits

Author SHA1 Message Date
Wang Pengcheng
f9c908862a
[RISCV] Split TuneShiftedZExtFusion (#76032)
We split `TuneShiftedZExtFusion` into three fusions to make them
reusable and match the GCC implementation[1].

The zexth/zextw fusions can be reused by XiangShan[2] and other
commercial processors, but shifted zero extension is not so common.

`macro-fusions-veyron-v1.mir` is renamed so it's not relevant to
specific processor.

References:
[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637303.html
[2] https://xiangshan-doc.readthedocs.io/zh_CN/latest/frontend/decode
2023-12-22 14:37:26 +08:00
wangpc
90f816e61f [RISCV] Rename TuneVeyronFusions to TuneVentanaVeyron
And fusion features are added to processor definition.
2023-12-22 14:29:31 +08:00
Craig Topper
e64f5d6305
[RISCV] Replace RISCVISD::VP_MERGE_VL with a new node that has a separate passthru operand. (#75682)
ISD::VP_MERGE treats the false operand as the source for elements past
VL. The vmerge instruction encodes 3 registers and treats the vd
register as the source for the tail.

This patch adds a new ISD opcode that models the tail source explicitly.
During lowering we copy the false operand to this operand.

I think we can merge RISCVISD::VSELECT_VL with this new opcode by using
an UNDEF passthru, but I'll save that for another patch.
2023-12-21 14:34:49 -08:00
Craig Topper
0dcff0db3a
[RISCV] Add codegen support for experimental.vp.splice (#74688)
IR intrinsics were already defined, but no codegen support had been
added.

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-12-21 08:38:32 -08:00
Yeting Kuo
9b561ca044
[RISCV] Make performFP_TO_INTCombine fold with ISD::FRINT. (#76020)
Fold (fp_to_int (frint X)) to (fcvt X) without rounding mode.
2023-12-21 15:03:36 +08:00
Brandon Wu
b3769adbc5
[RISCV] Fix wrong lmul for sf_vfnrclip (#76016) 2023-12-21 13:24:26 +08:00
Craig Topper
b03f0c596a
[RISCV] Add sifive-p450 CPU. (#75760)
This is an out of order core with no vector unit. More information:
https://www.sifive.com/cores/performance-p450-470

Scheduler model and other tuning will come in separate patches.
2023-12-20 09:52:02 -08:00
Yeting Kuo
b7376c3196
[RISCV][NFC] Add comments and tests for frint case of performFP_TO_INT_SATCombine. (#76014)
performFP_TO_INT_SATCombine could also serve pattern (fp_to_int_sat
(frint X)).
2023-12-20 14:56:28 +08:00
Brandon Wu
fb51aae702
[RISCV] Add missing lmul info for SiFive extensions (#76006) 2023-12-20 14:42:47 +08:00
Craig Topper
05abe8a7e8
[RISCV] Remove Zfbfmin dependency from Zvfbfmin. (#75851)
Zvfbfmin does not have any scalar operands making this an unnecessary
dependency. The spec was just updated to remove this. See
86d7a74f4b

This fixes a correctness issue where Xsfvfwmaccqqq was incorrectly
depending on Zfbfmin. The SiFive CPUs that support Xsfvfwmaccqqq do not
implement Zfbfmin, but do implement Zvfbfmin based on a previous
understanding that it only requires Zve32f. I've added tests for this
feature to raise the bar for adding dependencies to it in the future.
2023-12-19 15:07:38 -08:00
Michael Maitland
571d151dec
[RISCV][MISched] Set EnableIntervals to true for SiFive7 (#75681)
The SiFive7 scheduler model has been using AcquireAtCycles and
ReleaseAtCycles for some time. Without EnableIntervals, the scheduler
was not making decisions based on this information. This patch sets
EnableIntervals to true, and the test case demonstrates that the VADD
instructions can be issued one cycle earlier since the VCQ is not
reserved. This leads to better saturation of the SiFive7VA.
2023-12-19 11:03:03 -05:00
Craig Topper
beb2c7fb69
[RISCV] Move TargetOverlapConstraintType from RISCVVPseudo to TSFlags. NFC (#75877)
It can be more efficiently accessed from TSFlags and won't require extra
storage.

NFC because it wasn't exported to the cpp PseudoTable and isn't used in
tree yet.
2023-12-18 22:25:34 -08:00
Eric Biggers
09058654f6
[RISCV] Remove experimental from Vector Crypto extensions (#74213)
The RISC-V vector crypto extensions have been ratified. This patch
updates the Clang and LLVM support for these extensions to be
non-experimental, while leaving the C intrinsics as experimental since
the C intrinsics are not yet standardized.

Co-authored-by: Brandon Wu <brandon.wu@sifive.com>
2023-12-18 22:04:22 -08:00
Yeting Kuo
cdc0392669
[RISCV] Update implies for subtarget feature. (#75824)
PR #75576 and #75735 update some implies in
llvm/lib/Support/RISCVISAInfo.cpp, but both of them miss the subtarget
feature part.
This patch still preserve predicate HasStdExtZfhOrZfhmin and
HasStdExtZhinxOrZhinxmin, since they could make error message more
readable. ( Users might not know that zfh implies zfhmin.)
2023-12-19 09:47:46 +08:00
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
Jie Fu
b6cce87110 [RISCV] Fix -Wbraced-scalar-init in RISCVISelLowering.cpp (NFC)
llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:339:24:
 error: braces around scalar initializer [-Werror,-Wbraced-scalar-init]
  339 |     setOperationAction({ISD::ROTL}, XLenVT, Expand);
      |                        ^~~~~~~~~~~
1 error generated.
2023-12-17 19:59:42 +08:00
melonedo
3eaed9e6f5
[RISCV] Implement intrinsics for XCVbitmanip extension in CV32E40P (#74993)
Implement XCVbitmanip intrinsics for CV32E40P according to the
specification.

This commit is part of a patch-set to upstream the vendor specific
extensions of CV32E40P that need LLVM intrinsics to implement Clang
builtins.

Contributors: @CharKeaney, @ChunyuLiao, @jeremybennett, @lewis-revill,
@NandniJamnadas, @PaoloS02, @simonpcook, @xingmingjie.

Spec:
05481cf0ef/specifications/corev-builtin-spec.md (listing-of-pulp-bit-manipulation-builtins-xcvbitmanip).

Previously reviewed on Phabricator: https://reviews.llvm.org/D157510.
Parallel GCC patch:
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635795.html.

Co-authored-by: melonedo <funanzeng@gmail.com>
2023-12-17 19:29:40 +08:00
Philip Reames
4fa9697b47 [RISCV][InsertVSETVLI] Factor out isNonZeroLoadImmediate helper [nfc]
Just reducing a bit of code duplication.
2023-12-15 11:20:01 -08:00
Philip Reames
e8a15eca92
[RISCV] Prefer whole register loads and stores when VL=VLMAX (#75531)
If we're lowering a fixed length vector load or store which happens to
exactly VLEN in size (when VLEN is exactly known), we can use a whole
register load or store instead of the unit strided variants. This
doesn't require a vsetvli in some cases, allows additional flexibility
of vsetvli cases in others, and doesn't have a runtime dependency on the
value of VL.
2023-12-15 09:26:57 -08:00
Wang Yaduo
c532ba4edd [RISCV] Support printing immediate of RISCV MCInst in hexadecimal format (#74053)
Enable the llvm-objdump to disassemble the immediate of RISCV
instruction in hexadecimal format with --print-imm-hex flag.
2023-12-14 22:42:11 -08:00
Vitaly Buka
fc3adf74d3
Revert "[RISCV] Support printing immediate of RISCV MCInst in hexadecimal format" (#75561)
Reverts llvm/llvm-project#74053

Breaks https://lab.llvm.org/buildbot/#/builders/5/builds/39291

Co-authored-by: Wang Yaduo <wangyaduo@linux.alibaba.com>

Issue #75563
2023-12-14 22:05:47 -08:00
Wang Yaduo
3dde0d0256
[RISCV] Support printing immediate of RISCV MCInst in hexadecimal format (#74053)
Enable the llvm-objdump to disassemble the immediate of RISCV
instruction in hexadecimal format with --print-imm-hex flag.
2023-12-15 10:13:20 +08:00
Philip Reames
46d1f30882
[RISCV][InsertSETVTLI] Handle large immediates in backwards walk (#75409)
When doing our backwards walk, we were not handling the case where the
AVL was defined by a register whose definition was an ADDI xN, x0,
<imm>. Doing so (as we already do in the forward pass) allows us to
prune a few more transitions.
2023-12-14 07:36:07 -08:00
Philip Reames
632f1c5d18
[RISCV] When VLEN is exactly known, prefer VLMAX encoding for vsetvli (#75412)
If we know the exact VLEN, then we can tell if the AVL for particular
operation is equivalent to the vsetvli xN, zero, <vtype> encoding. Using
this encoding is better than having to materialize an immediate in a
register, but worse than being able to use the vsetivli zero, imm,
<type> encoding.
2023-12-13 17:51:03 -08:00
Philip Reames
12af9c8337 [RISCV] Extract a utility for computing bounds on VLMAX [nfc]
Simplifying an upcoming change...
2023-12-13 13:40:18 -08:00
Craig Topper
2c185709bc
[RISCV] Remove setJumpIsExpensive(). (#74647)
Middle end up optimizations can speculate away the short circuit
behavior of C/C++ && and ||. Using i1 and/or or logical select
instructions and a single branch.

SelectionDAGBuilder can turn i1 and/or/select back into multiple
branches, but this is disabled when jump is expensive.

RISC-V can use slt(u)(i) to evaluate a condition into any GPR which
makes us better than other targets that use a flag register. RISC-V also
has single instruction compare and branch. So its not clear from a code
size perspective that using compare+and/or is better.

If the full condition is dependent on multiple loads, using a logic
delays the branch resolution until all the loads are resolved even if
there is a cheap condition that makes the loads unnecessary.

PowerPC and Lanai are the only CPU targets that use setJumpIsExpensive.
NVPTX and AMDGPU also use it but they are GPU targets. PowerPC appears
to have a MachineIR pass that turns AND/OR of CR bits into multiple
branches. I don't know anything about Lanai and their reason for using
setJumpIsExpensive.

I think the decision to use logic vs branches is much more nuanced than
this big hammer. So I propose to make RISC-V match other CPU targets.

Anyone who wants the old behavior can still pass -mllvm
-jump-is-expensive=true.
2023-12-13 09:37:25 -08:00
Yingwei Zheng
3564c85b0e
[RISCV] Eliminate dead li after emitting VSETVLIs (#65934)
This patch tracks li instructions that set AVL operands and does DCE
after emitting VSETVLIs.
2023-12-13 23:18:48 +08:00
Craig Topper
8227072f5a [RISCV] Add missing break to last case in switch. NFC 2023-12-12 13:52:52 -08:00
Luke Lau
30e200b81e [RISCV] Remove forward declaration and unused argument. NFC 2023-12-12 17:51:35 +09:00
Luke Lau
6707b33b80
[RISCV] Don't set AVL if only zeroness is demanded (#74049)
This refactors the logic in transferBefore so that we're moving in the
direction of "keep the existing Info, only change what is needed".

For the sake of review there are two commits in this PR: The former is
needed to make the latter an NFC commit. Neither introduce any test
diffs but the former is not technically NFC, hence why I did not
precommit it.

- [RISCV] Preserve AVL when previous info is ratio only in
transferBefore
- [RISCV] Don't change AVL if only zeroness is demanded. NFC
2023-12-12 17:30:18 +09:00
Luke Lau
39445046dc
[RISCV] Remove unecessary early exit in transferBefore (#74040)
Previously we bailed if we encountered a pseudo without a VL op, i.e.
vmv.x.s,
which prevented us from preserving VL and VTYPE. It looks like this was
copied
over from a time whenever this code was operating on the MachineInstrs
in
place, see https://reviews.llvm.org/D127870

However because we no longer mutate the MIs, we can just get rid of this
early
exit which allows us to preserve VL and VTYPE when dealing with vmv.x.s.
2023-12-12 17:25:19 +09:00
Kazu Hirata
8f1accfb35 Revert "[RISCV] Update the interface of sifive vqmaccqoq (#74284)"
This reverts commit dc5570319676c14c48440b4ee87c8cfb35102ff6.

Several bots seem to be failing:

https://lab.llvm.org/buildbot/#/builders/10/builds/34651
https://lab.llvm.org/buildbot/#/builders/178/builds/6320
https://lab.llvm.org/buildbot/#/builders/77/builds/32918
2023-12-11 22:46:43 -08:00
Brandon Wu
dc55703196
[RISCV] Update the interface of sifive vqmaccqoq (#74284)
The
spec(https://sifive.cdn.prismic.io/sifive/60d5a660-3af0-49a3-a904-d2bbb1a21517_int8-matmul-spec.pdf)
is updated.
2023-12-12 13:17:47 +08:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-11 21:01:36 -08:00
Mikhail Gudim
29ee66f4a0
[RISCV] Macro-fusion support for veyron-v1 CPU. (#70012)
Support was added for the following fusions:
  auipc-addi, slli-srli, ld-add
Some parts of the code became repetative, so small refactoring of
existing lui-addi fusion was done.
2023-12-11 16:34:13 -05:00
Kazu Hirata
55531e715f [Target] Remove unused forward declarations (NFC) 2023-12-10 10:38:55 -08:00
Kazu Hirata
b85f1f9b18 [Target] Include bitset (NFC)
These files are relying on the transitive include of <bitset> from
GIMatchTableExecutor.h, which doesn't actually use std::bitset.
2023-12-09 18:34:57 -08:00
Craig Topper
2b36d85a3e [RISCV] Update comment for AVL operand in pseudo instructions. NFC 2023-12-08 10:47:31 -08: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
Wang Pengcheng
ea85345eb6
[RISCV][NFC] Use raw_svector_ostream to construct key of SubtargetMap (#72964)
To simplify some code.
2023-12-08 18:34:31 +08:00
Kazu Hirata
286ef12b47 [Target] Remove unnecessary includes (NFC) 2023-12-07 21:03:56 -08:00
Craig Topper
4162a9bca4 [RISCV] Cleanup pass initialization.
Remove redundant initializations from pass constructors that were
already being initialized by LLVMInitializeRISCVTarget().
2023-12-07 18:21:38 -08:00
Craig Topper
efc32f5e06 [RISCV] Use Triple::isRISCV64(). NFC 2023-12-07 18:21:20 -08:00
Craig Topper
e87f33d9ce
[RISCV][MC] Pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup. (#73721)
Instead of using the STI stored in RISCVAsmBackend, try to get it from
the MCFragment.

This addresses the issue raised here
https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
2023-12-07 13:17:58 -08:00
Craig Topper
b310932f87
[RISCV] Add vmv.x.s to RISCVOptWInstrs. (#74519)
This instruction produces a 32-bit sign extended value if the SEW is less than or
equal to 32.
2023-12-06 17:06:56 -08:00
Craig Topper
65cb5d58eb [RISCV] Remove DecoderNamespace from vector pseudoinstructions.
Pseudoinstructions don't have decoding information so don't need
a namespace.
2023-12-06 10:25:00 -08:00
Alex Bradbury
b717365216
[MachineScheduler][NFCI] Add Offset and OffsetIsScalable args to shouldClusterMemOps (#73778)
These are picked up from getMemOperandsWithOffsetWidth but weren't then
being passed through to shouldClusterMemOps, which forces backends to
collect the information again if they want to use the kind of heuristics
typically used for the similar shouldScheduleLoadsNear function (e.g.
checking the offset is within 1 cache line).

This patch just adds the parameters, but doesn't attempt to use them.
There is potential to use them in the current PPC and AArch64
shouldClusterMemOps implementation, and I intend to use the offset in
the heuristic for RISC-V. I've left these for future patches in the
interest of being as incremental as possible.

As noted in the review and in an inline FIXME, an ElementCount-style abstraction may later be used to condense these two parameters to one argument. ElementCount isn't quite suitable as it doesn't support negative offsets.
2023-12-06 15:30:48 +00:00