910 Commits

Author SHA1 Message Date
Benjamin Kramer
b6942a2880 [NFC] Hide implementation details in anonymous namespaces 2023-01-08 17:37:02 +01:00
Craig Topper
9f087ba05b [RISCV] Improve 4x and 8x (s/u)int_to_fp.
Previously we emitted a 4x or 8x vzext followed by a vfcvt.
We can instead use a 2x or 4x vzext followed by a vfwcvt.
2023-01-06 08:39:14 -08:00
Guillaume Chatelet
87b6b347fc Revert D141134 "[NFC] Only expose getXXXSize functions in TypeSize"
The patch should be discussed further.

This reverts commit dd56e1c92b0e6e6be249f2d2dd40894e0417223f.
2023-01-06 15:27:50 +00:00
Guillaume Chatelet
dd56e1c92b [NFC] Only expose getXXXSize functions in TypeSize
Currently 'TypeSize' exposes two functions that serve the same purpose:
 - getFixedSize / getFixedValue
 - getKnownMinSize / getKnownMinValue

source : bf82070ea4/llvm/include/llvm/Support/TypeSize.h (L337-L338)

This patch offers to remove one of the two and stick to a single function in the code base.

Differential Revision: https://reviews.llvm.org/D141134
2023-01-06 15:24:52 +00:00
Yeting Kuo
5a57ebcc43 [VP][RISCV] Add vp.abs and RISC-V support.
RISC-V uses ISD::ABS lower method (abs x) -> (smax_vl x (sub_vl 0, x)) for ISD::VP_ABS.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D141033
2023-01-06 15:18:12 +08:00
serge-sans-paille
38818b60c5
Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ part
Use deduction guides instead of helper functions.

The only non-automatic changes have been:

1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*))
2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase.
3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated.
4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that).

Per reviewers' comment, some useless makeArrayRef have been removed in the process.

This is a follow-up to https://reviews.llvm.org/D140896 that introduced
the deduction guides.

Differential Revision: https://reviews.llvm.org/D140955
2023-01-05 14:11:08 +01:00
Yeting Kuo
1e9e1b9cf8 [VP][RISCV] Add vp.ctlz/cttz and RISC-V support.
The patch also adds expandVPCTLZ and expandVPCTTZ to expand vp.ctlz/cttz nodes
and the cost model of vp.ctlz/cttz.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140370
2023-01-04 15:15:01 +08:00
jacquesguan
3bbdd9f506 [RISCV] Fix compile warning. 2023-01-03 11:58:18 +08:00
jacquesguan
db3f3243bb [RISCV] Use vfirst.m to extract the first element from mask vector.
This patch uses vfirst.m to extract the first bit of mask.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139512
2023-01-03 11:24:18 +08:00
Yeting Kuo
e2b65ff98d [RISCV] Use tail agnostic if inserting subvector/element at the end of a vector.
The patch tries to make more vslidup nodes use tail agnostic. The idea comes
from D125546 authored by Zack Chen.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140669
2022-12-31 11:29:09 +08:00
Craig Topper
a63b724729 [RISCV] Use SUB instead of XOR in lowerShiftLeftParts/lowerShiftRightParts./
isel is now capable of turning the SUB into XOR for shift amounts.
Though it uses NOT instead of XOR with ShiftSize-1.

By using SUB during lowering we enable more DAG combines with
other arithmetic on the shift amount.
2022-12-29 17:04:52 -08:00
Hsiangkai Wang
740cb3377d [RISCV][NFC] Remove redundant setOperationAction.
ISD::INSERT_VECTOR_ELT is already set above.

Differential Revision: https://reviews.llvm.org/D140716
2022-12-28 09:11:32 +00:00
Ilya Andreev
550d93ab1d [RISCV] Combine comparison and logic ops
Two comparison operations and a logical operation are combined into selection using MIN or MAX and comparison operation.
For optimization to be applied conditions have to be satisfied:
  1. In comparison operations has to be the one common operand.
  2. Supports only signed and unsigned integers.
  3. Comparison has to be the same with respect to common operand.
  4. There are no more users of comparison except logic operation.
  5. Every combination of comparison and AND, OR are supported.

