52796 Commits

Author SHA1 Message Date
Zi Xuan Wu (Zeson)
d90468d161 [CSKY] Add support for half-precision floats
Complete fp16 support by ensuring that load extension / truncate store operations are properly expanded.
2023-06-14 15:03:07 +08:00
Wang Rui
06cdc6f9ce [LoongArch] Ignore warnings when there is no environment in triple
In Rust bare-metal targets, there is no environment component in triple name. This patch ignores warnings that look like:

```
warning: triple-implied ABI conflicts with provided target-abi ‘lp64s', using target-abi
```

Reviewed By: SixWeining, xen0n

Differential Revision: https://reviews.llvm.org/D152778
2023-06-14 13:23:54 +08:00
Craig Topper
f9d0bf0631 Revert "[RISCV] Fold binary op into select if profitable."
This reverts commit d0189584631e587279ee5f0af5feb94d8045bb31.

Build failures have been reported in the Linux kernel.
2023-06-13 18:17:36 -07:00
Philip Reames
d8562e27e0 [RISCV] Canonicalize towards vmerge w/passthrough representation
This is the first patch in a series to change how we represent tail agnostic, tail undefined, and tail undisturbed operations. In current code, we tend to use an unsuffixed pseudo for undefined (despite calling it TA most places in code), and the _TU form for both agnostic and undisturbed (via the policy operand).

The key observation behind this patch is that we can represent tail undefined via a pseudo with a passthrough operand if that operand is IMPLICIT_DEF (aka undef). We already have a few instances of this in tree - see vmv.s.x and vslide* - but we can do this more universally. Once complete, we will be able to delete roughly ~1/3 of our vector pseudo classes.

A bit more information on the overall goal can be found in this discourse post: https://discourse.llvm.org/t/riscv-transition-in-vector-pseudo-structure-policy-variants/71295.

This patch doesn't actually remove the legacy unsuffixed pseudo as there's still some path from intrinsic lowering which uses it. (I have not yet located it.) This also means we don't have to modify any of the lookup tables which makes the migration simpler. We can defer deleting the tables and pseudos until one final change once all the instructions have been migrated.

There are a couple of regressions in the tests. At first, these concerned me, but it turns out that all of them are differences in expansion of a single source level instruction. I think we can safely ignore this for the moment. I did explore changing the handling of IMPLICIT_DEF in ScheduleDAG, but that causes an absolutely *massive* test diff with minimal profit. I really don't think it's worth doing.

Differential Revision: https://reviews.llvm.org/D152380
2023-06-13 16:26:37 -07:00
Craig Topper
a5cd198181 [SelectionDAG] Don't allow type legalization to create noop VP_TRUNCATE.
Type legalization may need to promote the result to the same type
as the input. Instead of forming a vp_truncate with the same
source and dest type, don't create any vp_truncate.

Handling in getNode like is done for ISD::TRUNCATE.
2023-06-13 12:51:24 -07:00
Craig Topper
2f2af2d017 [RISCV] Change the immediate argument to Zk* intrinsics/builtins from i8 to i32.
This matches gcc. It also lets us fix a bug that the byteselect
predicate was not being evaluated in tablegen. We can't have i8
TImmLeaf in tablegen because i8 isn't a type for any register class.

I've added AutoUpgrade support for the IR intrinsics.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D152627
2023-06-13 10:39:43 -07:00
Craig Topper
445ec58f5f [RISCV] Add support for llvm.prefetch to use Zicbop instructions.
Reviewed By: asb, reames

Differential Revision: https://reviews.llvm.org/D152723
2023-06-13 09:51:30 -07:00
Anna Thomas
26bfbec5d2 [Intrinsic] Introduce reduction intrinsics for minimum/maximum
This patch introduces the reduction intrinsic for floating point minimum
and maximum which has the same semantics (for NaN and signed zero) as
llvm.minimum and llvm.maximum.

Reviewed-By: nikic

Differential Revision: https://reviews.llvm.org/D152370
2023-06-13 12:29:58 -04:00
Jingu Kang
16daaf0887 [AArch64] Try to combine MULL with uzp1.
For example,

 smull(trunc(x), extract_high(y))
 ==>
 smull(extract_high(uzp1(undef,x)), extract_high(y))

 -> It will be matched to smull2

