Commit Graph

2222 Commits

Author SHA1 Message Date
Philip Reames
7ca0af8943 [RISCV] Consolidate test lines in fence lowering test
These are identical for RV32 and RV64.
2023-01-09 11:00:47 -08:00
Philip Reames
0fcbb12465 [RISCV] Add test coverage for singlethread fences 2023-01-09 10:14:12 -08:00
Alexey Baturo
35b8bb0ab3 [RISC-V][HWASAN] Don't explicitly load GOT entry to call hwasan mismatch routine
Reviewed by: luismarques

Differential Revision: https://reviews.llvm.org/D132994
2023-01-09 16:46:28 +03:00
LiDongjin
4554663bc0 Recommit "[RISCV] Enable the LocalStackSlotAllocation pass support"
This includes a fix for the tramp3d failure from the llvm-testsuite
that caused the last revert. Hopefully the others failures were the
same issue.

Original commit message:
For RISC-V, load/store(exclude vector load/store) instructions only has a 12 bit immediate operand. If the offset is out-of-range, it must make use of a temp register to make up this offset. If between these offsets, they have a small(IsInt<12>) relative offset, LocalStackSlotAllocation pass can find a value as frame base register's value, and replace the origin offset with this register's value plus the relative offset.

Co-authored-by: luxufan <luxufan@iscas.ac.cn>
Co-authored-by: Craig Topper <craig.topper@sifive.com>

Differential Revision: https://reviews.llvm.org/D98101
2023-01-06 09:54:19 -08: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
Craig Topper
1aa9862df3 [RISCV] Add more XVentanaCondOps patterns.
Add patterns with seteq/setne conditions.

We don't have instructions for seteq/setne except for comparing
with zero and need to emit an ADDI or XOR before a seqz/snez to
compare other values.

The select ISD node takes a 0/1 value for the condition, but the
VT_MASKC(N) instructions check all XLen bits for zero or non-zero.
We can use this to avoid the seqz/snez in many cases.

This is pretty ridiculous number of patterns. I wonder if we could
use some ComplexPatterns to merge them, but I'd like to do that as
a follow up and focus on correctness of the result in this patch.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D140421
2023-01-06 08:29:23 -08:00
Craig Topper
e5a71a41d8 [RISCV] Add support for the vscale_range attribute.
This is based on @frasercrmck's D107290. At least some of the clang
portion of D107290 has already been committed.

This uses vscale_range for min/max vector width unless the command
line overrides are used.

As a follow up, I plan to add a max or exact VLEN option to clang
to control the vscale_range. This will eliminate many of the reasons
for users to use the overrides through the -mllvm interface.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D139873
2023-01-06 08:20:37 -08: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
Kito Cheng
05a2ae1b4a [RISCV][InsertVSETVLI] Using right instruction during mutate AVL of vsetvli
Fixing a crash during vsetvli insertion pass.

We have a testcase with 3 vsetvli:

1. vsetivli        zero, 2, e8, m4, ta, ma
2. li      a1, 32;  vsetvli zero, a1, e8, m4, ta, mu
3. vsetivli        zero, 2, e8, m4, ta, ma

and then we trying to optimize 2nd vsetvli since the only user is vmv.x.s, so
it could mutate the AVL operand to the AVL operand of the 3rd vsetvli.
OK, so we propagate 2 to vsetvli, BUT it's vsetvli not vsetivli, so it expect a
register rather than a immediate value, so we have to update the opcode
if needed.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D141061
2023-01-06 00:44:30 +08: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
Philip Reames
46dee4a3a3 [RISCV][InsertVSETVLI] Split out demanded property for zero/non-zero of VL
The scalar move instructions (vmv.s.x, and fvmv.s.f) depend solely on whether the VL is 0 or non-zero. By tracking the fact we only demand the zeroness and not the whole VL value, we can allow changing VL over a scalar move. This helps to eliminate vsetvli toggles.

Differential Revision: https://reviews.llvm.org/D140157
2023-01-03 14:47:13 -08:00
Philip Reames
460c1bd344 [RISCV][InsertVSETVLI] Rewrite scalar insert forward rule in terms of demanded fields
This is mostly geared at consolidating logic into one form to reduce code duplication, but also has the effect of being a slight generalization. Since these operations aren't masked, we can ignore the mask policy bit when deciding on compatibility. The previous code was overly strict in checking that both policy bits matched.