It will convert
  %l0 = %a < %c
  %l1 = %b < %c
  %res = %l0 or %l1
into
  %sel = min(%a, %b)
  %res = %sel < %c

It supports several comparison operations (<, <=, >, >=), signed, unsigned values and different order of operands if they do not violate conditions.

Differential Revision: https://reviews.llvm.org/D134277
2022-12-23 17:10:21 +03:00
ping.deng
31ec840c61 [RISCV][NFC] Use Arrayref in TargetLowering functions.
Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D140464
2022-12-22 10:45:27 +08:00
Craig Topper
9b227cb1f5 [RISCV] Check the sign bits of the input of RISCVISD::ABSW in computeNumSignBitsForTargetNode.
We created a SIGN_EXTEND_INREG when we created the ABSW so the
input should have 33 sign bits, but check it to be safe.
2022-12-21 12:56:35 -08:00
Craig Topper
132546d939 [RISCV] Add DAG combine to fold (select C, (add X, Y), Y) -> (add (select C, X, 0), Y).
Similar for sub, or, and xor. These are all operations that have 0
as a neutral value. This is based on a similar tranform in InstCombine.

This allows us to remove some XVentanaCondOps patterns and
some code from DAGCombine for RISCVISD::SELECT_CC.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D140465
2022-12-21 10:57:57 -08:00
Elena Lepilkina
3a3f725a3c [RISCV] Omit SRA in case of setlt or setge with zero constant
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140206
2022-12-21 14:19:49 +03:00
Craig Topper
b6b30cb291 [RISCV] Simplify some code in SELECT_CC combine. NFC
An integer SELECT_CC should have all XLenVT operands, we don't
need to handle other cases.
2022-12-20 21:31:23 -08:00
Yeting Kuo
f8a05727b0 [RISCV][NFC] Add policy operand for RISCVISD::VSLIDEUP_VL and RISCVISD::VSLIDEDOWN_VL.
There is room for optimization to use tail agnostic vslideup/vslidedown to lower
some vector operations. D125546 is an revision for the kind of optimization.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140393
2022-12-21 10:50:04 +08:00
Kautuk Consul
6a907a41f4 [RISCV] Add codegen support for RISCV XVentanaCondOps Extension
This patch adds codegen support for part of XVentanaCondOps extension.
This extension is designed to reduce the number of branches in
the generated RISCV assembly by replacing branches with conditional
move instructions as defined by XVentanaCondOps specification.

The specification for XVentanaCondOps extension can be found at:
https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.1/ventana-custom-extensions-v1.0.1.pdf

Co-authored-by: Mikhail Gudim <mgudim@ventanamicro.com>

Differential Revision: https://reviews.llvm.org/D139394
2022-12-19 09:56:06 -08:00
Qiu Chaofan
a40ef656d8 [Intrinsic] Rename flt.rounds intrinsic to get.rounding
Address the inconsistency between FLT_ROUNDS_ and SET_ROUNDING SDAG
node. Rename FLT_ROUNDS_ to GET_ROUNDING and add llvm.get.rounding
intrinsic to replace flt.rounds.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D139507
2022-12-19 15:22:39 +08:00
Christudasan Devadasan
b5efec4b27 [CodeGen] Additional Register argument to storeRegToStackSlot/loadRegFromStackSlot
With D134950, targets get notified when a virtual register is created and/or
cloned. Targets can do the needful with the delegate callback. AMDGPU propagates
the virtual register flags maintained in the target file itself. They are useful
to identify a certain type of machine operands while inserting spill stores and
reloads. Since RegAllocFast spills the physical register itself, there is no way
its virtual register can be mapped back to retrieve the flags. It can be solved
by passing the virtual register as an additional argument. This argument has no
use when the spill interfaces are called during the greedy allocator or even the
PrologEpilogInserter and can pass a null register in such cases.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D138656
2022-12-17 11:55:34 +05:30
Yeting Kuo
982a586ab4 [RISCV] Emit .variant_cc directives for vector function calls.
The patch is splitted from D103435. The patch emits .variant_cc [0] for those
function calls that have vector arguments or vector return values.

