2759 Commits

Author SHA1 Message Date
Philip Reames
9cf675923a [RISCVRVVInitUndef] Remove implicit single use assumption for IMPLICIT_DEF
The code was written with the implicit assumption that each IMPLICIT_DEF either a) the tied operand, or b) an untied source, but not both. This is true right now, but an upcoming change may allow CSE of IMPLICIT_DEFs in some cases, so let's rewrite the code to handle that possibility.

I added an MIR case which demonstrates the multiple use IMPLICIT_DEF. To my knowledge, this is not a reachable configuration from IR right now.

As an aside, this makes the structure a much closer match with the sub-reg liveness case, and we can probably just merge these routines. (Future work.)

Differential Revision: https://reviews.llvm.org/D156477
2023-07-27 16:25:56 -07:00
Craig Topper
a81e1f0fb2 [RISCV] When using vror.vi for left rotate, mask the inverted immediate to SEW.
This makes the assembly more readable.

Reviewed By: luke

Differential Revision: https://reviews.llvm.org/D156348
2023-07-27 12:16:21 -07:00
Nitin John Raj
474cf4feb7 [RISCV][GlobalISel] Test legalization of binary logical instructions with wider types
Without any additional tweaking, we can successfully legalize for wider
types (i64, i96 for rv32; i128, i192 for rv64) that are integer
multiples of XLen.

Reviewed By: arsenm, craig.topper

Differential Revision: https://reviews.llvm.org/D155639
2023-07-26 15:37:13 -07:00
Luke Lau
33a93a41df [RISCV] Add SDNode patterns for vwsll.[vv,vx,vi]
This reuses the patterns introduced to help lower vnsr[a,l].vx in D155698.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155936
2023-07-26 20:26:35 +01:00
Luke Lau
ce8f094da8 [RISCV] Add patterns for vnsrl.vx where shift amount is truncated
Similar to D155698 where the shift amount is extended, this patch extends the
ComplexPattern to handle the case where the shift amount has been truncated.
Truncations are custom lowered to truncate_vector_vl, and in cases like i64 ->
i16 they are truncated by one power of two at a time, so we need to unravel
nested layers of them.

The pattern can also be reused for Zvbb's vwsll.vx in an upcoming patch.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155928
2023-07-26 20:26:32 +01:00
Luke Lau
7c652feb95 [RISCV] Add tests for vnsrl.vx where shift amount is truncated
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155927
2023-07-26 20:26:27 +01:00
Craig Topper
e28307e93a [RISCV] Handle seteq/setne conditions for CZERO_NEZ/CZERO_EQZ during isel.
This removes selectSETCC and adds isel patterns for seteq/setne
conditions.

This removes the duplication of selectSETCC between lowering and
isel. This also gets some cases in xaluo.ll that we missed previously.

Reviewed By: wangpc

Differential Revision: https://reviews.llvm.org/D156250
2023-07-26 10:06:08 -07:00
Kevin P. Neal
5ad2760ad9 [FPEnv][RISC-V] Correct a strictfp test.
Correct a RISC-V strictfp tests to follow the rules documented in the LangRef:
https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics

All function calls in a strictfp function require the strictfp attribute.

Test changes verified with D146845.
2023-07-26 09:10:19 -04:00
Jim Lin
2f726c22ce [RISCV] Merge rv32/rv64 vector slideup and slidedown intrinsic tests that have the same content. NFC. 2023-07-26 13:13:55 +08:00
Craig Topper
f6dc75cdd8 [RISCV] Add DAG combine to pull xor with 1 through select idiom that uses czero_eqz/nez.
If we are selecting between two setccs that need to be legalized
with xor, the select will be legalized first. Detect this pattern
so we can pull the xor through to expose it to additional
optimizations.

We could generalize this to other operations, but those normally
get handled in DAG combine before select legalization.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D156159
2023-07-25 09:13:24 -07:00
Craig Topper
b34a8b3a52 [RISCV] Generalize combineAddOfBooleanXor to support any boolean not just setcc.
Instead of checking for setcc, look for any 0/1 value.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D156153
2023-07-25 09:04:49 -07:00
Craig Topper
5ff5dac852 [RISCV] Add simple DAG combine to pull xor with 1 through select_cc.
If we're selecting the result of two setccs that have been legalized
by introducing an xor with 1, we can pull the xor with 1 through the
select to enable more optimizations.