Note: There's a slight difference from the reviewed version.  The reviewed version was based on a local revision which included the isCompatible change to only check AVL if VL is used.  I apparently never landed that change, and while functional, the functional change isn't visible without this one.  I chose to role the extra change into this patch.

Differential Revision: https://reviews.llvm.org/D140147
2023-01-03 14:19:52 -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
Craig Topper
7cd725858b [RISCV] RISCVDAGToDAGISel::selectShiftMask to shift by (sub size-1, X).
If the shift amount is (sub C, X) where C is -1 modulo the size of
the shift, we can replace the sub with a NOT.

We could also use XORI X, size-1, but NOT would work better with
c.not from the future Zce extension.
2022-12-29 16:33:18 -08:00
Craig Topper
e50976e569 [RISCV] Teach RISCVDAGToDAGISel::selectShiftMask to bypass adds with constant.
If the shift amount is (add X, C) where C is 0 modulo the size of
the shift, we can bypass the add.

Similar to other targets like AArch64 and X86.
2022-12-29 15:10:36 -08:00
Craig Topper
8abd70081f [TargetLowering] Teach BuildUDIV to take advantage of leading zeros in the dividend.
If the dividend has leading zeros, we can use them to reduce the
size of the multiplier and avoid the fixup cases.

This patch is for scalars only, but we might be able to do this
for vectors in a follow up.

Differential Revision: https://reviews.llvm.org/D140750
2022-12-29 13:58:46 -08:00
Hsiangkai Wang
af5dd2706c [RISCV] Add fmin/fmax scalar instructions to isAssociativeAndCommutative
Follow-up patch of D140530.

We can add FMIN, FMAX to isAssociativeAndCommutative to
increase instruction-level parallelism by the existing MachineCombiner
pass.

Differential Revision: https://reviews.llvm.org/D140602
2022-12-29 11:43:40 +00:00
Hsiangkai Wang
002005e674 [RISCV] Add integer scalar instructions to isAssociativeAndCommutative
Inspired by D138107.

We can add ADD, AND, OR, XOR, MUL, MIN[U]/MAX[U] to isAssociativeAndCommutative
to increase instruction-level parallelism by the existing MachineCombiner pass.

Differential Revision: https://reviews.llvm.org/D140530
2022-12-29 11:43:40 +00:00
Yeting Kuo
bd9c0f082b [RISCV] Add Svpbmt extension support.
Spec of Svpbmt: https://github.com/riscv/riscv-isa-manual/blob/master/src/supervisor.tex#L2399

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D140692
2022-12-28 23:57:54 -08:00
Craig Topper
0e9855c1f2 [RISCV] Add SH1ADD/SH2ADD/SH3ADD to RISCVDAGToDAGISel::hasAllNBitUsers. 2022-12-28 23:38:33 -08:00
Craig Topper
79d6e9c713 [RISCV] Prefer ADDI over ORI if the known bits are disjoint.
There is no compressed form of ORI but there is a compressed form
for ADDI.

This also works for XORI since DAGCombine will turn Xor with disjoint
bits in Or.

Note: The compressed forms require a simm6 immediate, but I'm doing
this for the full simm12 range.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D140674
2022-12-28 19:59:42 -08:00
Craig Topper
9b59207a98 [RISCV] Fix mistakes in fixed-vectors-vreductions-mask.ll command lines. NFC
There were 4 RUN lines, but only 2 of them were unique. I believe
we were trying to test LMUL=1 and LMUL=8 with riscv32 and riscv64.
But put riscv32 on both LMUL=1 lines and riscv64 on both LMUL=8 lines.
2022-12-28 15:26:15 -08:00
Craig Topper
6357b63735 [RISCV] Add RISCV::XORI to RISCVDAGToDAGISel::hasAllNBitUsers. 2022-12-28 15:17:41 -08:00
Craig Topper
cdf09ce7e7 [RISCV] Support SRLI in hasAllNBitUsers.
We can recursively look through SRLI if the shift amount is less
than the demanded bits. We can reduce the demanded bit count by
the shift amount and check the users of the SRLI.
2022-12-28 13:10:52 -08:00
Jojo R
54752f3ff6 [RISCV] Implement assembler support for XTHeadVdot
This patch implements the T-Head vendor extensions (XTHeadVdot),
which is documented here, it's based on standard vector extension v1.0:
  https://github.com/T-head-Semi/thead-extension-spec
2022-12-26 19:05:22 +08:00
Craig Topper
dfec6f7e62 Revert "[RISCV] Enable the LocalStackSlotAllocation pass support."
This reverts commit 180397cdde.