Differential Revision: https://reviews.llvm.org/D150969
2023-06-13 14:34:12 +01:00
Simon Pilgrim
834cc88c5d [X86] X86FixupVectorConstantsPass - attempt to replace full width fp vector constant loads with broadcasts on AVX+ targets (REAPPLIED)
lowerBuildVectorAsBroadcast will not broadcast splat constants in all cases, resulting in a lot of situations where a full width vector load that has failed to fold but is loading splat constant values could use a broadcast load instruction just as cheaply, and save constant pool space.

NOTE: SSE3 targets can use MOVDDUP but not all SSE era CPUs can perform this as cheaply as a vector load, we will need to add scheduler model checks if we want to pursue this.

This is an updated commit of 98061013e01207444cfd3980cde17b5e75764fbe after being reverted at a279a09ab9524d1d74ef29b34618102d4b202e2f
2023-06-13 12:10:11 +01:00
David Green
16c4de1ffc [AArch64][SVE] Extra patterns for predicated and/or/xor
Similar to the other patterns, this adds predicated and/xor/xor patterns.

Differential Revision: https://reviews.llvm.org/D151086
2023-06-13 11:21:18 +01:00
Simon Pilgrim
e61bb1e541 MachineConstantPool::getConstantPoolIndex - don't reuse mismatched constants contained undef/poison (Issue #63108)
This patch fixes an issue where we were reusing constant pool entries that contained undef elements, despite the additional uses of the 'equivalent constant' requiring some/all of the elements to be zero.

The CanShareConstantPoolEntry helper function uses ConstantFoldCastOperand to bitcast the type mismatching constants to integer representations to allow comparison, but unfortunately this treats undef elements as zero (which they will be written out as in the final asm). This caused an issue where the original constant pool entry contained undef elements, which was shared with a later constant that required the elements to be zero. This then caused a later analysis pass to incorrectly discard these undef elements.

Ideally we need a more thorough analysis/merging of the constant pool entries so the elements are forced to real zero elements, but for now we just prevent reuse of the constant pool entry entirely if the constants don't have matching undef/poison elements.

Fixes #63108

Differential Revision: https://reviews.llvm.org/D152357
2023-06-13 10:40:24 +01:00
Simon Pilgrim
35def3034f [GlobalIsel][X86] Regenerate legalize-phi.mir 2023-06-13 10:40:23 +01:00
Amaury Séchet
a70d5e25f3 [DAGCombine] Make sure combined nodes are added back to the worklist in topological order.
Currently, a node and its users are added back to the worklist in reverse topological order after it is combined. This diff changes that order to be topological. This is part of a larger migration to get the DAGCombiner to process nodes in topological order.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D127115
2023-06-13 09:14:37 +00:00
Matt Arsenault
d0923a7739 AMDGPU: Correct constants used in fast math log expansion
The division between float constants was done with less
precision. Performing the divide in double and truncating to float
provides the same value as used in the library fast math expansion.
2023-06-12 21:11:41 -04:00
Matt Arsenault
1f615b502c AMDGPU: Modernize log codegen tests 2023-06-12 21:11:36 -04:00
Matt Arsenault
eccc89b26c AMDGPU: Add llvm.amdgcn.log intrinsic
This will map directly to the hardware instruction which does not
handle denormals for f32. This will allow moving the generic intrinsic
to be lowered correctly. Also handles selecting the f16 version, but
there's no reason to use it over the generic intrinsic.
2023-06-12 21:10:30 -04:00
Matt Arsenault
ee19fabc98 LowerMemIntrinsics: Handle inserting addrspacecast for memmove lowering
We're missing a trivial non-AA way to check for non-aliasing address
spaces.
2023-06-12 21:10:30 -04:00
Eric Gouriou
c5a88fe3d0 [RISC-V] Zvk update to 0.9.7, Zvknc/Zvksc
Update the RISC-V Zvk (vector cryptography) extension support from 0.5
to version 0.9.7 (2023-05-31), per
    <https://github.com/riscv/riscv-crypto/releases/download/v20230531/riscv-crypto-spec-vector.pdf>