[0]: https://github.com/riscv/riscv-elf-psabi-doc/pull/190

Initial authored by: HsiangKai

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D139414
2022-12-16 13:51:39 +08:00
Anton Sidorenko
37f9eec142 [RISCV] Allow conversion of fp divisions to fp multiplications by the reciprocal
If the divisor is repeated at least twice, we will convert the FDIVs to the
calculation of the reciprocal and FMULs.

We perform the transformation only under fast-math mode. FDIVs must have
'arcp' flag.

Differential Revision: https://reviews.llvm.org/D140024
2022-12-15 13:00:36 +03:00
Philip Reames
d86011984e [RISCV] Avoid generate large LMUL vmv.s.x or fvmv.s.f
This is a follow up to patch discussion on D139656. As noted there, M2/M4/M8 versions of these instructions don't actually exist, and using them results in overly constrained register allocation.

In that review, we'd talked about moving towards a variant of the instructions which ignored LMUL. I decided to see what happened if we just stopped generating the high LMUL variants, and the results are surprisingly neutral. I only see one minor thing which looks like a real regression among all the churn. I think this is worth doing now to loosen register allocation constraints, and avoid digging our hole around these instructions deeper while thinking about the right model change.

Differential Revision: https://reviews.llvm.org/D140027
2022-12-14 10:53:34 -08:00
Yeting Kuo
ad68586a37 [VP][RISCV] Add vp.ctpop and RISC-V support.
The patch also adds expandVPCTPOP in TargetLowering to expand VP_CTPOP nodes.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139920
2022-12-14 09:47:44 +08:00
Philip Reames
668cde81df [RISCV] Reuse VL (if non-zero) when building single element vector for start of reduction chain
This is an alternative patch on a path to D137530.

The basic problem being tackled here is that we need to place a scalar into lane 0 of a vector register before our reduction instructions. Since we only care about lane 0 of the vector, we can use any VL >= 1 provided that the total amount of work performed matches the work performed for a VL=1.

This change does not contain the logic from D137530 to perform the insert at the original VT, and then extract down to LMUL1. That turns out to be a good choice, as discussion in this review has indicated there are issues around LMUL2 and above with our representation of vmv.s.x. We'd also need to be careful with the splat logic for the same reasons.

The only potentially concerning codegen change I spot here is that we stop using a broadcast load (for VL=1) and instead do a scalar load and insert. I think this is probably reasonable; if reviewers disagree, I can investigate using a broadcast load which writes to the undef lanes. If we want to do that, we should do it for VECTOR_INSERT_ELT as well, so that'll end up as it's own patch series.

Differential Revision: https://reviews.llvm.org/D139656
2022-12-13 12:16:26 -08:00
Craig Topper
bee9a92aec [RISCV] Use reduction result type for EXTRACT_VECTOR_ELT in lowerReductionSeq.
Remove the call to getSExtOrTrunc.

Reduction ISD nodes produce a scalar result and that result is
allowed to be larger than the vector element type due to type
legalization. This is the same rule we allow for EXTRACT_VECTOR_ELT
for the same reason.