This seems to cause llvm-testsuite failures.
2022-12-25 12:57:47 -08:00
Roman Lebedev
110c5442b8 [NFC][Codegen] Add tests with oversized shifts by non-byte-multiple 2022-12-24 19:26:41 +03:00
Roman Lebedev
a9fbf25a14 [NFC][Codegen] Rename tests for oversized shifts by byte multiple 2022-12-24 19:26:41 +03:00
Craig Topper
653a9fbd13 [RISCV] Support the short-forward-branch predicated ops in RISCVSExtWRemoval. 2022-12-23 21:39:22 -08:00
Roman Lebedev
c10b0dfdc8 [NFC][Codegen] Add RISCV test coverage for D140638 2022-12-24 03:33:11 +03: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
Ilya Andreev
7b9b81a245 [RISCV][test] 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 or 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.
2022-12-23 17:10:21 +03:00
Nitin John Raj
d64d3c5a8f [RISCV] Add pass to remove W suffix from ADDIW and SLLIW to improve compressibility
SLLI and ADD are more compressible than SLLIW and ADDW. SLLI/ADD both have a 5-bit register encoding. SLLIW/ADDW have a 3-bit register encoding. They both require the dest to also be one of the sources.

We aggressively form ADDW/SLLIW as it helps hasAllWBitUsers in RISCVISelDAGToDAG to not require recursion. So we need a pass to remove excessive -w suffixes.

Differential Revision: https://reviews.llvm.org/D139948
2022-12-22 14:19:26 -08:00
Nikita Popov
8e451cda38 [RISCV] Convert test to opaque pointers (NFC)
There is a minor change in operand order (of a commutative
instruction).
2022-12-22 15:55:53 +01:00
Nikita Popov
866c84a973 [RISCV] Convert some tests to opaque pointers (NFC)
The asm test has minor differences in instruction scheduling only.
2022-12-22 15:50:22 +01:00
Nikita Popov
4794a168d4 [RISCV] Name instructions in tests (NFC) 2022-12-22 14:31:01 +01:00
Craig Topper
ae4da1f64e [RISCV] Add more abs+zext test cases. NFC 2022-12-21 22:13:06 -08:00
Craig Topper
9fdf21f3d0 [RISCV] Add test cases for i8/i16 abs followed by zext.
The andi, zext.h and slli+srli shift pairs at the end of the generated
output are unnecessary if the input is sign extended.
2022-12-21 12:26:01 -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
Craig Topper
51315d8dee [RISCV] Add more test cases to select.ll. NFC
These are test for select (and (x , 0x1) == 0), (z ^ y), y ) and select (and (x , 0x1) == 0), (z | y), y )

These can be made branchless by using ((x-1) & z ) ^ y.
2022-12-21 10:38:12 -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
Elena Lepilkina
ea21fa3a59 [Precommit][RISCV] Test folding for RISCVISD::BR_CC node
Precommit test for https://reviews.llvm.org/D140206
2022-12-21 14:19:49 +03:00
LiDongjin
180397cdde [RISCV] Enable the LocalStackSlotAllocation pass support.
Differential Revision: https://reviews.llvm.org/D98101

Co-authored-by: luxufan <luxufan@iscas.ac.cn>
2022-12-21 16:45:51 +08:00
Craig Topper
88793a0478 [RISCV] Add XVentanaCondOps to RISCVSExtWRemoval. 2022-12-20 18:46:45 -08:00
Craig Topper
7f9dc7bf85 [RISCV] Add more XVentanaCondOps tests with icmp conditions. NFC
Most of our existing tests use i1 arguments for the conditions.
With icmp conditions there are opportunities for improving the
generated code.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D140403
2022-12-20 11:36:28 -08:00
Craig Topper
4a2e7da3ce [RISCV] Teach RISCVMergeBaseOffset to handle constant pools.
Primarily this allows us to fold the addi from PseudoLLA expansion
into a load.

If the linker is able to GP relax the constant pool access we'll
end up with a GP relative load.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D140341
2022-12-20 07:16:43 -08:00
Craig Topper
90cb5f2fc8 [RISCV] Add +xventanacondops command line to select-binop-identity.ll. NFC 2022-12-19 19:12:39 -08:00
Craig Topper
aa4252ec6f [RISCV] Add zeroext attribute to i1 arguments in xventanacondops.ll. NFC
Removes some extra andi instructions.
2022-12-19 19:12:38 -08:00