We could generalize this to other binary operators with identical
conditions, but those are usually caught before we legalize the select.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D156144
2023-07-25 09:03:45 -07:00
Jim Lin
4eff7fae60 [RISCV] Merge rv32/rv64 vector narrowing integer right shift intrinsic tests that have the same content. NFC. 2023-07-25 16:09:21 +08:00
LiaoChunyu
620e61c518 [RISCV] Match ext_vl+sra_vl/srl_vl+trunc_vector_vl to vnsra.wv/vnsrl.wv
similar to D117454, try to add vl patterns and testcases.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155466
2023-07-25 14:21:02 +08:00
Craig Topper
49429783b0 [RISCV] Add lowering for scalar fmaximum/fminimum.
Unlike fmaxnum and fminnum, these operations propagate nan and
consider -0.0 to be less than +0.0.

Without Zfa, we don't have a single instruction for this. The
lowering I've used forces the other input to nan if one input
is a nan. If both inputs are nan, they get swapped. Then use
the fmax or fmin instruction.

New ISD nodes are needed because fmaxnum/fminnum to not define
the order of -0.0 and +0.0.

This lowering ensures the snans are quieted though that is probably not
required in default environment). Also ensures non-canonical nans
are canonicalized, though I'm also not sure that's needed.

Another option could be to use fmax/fmin and then overwrite the
result based on the inputs being nan, but I'm not sure we can do
that with any less code.

Future work will handle nonans FMF, and handling the case where
we can prove the input isn't nan.

This does fix the crash in #64022, but we need to do more work
to avoid scalarization.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D156069
2023-07-24 13:46:35 -07:00
Philip Reames
a6cd1f623d [RISCV] Adjust memcpy lowering test coverage w/V
This is fixing a mistake in 4f4f49137.
2023-07-24 12:32:17 -07:00
Philip Reames
4f4f491375 [RISCV] Add memcpy lowering test coverage with and without V 2023-07-24 12:25:09 -07:00
Craig Topper
5990199e2c [RISCV] Add CZERO_EQZ/CZERO_NEZ to ComputeNumSignBitsForTargetNode.
Reviewed By: wangpc

Differential Revision: https://reviews.llvm.org/D156082
2023-07-24 07:43:02 -07:00
Craig Topper
82686d7d55 [RISCV] Add test case for D156082 to condops.ll
This test is copied from select-cc.ll. It wasn't worth adding
Zicond RUN lines to that file.

Reviewed By: asb, wangpc

Differential Revision: https://reviews.llvm.org/D156083
2023-07-24 07:42:46 -07:00
Craig Topper
9da0db4dd8 [RISCV] Add CZERO_EQZ/CZERO_NEZ to computeKnownBitsForTargetNode.
Reviewed By: wangpc

Differential Revision: https://reviews.llvm.org/D156081
2023-07-24 07:38:12 -07:00
Luke Lau
5b95bba6fe [RISCV] Set Fast flag for unaligned memory accesses
The +unaligned-scalar-mem and +unaligned-vector-mem features were added in
D126085 and D149375 respectively to allow subtargets to indicate that
they supported misaligned loads/stores with "sufficient" performance.
This is separate from whether or not the target actually supports
misaligned accesses, which could be determined from Zicclsm.

This patch enables the Fast flag under the assumption that any subtarget
that declares support for +unaligned-*-mem will want to opt into
optimisations that take advantage of misaligned scalar accesses, such as
store merging.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D150771
2023-07-24 10:58:57 +01:00
WANG Rui
595d5f36f4 [DAGCombine] Canonicalize operands for visitANDLike
During the construction of SelectionDAG, there are no explicit canonicalization rules to adjust the order of operands for AND nodes.  This may prevent the optimization in DAGCombiner::visitANDLike from being triggered. This patch canonicalizes the operands before matches, which can be observed to improve optimization on the RISC-V target architecture.