We can copy the result type over from the reduction node to
EXTRACT_VECTOR_ELT.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D139757
2022-12-13 09:10:36 -08:00
Philip Reames
ecabba04a3 [RISCV] Use lowerScalarInsert when folding op into reduction [nfc]
This doesn't cause any functional change since this is being applied to a insert generated by the same routine.  This is mostly about consolidating the logic for vmv.s.x into one place to simplify future changes.
2022-12-13 09:08:39 -08:00
Philip Reames
44e0427cf0 [RISCV] Use lowerScalarInsert in lowerReductionSeq [nfc]
Use the newly introduced helper routine.  At the moment, this generates the same code (at this call site!) since LMUL is restricted to LMUL1 or less, and VL is hard coded to 1.  In a future patch, I will loosen the second part.
2022-12-13 09:08:39 -08:00
Philip Reames
8adde6941a [RISCV] Use vmv.v.i for insertion into lane 0 of undef vector when profitable
If we're initializing lane 0 of an undef vector, we can optionally write to other lanes of the vector. Doing so may require additional work, so we don't want to e.g. always use a splat. However, since we don't have an immediate form of vmv.s.x it's useful to use a vmv.v.i if the work required is expected to be equal in practice.  We restrict this to when LMUL <= 1 to a) prevent doing additional work at higher LMULs, and b) avoid overconstraining the register allocator.

At the moment, the new utility is only used by one case in INSERT_VECTOR_ELT lowering. My expectation is that we will reuse this in a couple other places, but each of those deserve individual review.

This change is inspired by D137530, but is not directly related to it. I vaguely remember we discussed the tradeoffs of using vmv.v.i in another recent review, but couldn't find it.

Differential Revision: https://reviews.llvm.org/D139648
2022-12-13 07:54:46 -08:00
Alexey Baturo
54e72dd4eb re-land [RISC-V][HWASAN] Support tagging global variables for RISC-V HWASAN
Now with fix to limit added tagged-globals.ll to risc-v platform
--
[RISC-V][HWASAN] Support tagging global variables for RISC-V HWASAN

Reviewed by: luismarques

Differential Revision: https://reviews.llvm.org/D132995
2022-12-13 15:51:51 +03:00
Alexey Baturo
5e89876538 Revert "[RISC-V][HWASAN] Support tagging global variables for RISC-V HWASAN"
This reverts commit 11937ca5642216a67e021e69fc824f709267bada.
2022-12-13 15:17:40 +03:00
Alexey Baturo
11937ca564 [RISC-V][HWASAN] Support tagging global variables for RISC-V HWASAN
Reviewed by: luismarques

Differential Revision: https://reviews.llvm.org/D132995
2022-12-13 14:57:34 +03:00
Philip Reames
a4b45c28a1 [RISCV] Allow fractional LMUL for reduction start value
For reductions, we need to put the start value into a source vector. For fractional LMULs, we can perform the operation at the original LMUL.  For LMUL > 1, we eventually want to use a scalar insert, but that's outside the scope of this patch.

Differential Revision: https://reviews.llvm.org/D139747
2022-12-12 09:08:21 -08:00
jacquesguan
c2f199fa48 [DAGCombiner] Scalarize extend/truncate for splat vector.
This revision scalarizes extend/truncate for splat vector.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D122875
2022-12-12 14:53:10 +08:00
Yeting Kuo
47b9da72e0 [VP][RISCV] Add vp.bitreverse and RISC-V support.
The patch also added function expandVPBITREVERSE to expand ISD::VP_BITREVERSE nodes.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139697
2022-12-12 10:58:44 +08:00
Craig Topper
eec0ac9726 [RISCV] clang-format lowerReductionSeq. NFC
Wraps a long line to 80 columns.
2022-12-09 17:03:35 -08:00
Philip Reames
1ebe8f4c45 [RISCV] Share reduction lowering code for vp.reduce
We can consolidate code and clarify edge case behavior at the same time.

There are two functional differences here.

First, I remove the ResVT handling, and always use the reduction element type. This appears to be dead code. There's no test coverage, and this code doesn't need to account for scalar type legalization anyways.