Differences:
     - Zvbc is dropped from Zvkn and Zvks, and by extension
       from Zvkng and Zvksg;
     - new combo extensions Zvknc and Zvksc are introduced,
      adding Zvbc to Zvkn and Zvks;
     - the experimentatl extensions are tagged as "0.9",
       from the earlier "0.5".

Reviewed By: 4vtomat

Differential Revision: https://reviews.llvm.org/D152117
2023-06-12 15:43:08 -07:00
Luke Lau
a84994071c [RISCV] Use TU vmv.v.v instead of vslideup.vi N,M,0 for insert vector_shuffles
This applies the same technique in https://reviews.llvm.org/D152565 to
vslideups when lowering vector_shuffles that have an insert pattern in
their mask.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D152724
2023-06-12 21:08:49 +01:00
Noah Goldstein
5c8188c7bc [DAGCombine] Use IsKnownNeverZero to see if we need zero-check in is_pow2 setcc patern
`ctpop(X) eq/ne 1` is checking if X is a non-zero power of 2. Power of
2 check including zero is `(X & (X-1)) eq/ne 0` and unfortunately
there is no good pattern for checking a power of 2 while excluding
zero. So, when lowering `ctpop(X) eq/ne 1`, explicitly check
`IsKnownNeverZero(X)` to maybe be able to optimize out the extra zero
check.

We need this explicitly as DAGCombiner does not re-analyze provable
setcc nodes, and the middle-end never finds it beneficially to broaden
`ctpop(X) eq/ne 1` -> `ctpop(X) ule/ugt 1` (power of 2 including
zero).

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D152675
2023-06-12 13:52:43 -05:00
Noah Goldstein
4e2b532cb9 [X86] Add tests for optimizing out zero-check in is_pow2 setcc pattern; NFC
Differential Revision: https://reviews.llvm.org/D152674
2023-06-12 13:52:43 -05:00
Mikhail Gudim
d018958463 [RISCV] Fold binary op into select if profitable.
Consider the following pattern `binOp (select cond, x, c0), c1`.
Where `c0` and `c1` are constants.
We can transform it to `select cond, binOp(x, c1), binOp(c0, c1)`.

If `binOp(c0, c1)` ends up being `0` or `-1` we can turn the select into
a more profitable sequence.
2023-06-12 14:19:12 -04:00
Craig Topper
c5fdab3014 [RISCV] Use tail undisturbed vmv.v.v instead of vadd.vi with 0 for vp.merge with all ones mask.
No idea what I was thinking when I suggested vadd.vi.

Reviewed By: reames, frasercrmck, fakepaper56

Differential Revision: https://reviews.llvm.org/D152553
2023-06-12 10:27:08 -07:00
Craig Topper
17e2d07ad1 [RISCV] Use tail undisturbed vmv.v.v instead of vslideup.vi vN, vM, 0 for subvector insertion
vslideup has a vector overlap constraint that vmv.v.v doesn't.
vmv.v.v is also a simpler instruction so may have better
throughput and/or latency in some CPUs.

This is an alternative to D152298, D152368, and D152496.

Reviewed By: luke, reames

Differential Revision: https://reviews.llvm.org/D152565
2023-06-12 10:01:39 -07:00
Craig Topper
b418482f80 [RISCV] Don't use (ADD (SLLI C, 32), C) to materialize constants when optimizing for size.
Addresses post-commit feedback from D152236.

Reviewed By: asb, dtcxzyw

Differential Revision: https://reviews.llvm.org/D152602
2023-06-12 09:52:35 -07:00
Anna Thomas
b2195bc771 [SelectionDAG][AArch64] Legalize FMAXIMUM/FMINIMUM
The missing legalization in SelectionDAG was identified when adding the
intrinsic support for vector reduction for maximum/minimum (D152370).

Fixes part of PR: https://github.com/llvm/llvm-project/issues/63267