Canonicalize:
```
and(x, add) -> and(add, x)
```

Signed-off-by: WANG Rui <wangrui@loongson.cn>

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D154760
2023-07-24 16:52:04 +08:00
WANG Rui
cea980f380 [RISCV] Add tests for (and (add x, c1), (lshr y, c2))
Add tests for (and (add x, c1), (lshr y, c2)).

Signed-off-by: WANG Rui <wangrui@loongson.cn>

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154808
2023-07-24 16:52:02 +08:00
Craig Topper
74d16b212b [RISCV] Add Zicond RUN lines to xaluo.ll. NFC
A couple of these tests show a need for computeKnownBits support
for Zicond.
2023-07-23 23:03:18 -07:00
Jim Lin
37b474a20e [RISCV] Remove unused check prefixes for tests. NFC
Also remove the warning line for that these prefixes are unused.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D156048
2023-07-24 13:42:49 +08:00
eopXD
78d91df452 [RISCV] Support register allocation for GHC when f/d is not specified in the architecture
This patch supports register allocation for floating-point types when
`zfinx` and `zdinx` is specified in the architecture for the GHC
calling convention.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155910
2023-07-23 22:40:10 -07:00
Jun Sha (Joshua)
f375ee36c4 [RISCV] Add codegen for Zfbfmin instructions
The implementation in https://reviews.llvm.org/D151313 is done for the circumstance without Zfbfmin. This patch adds codegen support for the 6 instructions provided in Zfbfmin extension.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D153234
2023-07-24 10:37:58 +08:00
Philip Reames
785939c15e Revert "[RISCV] Add test which shows alignment of constant pools and the functions which followed"
This reverts commit cbf2a6ce197e8176c01316fe25400aae0b7390c4.  This was a precommited test for a change which is being abandoned.
2023-07-21 16:03:15 -07:00
Philip Reames
cbf2a6ce19 [RISCV] Add test which shows alignment of constant pools and the functions which followed 2023-07-21 15:02:43 -07:00
Fangrui Song
ffa829c4c5 [RISCV] Allow delayed decision for ADD/SUB relocations
For a label difference `A-B` in assembly, if A and B are separated by a
linker-relaxable instruction, we should emit a pair of ADD/SUB
relocations (e.g. R_RISCV_ADD32/R_RISCV_SUB32,
R_RISCV_ADD64/R_RISCV_SUB64).

However, the decision is made upfront at parsing time with inadequate
heuristics (`requiresFixup`). As a result, LLVM integrated assembler
incorrectly suppresses R_RISCV_ADD32/R_RISCV_SUB32 for the following
code:
```
// Simplified from a workaround https://android-review.googlesource.com/c/platform/art/+/2619609
// Both end and begin are not defined yet. We decide ADD/SUB relocations upfront and don't know they will be needed.
.4byte end-begin

begin:
  call foo
end:
```

To fix the bug, make two primary changes:

* Delete `requiresFixups` and the overridden emitValueImpl (from D103539).
  This deletion requires accurate evaluateAsAbolute (D153097).
* In MCAssembler::evaluateFixup, call handleAddSubRelocations to emit
  ADD/SUB relocations.

However, there is a remaining issue in
MCExpr.cpp:AttemptToFoldSymbolOffsetDifference. With MCAsmLayout, we may
incorrectly fold A-B even when A and B are separated by a
linker-relaxable instruction. This deficiency is acknowledged (see
D153097), but was previously bypassed by eagerly emitting ADD/SUB using
`requiresFixups`. To address this, we partially reintroduce `canFold` (from
D61584, removed by D103539).

Some expressions (e.g. .size and .fill) need to take the `MCAsmLayout`
code path in AttemptToFoldSymbolOffsetDifference, avoiding relocations
(weird, but matching GNU assembler and needed to match user
expectation). Switch to evaluateKnownAbsolute to leverage the `InSet`
condition.

As a bonus, this change allows for the removal of some relocations for
the FDE `address_range` field in the .eh_frame section.

