55755 Commits

Author SHA1 Message Date
David Green
b0b1a11305 [AArch64] Add libcall for fp128 pow/log/sin/cos/etc.
As with other operations, this adds libcall support for fp128 G_FPOW,
G_FLOG/G_FEXP/etc, and G_FSIN/G_FCOS/etc operations.
2024-10-03 08:03:47 +01:00
NAKAMURA Takumi
650c41aad2 Revert "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN (#110714)"
Some builders has been failing tests.
```
Failed Tests (2):
  LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-load-global-old-legalization.mir
  LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-load-local.mir
```

This reverts commit ae5bd2a9f292037c605b2ec0ee31200581bd8701.
(llvmorg-20-init-7805-gae5bd2a9f292)
2024-10-03 15:38:34 +09:00
Andrei Safronov
56736c7937
[Xtensa] Implement volatile load/store. (#110292)
Add a memory wait "MEMW" instruction before volatile load/store
operations, as implemented in GCC.
2024-10-03 08:35:27 +03:00
Luke Lau
d15e53c1e4
[RISCV] Check vmerge's true is in same block in vmerge -> vmv.v.v peephole (#110861)
The peepholes in RISCVVectorPeephole need to be local and we were
failing to check if the true operand was in the same block as the
vmerge.

Fixes #110832
2024-10-03 12:02:54 +08:00
Daniel Paoliello
db33d82026
[llvm] Mark win x64 SEH pseudo instruction as meta instructions (#110889)
When adding new SEH pseudo instructions in #110024 I noticed that some
of the tests were changing their output since these new instructions
were counting towards thresholds for branching versus folding decisions.

These instructions do not result in real machine instructions being
emitted, so they should be marked as meta instructions.
2024-10-02 16:52:04 -07:00
Keith Packard
ca57e8f23f
[RISCV] Support -mstack-protector-guard=tls (#108942)
Add support for using a thread-local variable with a specified offset
for holding the stack guard canary value.

Closes: #46685
2024-10-02 16:33:31 -07:00
Francis Visoiu Mistrih
916e6ad7d0
[CodeGen] Fix InstructionCount remarks for MI bundles (#107621)
For MI bundles, the instruction count remark doesn't count the
instructions inside the bundle.
2024-10-02 13:37:25 -07:00
Michael Maitland
40b8a0fd17
[RISCV][GISEL] Generate VLMax using -1 constant (#110778)
SelectionDAG uses ISD::REGISTER and uses RISCV::X0 to represent VLMAX.
Then in ComplexPattern VLOpt uses selectVLOp to convert RISCV::X0 to
RISCV::VLMaxSentinel.

The original legalization patch for G_SPLAT_VECTOR used Register
RISCV::X0 directly. $x0 has no LLT type, so GIComplexOperandMatcher has
no way of matching.

The approach we are changing to here will allow us to successfully use
GIComplexOperandMatcher to implement the ComplexMatcherFn selectVLOp in
GISEL since the operand now has a type.
2024-10-02 16:06:22 -04:00
Farzon Lotfi
7d0ca6019d
[NFC][DirectX] Remove DXILIntrinsicExpansion as a required pass of DXILOpLowering (#110750)
Updates tests and moves the code accordingly.
2024-10-02 15:55:40 -04:00
Krzysztof Drewniak
ae5bd2a9f2
[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN (#110714)
Certain pointer address spaces were not being correctly handled by the
GlobalISel lowering for buffer_load and buffer_store.

1. ptr addrspace(1) and addrspace(4) did not have rewrite patterns
defined for them, while p0 did, since those pointer types weren't in the
list of types that was iterated to form the patterns.
2. Vectors of pointers need to be bitcast to vectors of the
corresponding scalars, since there doesn't seem to be a good way to
define the rewrite patterns for buffer_load/store of those types

The need to bitcast vectors of pointers was also revealed to affect
ordinary `G_LOAD` and `G_STORE` in some cases, so
`shouldBitcastLoadStore()` has been fixed to handle it properly.
2024-10-02 13:46:56 -05:00
spupyrev
9016f27c42
[CodeLayout] Size-aware machine block placement (#109711)
This is an implementation of a new "size-aware" machine block placement.
The
idea is to reorder blocks so that the number of fall-through jumps is
maximized.
Observe that profile data is ignored for the optimization, and it is
applied only
for instances with hasOptSize()=true.
This strategy has two benefits:
(i) it eliminates jump instructions, which results in smaller text size;
(ii) we avoid using profile data while reordering blocks, which yields
more
"uniform" functions, thus helping ICF and machine outliner/merger.

For large (mobile) apps, the size benefits of (i) and (ii) are roughly
the same,
combined providing up to 0.5% uncompressed and up to 1% compressed
savings size
on top of the current solution.

The optimization is turned off by default.
2024-10-02 10:48:08 -07:00
Matt Arsenault
f2eeb3dc7b
AMDGPU: Handle v_add* in eliminateFrameIndex (#102346) 2024-10-02 21:19:45 +04:00
Matt Arsenault
4cd1f9ac9f
AMDGPU: Add baseline test for frame index folding (#110737)
We currently can increase the instruction count
when a frame index requires materialization.
2024-10-02 19:47:32 +04:00
Matt Arsenault
187dcd8e22
DAG: Preserve disjoint flag when emitting final instructions (#110795) 2024-10-02 19:37:04 +04:00
Janek van Oirschot
e35319524a
[AMDGPU] Fix stack size metadata for functions with direct and indirect calls (#110828)
When a function has an external call, it should still use the stack
sizes of direct, known, calls to calculate its own stack size
2024-10-02 14:52:52 +01:00
Matt Arsenault
1bc9b67bd8
Scalarizer: Replace cl::opts with pass parameters (#110645)
Preserve the existing defaults (although load-store defaulting
to false is a really bad one). Also migrate DirectX tests to new PM.
2024-10-02 14:45:26 +04:00
Jeremy Morse
e6bf48d110
[X86] Don't request 0x90 nop filling in p2align directives (#110134)
As of rev ea222be0d, LLVMs assembler will actually try to honour the
"fill value" part of p2align directives. X86 printed these as 0x90, which
isn't actually what it wanted: we want multi-byte nops for .text
padding. Compiling via a textual assembly file produces single-byte
nop padding since ea222be0d but the built-in assembler will produce
multi-byte nops. This divergent behaviour is undesirable.

To fix: don't set the byte padding field for x86, which allows the
assembler to pick multi-byte nops. Test that we get the same multi-byte
padding when compiled via textual assembly or directly to object file.
Added same-align-bytes-with-llasm-llobj.ll to that effect, updated
numerous other tests to not contain check-lines for the explicit padding.
2024-10-02 11:14:05 +01:00
Bevin Hansson
1a65d95d00
[CodeGen][RAGreedy] Inform LiveDebugVariables about snippets spilled by InlineSpiller. (#109962)
RAGreedy invokes InlineSpiller to spill a particular virtreg inline.
When the spiller does this, it also identifies small, adjacent liveranges called
snippets. These are also spilled or rematerialized in the process.

However, the spiller does not inform RA that it has spilled these regs.
This means that debug variable locations referencing these regs/ranges
are lost.

Mark any spilled regs which do not have a stack slot assigned to them as
allocated to the slot being spilled to to tell LDV that those regs are
located in that slot, even though the regs might no longer exist in the
program after regalloc is finished. Also, inform RA about all of the
regs which were replaced (spilled or rematted), not just the one that was
requested so that it can properly manage the ranges of the debug vars.
2024-10-02 10:29:56 +02:00
Matt Arsenault
30ea7e859b AMDGPU: Preserve flags in regbankselect when splitting or 2024-10-02 12:08:21 +04:00
Matt Arsenault
203d5158c3 AMDGPU/GlobalISel: Preserve flags when splitting select
RegBankSelect was losing flags on selects.
2024-10-02 12:08:17 +04:00
Luke Lau
496187b3b8 [RISCV] Move bfloat tests back above half. NFC
In the other tests bfloats tend to come before the halfs, in
insertelt-fp.ll they were temporarily swapped to help with the diff in
2024-10-02 15:30:49 +08:00
Luke Lau
1fa4a74d53
[RISCV] Lower insert_vector_elt on zvfhmin/zvfbfmin (#110221)
This is the dual of #110144, but doesn't handle the case when the scalar
type is illegal i.e. no zfhmin/zfbfmin. It looks like softening isn't
yet implemented for insert_vector_elt operands and it will crash during
type legalization, so I've left that configuration out of the tests.
2024-10-02 15:26:25 +08:00
Luke Lau
30f58ab17f
[RISCV] Lower vector_reverse for zvfhmin/zvfbfmin (#110218)
Previously we crashed because we had no lowering for f16/bf16 scalable
vectors.
Because the lowering uses vrgather_vv_vl, we need to add bf16 patterns
for it.
2024-10-02 14:25:15 +08:00
Craig Topper
bc91f3cdd5
[RISCV] Add 32 bit GPR sub-register for Zfinx. (#108336)
This patches adds a 32 bit register class for use with Zfinx instructions. This makes them more similar to F instructions and allows us to only spill 32 bits.
    
I've added CodeGenOnly instructions for load/store using GPRF32 as that gave better results than insert_subreg/extract_subreg.
    
Function arguments use this new GPRF32 register class for f32 arguments with Zfinx. Eliminating the need to use RISCVISD::FMV* nodes.
    
This is similar to #107446 which adds a 16 bit register class.
2024-10-01 22:09:27 -07:00
Craig Topper
1053b3ea24 [RISCV][GISel] Stop promoting s32 G_SHL/ASHR/LSHR shift amount to s64 on RV64.
There are no SelectionDAG patterns to share. GISel has its own patterns
since it considers s32 a legal type and SDAG does not.
2024-10-01 21:23:01 -07:00
Craig Topper
9c15ff21aa
[RISCV][GISel] Add RISCVPassConfig::getCSEConfig() to match other targets. (#110755) 2024-10-01 21:07:26 -07:00
Michael Maitland
ca5b81bdef
[RISCV][GISEL] regbankselect for G_SPLAT_VECTOR (#110744) 2024-10-01 21:50:21 -04:00
Michael Maitland
d7e0c08ab9
[RISCV][GISEL] regbankselect for G_VMCLR_VL (#110746)
These are genereated when legalizing G_SPLAT_VECTOR
2024-10-01 21:16:58 -04:00
Craig Topper
c62cb1bf1e [RISCV][GISel] Stop promoting s32 G_ROTL/ROTR rotate amount to s64 on RV64.
There are no SelectionDAG patterns to share. GISel has its own patterns
since it considers s32 a legal type and SDAG does not.
2024-10-01 16:07:26 -07:00
yonghong-song
38a8000f30
[BPF] Use mul for certain div/mod operations (#110712)
The motivation example likes below
```
  $ cat t1.c
  struct S {
    int var[3];
  };
  int foo1 (struct S *a, struct S *b)
  {
      return a - b;
  }
```
For cpu v1/v2/v3, the compilation will fail with the following error:
```
  $ clang --target=bpf -O2 -c t1.c -mcpu=v3
  t1.c:4:5: error: unsupported signed division, please convert to unsigned div/mod.
  4 | int foo1 (struct S *a, struct S *b)
        |     ^
  1 error generated.
```
The reason is that sdiv/smod is only supported at -mcpu=v4. At cpu
v1/v2/v3, only udiv/umod is supported.

But the above example (for func foo1()) is reasonable common and user
has to workaround the compilation failure by using udiv with
conditionals.

For x86, for the above t1.c, compile and dump the asm code like below:
```
  $ clang -O2 -c t1.c && llvm-objdump -d t1.o
  0000000000000000 <foo1>:
       0: 48 29 f7                      subq    %rsi, %rdi
       3: 48 c1 ef 02                   shrq    $0x2, %rdi
       7: 69 c7 ab aa aa aa             imull   $0xaaaaaaab, %edi, %eax # imm = 0xAAAAAAAB
       d: c3                            retq
```
Basically sdiv can be replaced with sub, shr and imul. Latest gcc-bpf is
also able to generate code similar to x86 with -mcpu=v1. See
https://godbolt.org/z/feP9ETbjj

Generally multiplication is cheaper than divide. LLVM SelectionDAG
already supports to generate alternative codes (mul etc.) for div/mod
operations if the divisor is constant and if the cost of division is not
cheap. For BPF backend, let us use multiplication instead of divide
whenever possible. The following is the list of div/mod operations which
can be converted to mul.
  - 32bit signed/unsigned div/mod with constant divisor
- 64bit signed/unsigned div with constant divisor and with 'exact' flag
in IR where 'exact' means if replacing div with mod, it is guaranteed
that modulo result will be 0. The above foo1() case belongs here.
2024-10-01 14:20:54 -07:00
David Majnemer
aa02b76b1a [X86] Let's improve the expression we dump for vpternlog
Right now, we are printing stuff like:
 zmm0 = (~zmm0 & zmm1 & mem) | (zmm0 & ~zmm1 & ~mem) |
        (zmm0 & ~zmm1 & mem) | (zmm0 & zmm1 & ~mem) |
	(zmm0 & zmm1 & mem)

This is not wrong but it sure is verbose and it makes it a bit hard to
understand what is going on at a glance.

The above expression is equivalent to:
 zmm0 = zmm0 | (zmm1 & mem)

I considered simplifying the expressions on the fly but that gets out of
hand very quickly. Quine-McCluskey is not so simple and so fast that it
makes a ton of sense for our pretty printer. I quickly played around
with some different normal forms and ended up just using this [1] table
of functions with some minor post-processing. I made sure that each
function is identical to the appropriate BooleanFunction in Mathematica.

If the size of these tables ends up mattering for whatever reason there
are a few obvious things we could do to save space without undue effort.

[1]: https://gist.github.com/dougallj/81a80cd381988466c4e1c4889ecac95b#file-2-x86-base-txt
2024-10-01 21:18:32 +00:00
Florian Mayer
60af1548e1
[MTE] Allow stack history for API level >=35 (#110328) 2024-10-01 13:11:24 -07:00
Craig Topper
916c830209 Revert "[RISCV][GISel] Remove unused isel patterns for s32 shifts with s64 shift amount."
This reverts commit 9e45e7facbdec209a06ee20fcfbb7d0622835e21.

I found a way that these can be used. I think it's a bug somewhere
else that I need to address separately first.
2024-10-01 12:14:55 -07:00
Alex Bradbury
e45b44c630
[RISCV] Add pattern for PACK/PACKH in common misaligned load case (#110644)
PACKH is currently only selected for assembling the first two bytes of a
misligned load. A fairly complex RV32-only pattern is added for
producing PACKH+PACKH+PACK to assemble the result of a misaligned 32-bit
load.

Another pattern was added that just covers PACKH for shifted offsets 16
and 24, producing a packh and shift to replace two shifts and an 'or'.
This slightly improves RV64IZKBK for a 64-bit load, but fails to match
for the misaligned 32-bit load because the load of the upper byte is
anyext in the SelectionDAG.

I wrote the patch this way because it was quick and easy and has at
least some benefit, but the "right" approach probably merits further
discussion. Introducing target-specific SDNodes for PACK* and having
custom lowering for unaligned load/stores that introduces those nodes
them seems like it might be attractive. However, adding these patterns does provide benefit - so that's what this patch does for now.
2024-10-01 20:09:51 +01:00
eddyz87
2fca0effb4
[BPF] fix sub-register handling for bpf_fastcall (#110618)
bpf_fastcall induced spill/fill pairs should be generated for
sub-register as well as for sub-registers. At the moment this is not the
case, e.g.:

    $ cat t.c
    extern int foo(void) __attribute__((bpf_fastcall));

    int bar(int a) {
      foo();
      return a;
    }

    $ clang --target=bpf -mcpu=v3 -O2 -S t.c -o -
    ...
    call foo
    w0 = w1
    exit

Modify BPFMIPeephole.cpp:collectBPFFastCalls() to check sub-registers
liveness and thus produce correct code for example above:

    *(u64 *)(r10 - 8) = r1
    call foo
    r1 = *(u64 *)(r10 - 8)
    w0 = w1
    exit
2024-10-01 21:20:22 +03:00
Michael Maitland
f957d080e9
[RISCV][GISEL] Legalize G_EXTRACT_SUBVECTOR (#109426)
This is heavily based on the SelectionDAG lowerEXTRACT_SUBVECTOR code.
2024-10-01 14:08:49 -04:00
Matt Arsenault
2d3119c3d9 AMDGPU: Add more tests for frame index code quality
There are also some bugs with sgpr constraints.
2024-10-01 21:42:34 +04:00
Matt Arsenault
f61abee01a AMDGPU: Add missing tests for local stack alloc s_add_i32 handling
None of these tested the case where the non-frame index operand
was a register.
2024-10-01 19:49:18 +04:00
Fabian Ritter
16ba126a14
[AMDGPU][GlobalISel][NFC] Use amdhsa target for flat/private tests (#110672)
As a proxy criterion, mesa targets have unaligned-access-mode (which
determines whether the hardware allows unaligned memory accesses) not
set whereas amdhsa targets do. This PR changes tests to use amdhsa
instead of mesa and inserts additional checks with unaligned-access-mode
unset explicitly.

This is in preparation for PR #110219, which will generate different
code depending on the unaligned-access-mode.
2024-10-01 17:04:18 +02:00
Matt Arsenault
8395b3f60f AMDGPU: Mark scc dead when materialized frame base registers 2024-10-01 18:54:18 +04:00
Brox Chen
2672037e36
[AMDGPU][True16][MC] Support VOP3 only instructions with true16 and fake16 (#109891)
Update VOP3 only instructions with true16 and fake16 formats. 

This patch includes instructions:
V_MUL_LO_U16
V_MAX_U16
V_MAX_I16
V_MIN_U16
V_MIN_I16
V_LSHLREV_B16
V_LSHRREV_B16
V_ASHRREV_I16
2024-10-01 09:25:36 -04:00
Nikita Popov
9f81acf4ef [Mips] Regenerate test checks (NFC)
Some of these check lines are insufficient to determine correctness.
Generate full check lines instead.

To reduce noise, add nounwind and use static relocation model.
2024-10-01 14:49:14 +02:00
Alex Bradbury
14c4f28ec1
[RISCV] Enable load clustering by default (#73789)
We believe this is neutral or slightly better in the majority of cases.
2024-10-01 13:45:30 +01:00
James Chesterman
b2a6814126
[AArch64][NEON][SVE] Lower i8 to i64 partial reduction to a dot product (#110220)
An i8 to i64 partial reduction can instead be done with an i8 to i32 dot
product followed by a sign extension.
2024-10-01 13:26:38 +01:00
Nikita Popov
4b3ba64ba7
[SCEVExpander] Clear flags when reusing GEP (#109293)
As pointed out in the review of #102133, SCEVExpander currently
incorrectly reuses GEP instructions that have poison-generating flags
set. Fix this by clearing the flags on the reused instruction.
2024-10-01 14:22:54 +02:00
Simon Pilgrim
520562c597 Revert 412d59f0a510a05c08ed45545943dfd2f901bc5d "[DAG] combineShiftToMULH - handle zext nneg as sext"
Reverting until I can investigate a miscompilation reported by @mstorsjo
2024-10-01 10:52:27 +01:00
Alex Bradbury
39b2e35f3d [RISCV][test] Precommit tests showing codegen for unaligned load/store with zbkb
We have missed opportunities for selecting pack* instructions, that will
be addressed in future patches.
2024-10-01 10:49:50 +01:00
CarolineConcatto
308c9a9451
[Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction (#97602)
This patch adds these intrinsics:

  // Variants are also available for:
  // [_s8], [_u16], [_s16], [_u32], [_s32], [_u64], [_s64]
  // [_bf16], [_f16], [_f32], [_f64]
void svwrite_lane_zt[_u8](uint64_t zt0, svuint8_t zt, uint64_t idx)
__arm_streaming __arm_inout("zt0");
void svwrite_zt[_u8](uint64_t zt0, svuint8_t zt) __arm_streaming
__arm_inout("zt0");

according to PR#324[1]
[1]https://github.com/ARM-software/acle/pull/324
2024-10-01 10:11:32 +01:00
Vyacheslav Levytskyy
0e3476605f
[SPIR-V] Implement support of the SPV_EXT_arithmetic_fence SPIRV extension (#110500)
This PR implements support of the SPV_EXT_arithmetic_fence SPIRV
extension:
https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/EXT/SPV_EXT_arithmetic_fence.html.
2024-10-01 10:48:25 +02:00
Vyacheslav Levytskyy
c538d5c8b2
[SPIR-V] Discard some llvm intrinsics which we do not expect to actually represent code after lowering (#110233)
There are llvm intrinsics which we do not expect to actually represent
code after lowering or which are not implemented yet but can be found in
a customer's LLVM IR input. We do not want translation to crash when
these llvm intrinsics are found, and this PR fixes the issue with
translation crash for some known cases, aligned with Khronos Translator.
2024-10-01 10:48:10 +02:00