Second, if the VL happens to be known non-zero, we can avoid passing through start. This is mostly needed to allow reuse of the existing code; I don't consider it interesting as an optimization on it's own.

Differential Revision: https://reviews.llvm.org/D139733
2022-12-09 12:22:59 -08:00
Philip Reames
4e5b3f6307 [RISCV] Consolidate a bit of common logic for forming reductions
There's several patches in flght which change this code, better to only have one copy.

The VP case is left seperate for the moment as the result value type differs.
2022-12-09 08:18:51 -08:00
Craig Topper
66ff073182 [RISCV] Support F16 vectors with Zfhmin+Zvfh.
I've enabled Zfhmin on 2 basic tests to show this isn't
completely broken.

Reviewed By: monkchiang

Differential Revision: https://reviews.llvm.org/D139562
2022-12-07 19:14:11 -08:00
Craig Topper
258bb453fb [RISCV] Without Zfh, promote f16 inputs before creating RISCVISD::FCVT_W(U)_RV64 nodes.
This allows us to remove a couple more Zfhmin isel patterns.
2022-12-07 12:25:30 -08:00
Craig Topper
e3540fb948 [RISCV] Promote f16 fp_to_int_sat with Zfhmin during lowering instead of isel.
We already have a custom handler for FP_TO_(S/U)INT_SAT. It's easy
enought to inject an FP_EXTEND in there.
2022-12-07 11:58:30 -08:00
Yeting Kuo
0f8c761c48 [VP][RISCV] Recommit "Add vp.fshl/fshr and RISC-V support."
This reverts commit 7883e5b061bdbbe8bee5f479ebe911db5045b7e9.

The original commit was reverted that it didn't update test files after D136263
landed. The recommit fixed those.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139509
2022-12-07 15:58:12 +08:00
Kazu Hirata
7883e5b061 Revert "[VP][RISCV] Add vp.fshl/fshr and RISC-V support."
This reverts commit 70de0e014013b4d97febe6704881a9a8c893d078.

I'm seeing:

Failed Tests (2):
  LLVM :: CodeGen/RISCV/rvv/fixed-vectors-fshr-fshl-vp.ll
  LLVM :: CodeGen/RISCV/rvv/fshr-fshl-vp.ll

Also reported at:

https://lab.llvm.org/buildbot/#/builders/123/builds/14531
2022-12-06 22:27:43 -08:00
Monk Chiang
7b50c18360 [RISCV] Codegen support for Zfhmin.
The Zfhmin subset only has FLH, FSH, FMV.X.H, FMV.H.X, FCVT.S.H, and FCVT.H.S.
If the D extension is present, the FCVT.D.H and FCVT.H.D instructions are also included.
Since most instructions are not included for Zfhmin, so most operations are promoted.
The patch primarily about making f16 a legal type.

RISC-V ISA info:
https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139391
2022-12-06 22:14:15 -08:00
Yeting Kuo
70de0e0140 [VP][RISCV] Add vp.fshl/fshr and RISC-V support.
The patch made VectorLegalizer expand ISD::VP_FSHL and ISD::VP_FSHR to
achieve the codegen.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D138379
2022-12-07 12:16:36 +08:00
jacquesguan
f7a46aa8fb [RISCV] Fold vector binary operatrion into select with identity constant.
This patch implements shouldFoldSelectWithIdentityConstant for RISCV. It would try to generate vmerge after the binary instruction and let them folded to maksed instruction later.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D131551
2022-12-06 11:19:31 +08:00
ChunyuLiao
85834d8685 [RISCV]Keep (select c, 0/-1, X) during PerformDAGCombine
D135833, lowerSelect: (select C, -1/0, X) -> or/and
Keep (select c, 0/-1, X), thus making better use of lowerSelect to eliminate branch instructions.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D139272
2022-12-06 09:26:29 +08:00
Kazu Hirata
3c09ed006a [llvm] Use std::nullopt instead of None in comments (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 17:12:44 -08:00