riscv64-64b-pcrel.s contains the main test.
Add a linker relaxable instruction to dwarf-riscv-relocs.ll to test what
it intends to test.
Merge fixups-relax-diff.ll into fixups-diff.ll.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D155357
2023-07-21 08:37:58 -07:00
Simon Pilgrim
ae60706da0 [DAG] SimplifyDemandedBits - call ComputeKnownBits for constant non-uniform ISD::SRL shift amounts
We only attempted to determine KnownBits for uniform constant shift amounts, but ComputeKnownBits is able to handle some non-uniform cases as well that we can use as a fallback.
2023-07-21 14:52:57 +01:00
Luke Lau
33a83c5486 [RISCV] Add SDNode patterns for vrol.[vv,vx] and vror.[vv,vx,vi]
These correspond to ROTL/ROTR nodes

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155439
2023-07-21 10:22:46 +01:00
Luke Lau
24628a14c4 [RISCV] Add patterns for vnsr[a,l].wx where shift amount has different type than vector element
We're currently only matching scalar shift amounts where the type is the same
as the vector element type. But because only the bottom log2(2*SEW) bits are
used, only 7 bits will be used at most so we can use any scalar type >= i8.

This patch adds patterns for the case above, as well as for when the shift
amount type is the same as the widened element type and doesn't need extended.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155698
2023-07-21 10:13:28 +01:00
Luke Lau
418e678ba3 [RISCV] Add tests for vnsr[l,a].wx patterns that could be matched
These patterns of ([l,a]shr v, ([s,z]ext splat)) only pick up the cases where
the scalar has the same type as the vector element. However since only the low
log2(SEW) bits of the scalar are read, we could use any scalar type that has
been extended.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155697
2023-07-21 10:13:26 +01:00
Piyou Chen
a70aa5ea7c [RISCV] precommit for removing useless copy from undef subreg
testcase from https://github.com/llvm/llvm-project/issues/63554

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D155039
2023-07-20 20:38:24 -07:00
Philip Reames
4f057f5296 [RISCV] Expand memset.inline test coverage [nfc]
Add coverage for unaligned overlap cases, and for vector stores.

Note that the vector memset here is coming from store combining, not memset lowering.
2023-07-20 17:37:36 -07:00
Philip Reames
34c01a6044 [RISCV] Add memset.inline test coverage with and without V [nfc] 2023-07-20 15:03:53 -07:00
Philip Reames
eb3f2fe467 [RISCV] Revise check names for unaligned memory op tests [nfc]
This has come up a few times in review; the current ones seem to be universally confusing.  Even I as the original author of most of these get confused.  Switch to using the SLOW/FAST naming used by x86, hopefully that's a bit clearer.
2023-07-20 13:36:53 -07:00
Kevin P. Neal
95c2d01dfe [FPEnv][RISCV] Correct strictfp tests.
Correct RISC-V strictfp tests to follow the rules documented in the LangRef:
https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics

Mostly these tests just needed the strictfp attribute on function definitions.
I've also removed the strictfp attribute from uses of the constrained
intrinsics because it comes by default since D154991, but I only did this
in tests I was changing anyway.

Test changes verified with D146845.
2023-07-20 10:16:56 -04:00
Fangrui Song
82b4368f7f [llvm-readobj] Print <null> for relocation target with an empty name
For a relocation, we don't differentiate the two cases:

* the symbol index is 0
* the symbol index is non zero, the type is not STT_SECTION, and the name is empty. Clang generates such local symbols for RISC-V linker relaxation.

So we may print
```
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 0

// llvm-readobj
0x1C R_RISCV_32_PCREL - 0x0
```

while GNU readelf prints "<null>", which is clearer. Let's match the GNU behavior.
Related to https://reviews.llvm.org/D81842

```
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 <null> + 0

// llvm-readobj
0x1C R_RISCV_32_PCREL <null> 0x0
```

Reviewed By: jhenderson, kito-cheng