Differential Revision: https://reviews.llvm.org/D152718
2023-06-12 12:22:21 -04:00
Kazu Hirata
9eea63bc9c [AMDGPU] Fix resource-usage-pal.ll 2023-06-12 08:06:46 -07:00
Baptiste
3604fdf18d [AMDGPU] Do not assume stack size for PAL code object indirect calls
There is no need to set a big default stack size for PAL code object indirect
calls. The driver knows the max recursion depth, so it can compute a more
accurate value from the minimum scratch size.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D150609
2023-06-12 10:14:17 -04:00
Ivan Kosarev
d09fa8ff2c [AMDGPU][GFX11] Add test coverage for cases involving conversions from and to fp16 values.
Other such tests, of which there are many, are to be updated with
separate patches.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D152557
2023-06-12 13:04:40 +01:00
Francesco Petrogalli
45902a25fa [MISched] Require asserts and AArch64 registered target for test.
Fixes failure at https://lab.llvm.org/buildbot/#/builders/124/builds/7472:

```
llc: Unknown command line argument '-debug-only=machine-scheduler'. Try: '/home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/bin/llc --help'
```

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D152703
2023-06-12 13:51:19 +02:00
Simon Pilgrim
3d34f7be73 [GlobalIsel][X86] Rename x86_64-select-fcmp.mir to select-fcmp.mir and add 32-bit test coverage
x86_64 was being used as shorthand for SSE2
2023-06-12 12:41:27 +01:00
Simon Pilgrim
22c17c6a1f [GlobalIsel][X86] Move G_FCMP getActionDefinitionsBuilder out of setLegalizerInfo64bit and add 32-bit support
We were using x86_64-only support as a SSE2 proxy
2023-06-12 12:18:37 +01:00
Simon Pilgrim
6a12ab874a [GlobalIsel][X86] Regenerate legalize-fcmp.mir 2023-06-12 12:18:36 +01:00
Simon Pilgrim
1a576aa09d [GlobalIsel][X86] Rename x86_64-legalize-fcmp to legalize-fcmp
32-bit support will be added shortly - x86_64 was being used a shorthand for SSE2
2023-06-12 12:18:36 +01:00
Luke Lau
2a1716dec5 [LegalizeTypes][VP] Widen load/store of fixed length vectors to VP ops
If we have a load/store with an illegal fixed length vector result type that
needs widened, e.g. `x:v6i32 = load p`
Instead of just widening it to: `x:v8i32 = load p`
We can widen it to the equivalent VP operation and set the EVL to the
exact number of elements needed: `x:v8i32 = vp_load a, b, mask=true, evl=6`
Provided that the target supports vp_load/vp_store on the widened type.

Scalable vectors are already widened this way where possible, so this
largely reuses the same logic.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D148713
2023-06-12 10:21:04 +01:00
Francesco Petrogalli
15a16ef8e0 [MISched] Use StartAtCycle in trace dumps.
This commit re-work the methods that dump traces with resource usage to take into account the StartAtCycle value added by https://reviews.llvm.org/D150310.

For each i, the values of the lists StartAtCycle and ReservedCycles is  are printed with the interval [StartAtCycle[i], ReservedCycles[i])

```
... | StartAtCycle[i] | ... | ReservedCycles[i] - 1 | ReservedCycles[i] | ...
    | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |                   |
```

Reviewed By: andreadb

Differential Revision: https://reviews.llvm.org/D150311
2023-06-12 09:11:48 +02:00
Fangrui Song
849f1dd15e [XRay] Rename XRayOmitFunctionIndex to XRayFunctionIndex
Apply my post-commit comment on D81995. The negative name misguided commit
d8a8e5d6240a1db809cd95106910358e69bbf299 (`[clang][cli] Remove marshalling from
Opt{In,Out}FFlag`) to:

* accidentally flip the option to not emit the xray_fn_idx section.
* change -fno-xray-function-index (instead of -fxray-function-index) to emit xray_fn_idx