Differential Revision: https://reviews.llvm.org/D155353
2023-07-20 00:42:38 -07:00
Craig Topper
7dfe62327d [RISCV] Add a DAG combine for (czero_eq X, (xor Y, 1)) -> (czero_ne X, Y) if Y is 0 or 1.
This is an alternative to D155288 that can handle other sources of
xori like FP compares. Unfortunately, it misses the i64 setge case
on RV32 in condops.ll.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D155328
2023-07-19 12:33:08 -07:00
Craig Topper
3055c5815a [RISCV] Upgrade Zvfh version to 1.0 and move out of experimental state.
This has been ratified according to https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions

Differential Revision: https://reviews.llvm.org/D155668
2023-07-19 10:03:57 -07:00
Luke Lau
efedcbeeb8 [RISCV] Fold ops into vmv.v.v as vmerge with all-ones mask
A vmv.v.v shares the same encoding as a vmerge that isn't masked, so we can
also fold it into its operands if we treat it as a vmerge with an all-ones
mask.  We take care here not to actually transform the existing vmv into a
vmerge, otherwise things like True.hasOneUse() become inaccurate. Instead this
just returns an equivalent list of operands.
This is an alternative to D153351.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D155101
2023-07-19 17:24:42 +01:00
Luke Lau
0f277ab361 [RISCV] Fold vmerge into its ops with smaller VL if known
Currently when folding vmerge into its operands, we stop if the VLs aren't
identical.  However since the body of (vmerge (vop)) is the intersection of
vmerge and vop's bodies, we can use the smaller of the two VLs if we know it
ahead of time.  This patch relaxes the constraint on VL if they are both
constants, or if either of them are VLMAX.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D155071
2023-07-19 17:24:40 +01:00
Luke Lau
66dc29a82a [RISCV] Add tests for merges with differing VLs that could be folded
Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D155069
2023-07-19 17:24:38 +01:00
Djordje Todorovic
80e20c8a8d [RISCV] Add DAG combine for CTTZ/CTLZ in the case of input 0
Within the AggressiveInstCombine Pass we have
an analysis/optimization that matches that
pattern of the Table Based CTZ. Some Targets do
not support/define ctz(0), but since the
AggressiveInstCombine is just an extension of
InstCombine, it should be a target-independent
canonicalization Pass, and therefore, we decided
to introduce several instructions, such as select
and compare that produce canonical IR, even if
the input is 0. The task for the Targets that do
support that input is to handle such a case and
to produce an optimal assembly.

This patch optimizes the CTTZ/CTLZ instructions
if the input is 0 by performing the`DAG combine`,
by generating the cttz(x) & 0x1f pattern (the
same goes for ctlz as well).

Differential Revision: https://reviews.llvm.org/D151449
2023-07-19 16:22:04 +02:00
eopXD
32c257d384 [RISCV] Use the stack for MVT::f16 for fastcc when there are no other registers available
In D155502, we added code for the compiler to check GPR-s for f16
under zhinx. This commit adds code to hit the stack when we run out of
GPR-s.

With this patch and D155502, resolves #63922

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155507
2023-07-18 19:49:17 -07:00
Craig Topper
ea3683e98f [RISCV] Improve type promotion for i32 clmulr/clmulh on RV64.
Instead of zero extending the inputs by masking. We can shift them
left instead. This is cheaper when we don't zext.w instruction.

This does make the case where the inputs are already zero extended
or freely zero extendable worse though.

Reviewed By: wangpc

Differential Revision: https://reviews.llvm.org/D155530
2023-07-18 10:39:25 -07:00
Craig Topper
0c055286b2 [RISCV] Use RISCVISD::CZERO_EQZ/CZERO_NEZ for XVentanaCondOps.
This makes Zicond and XVentanaCondOps use the same code path.
The instructions have identical semantics.

Reviewed By: wangpc

Differential Revision: https://reviews.llvm.org/D155391
2023-07-18 10:18:02 -07:00
eopXD
ca72457346 [RISCV] Add test coverage for peephole vmerge optimization of unmasked rvv instruction with a rounding mode (NFC)
No functional change intended.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D155550
2023-07-18 10:03:58 -07:00