This patch renames XRayOmitFunctionIndex and makes -fxray-function-index emit
xray_fn_idx, but the default remains -fno-xray-function-index .
2023-06-11 15:27:22 -07:00
Oleksii Lozovskyi
c72dea88b6 [AArch64][ARM][X86] Split XRay tests for Linux/macOS
XRay instrumentation works for macOS running on Apple Silicon, but
codegen is untested there. I'm going to make changes affecting this
target, get the XRay tests running on AArch64.

Data sections are going to become slightly different on x86_64 soon.
I do want the tests to be specific about symbol names, so instead of
having test check the common step, bifurcate tests a bit and check
the full symbol names.

As for ARM, XRay is not really supported on iOS at the moment, though
ARM is also really used there with modern phones. Nevertheless, codegen
tests exist and the output is going to change a little, make it easier
to write the special case for iOS.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D145291
2023-06-11 12:53:29 -07:00
Simon Pilgrim
26706807c9 [GlobalIsel][X86] Ensure bit count legalizer patterns keep matching result + input scalar types 2023-06-11 18:56:28 +01:00
Ben Shi
71d90f3108 [AVR] Optimize 8-bit rotation when rotation bits == 3
Fixes https://github.com/llvm/llvm-project/issues/63100

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D152365
2023-06-11 08:41:47 +08:00
Ben Shi
e21df8296d [AVR] Optimize 8-bit rotation when rotation bits >= 4
Fixes https://github.com/llvm/llvm-project/issues/63100

Reviewed By: aykevl, Patryk27, jacquesguan

Differential Revision: https://reviews.llvm.org/D152130
2023-06-11 08:36:22 +08:00
Noah Goldstein
b6808ba291 [X86] Make constant mul -> shl + add/sub work for vector types
Something like:
    `%r = mul %x, <33, 33, 33, ...>`

Is best lowered as:
    `%tmp = %shl x, <5, 5, 5>; %r = add %tmp, %x`

As well, since vectors have non-destructive shifts, we can also do
cases where the multiply constant is `Pow2A +/- Pow2B` for arbitrary A
and B, unlike in the scalar case where the extra `mov` instructions
make it not worth it.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D150324
2023-06-10 14:38:46 -05:00
Matt Arsenault
6d2e5c3445 LowerMemIntrinsics: Skip memmove with different address spaces
This is a quick fix for an assert when the source and dest have
different address spaces. The pointer compare needs to have matching
types, but we can't generically introduce addrspacecast and we don't
know if the address spaces alias.
2023-06-10 12:28:05 -04:00
Ben Shi
f3837e726f [AVR] Fix incorrect expansion of pseudo instruction ROLBRd
Since ROLBRd needs an implicit R1 (on AVR) or an implicit R17 (on AVRTiny),
we split ROLBRd to ROLBRdR1 (on AVR) and ROLBRdR17 (on AVRTiny).

Reviewed By: aykevl, Patryk27

Differential Revision: https://reviews.llvm.org/D152248
2023-06-11 00:20:43 +08:00
Ben Shi
cef723a0fe [AVR] Enable sub register liveness
Reviewed By: Patryk27

Differential Revision: https://reviews.llvm.org/D152606
2023-06-11 00:16:35 +08:00
Ben Shi
3b8c12c18e [AVR][NFC] Improve CodeGen tests
Reviewed By: Patryk27

Differential Revision: https://reviews.llvm.org/D152605
2023-06-11 00:15:20 +08:00
Matt Arsenault
abff7668ab AMDGPU: Implement known bits functions for min3/max3/med3 2023-06-10 10:58:44 -04:00
Matt Arsenault
f24de950e5 AMDGPU: Add baseline tests for known bits handling of med3 2023-06-10 10:58:39 -04:00
Matt Arsenault
5b657f50b8 AMDGPU: Move LICM after AMDGPUCodeGenPrepare
The commit that added the run says it's to hoist uniform parts of
integer division expansion. That expansion is performed later, so this
didn't do anything in that case. Move this later so the original test
shows the improvement.

This also saves a run of "Canonicalize natural loops". Not sure why
this appears to be still getting a separate loop PM run. Also feels a
bit heavy to run this just for divide. Is there a way to specifically
hoist the divide sequence when it expands?
2023-06-10 07:37:32 -04:00