8716 Commits

Author SHA1 Message Date
David Green
b9b9addae6 [AArch64] Add bitcast + extend tests. NFC 2025-03-31 14:22:49 +01:00
Jacek Caban
606e0b4806
[ARM64EC] Add support for function aliases on ARM64EC (#132295)
Required for mingw-w64, which uses the alias attribute in its CRT.

Follows ARM64EC mangling rules by mangling the alias symbol and emitting
an unmangled anti-dependency alias. Since metadata is not allowed on
GlobalAlias objects, extend arm64ec_unmangled_name to support multiple
unmangled names and attach the alias anti-dependency name to the target
function's metadata.
2025-03-31 12:56:09 +02:00
Fangrui Song
3acccf042a [MC] Don't print () around $ names
This MIPS behavior from edb9d84dcc4824865e86f963e52d67eb50dde7f5 (2010)
is obsoleted and misleading. This caused confusion in
https://reviews.llvm.org/D123702 ([NVPTX] Disable parens for identifiers
starting with '$')

Note: $tmp was rejected by AsmParser before
https://reviews.llvm.org/D75111 (2020)
2025-03-30 16:38:16 -07:00
Mingming Liu
9747bb182f
[CodeGen][StaticDataSplitter]Support constant pool partitioning (#129781)
This is a follow-up patch of
https://github.com/llvm/llvm-project/pull/125756

In this PR, static-data-splitter pass produces the aggregated profile
counts of constants for constant pools in a global state
(`StateDataProfileInfo`), and asm printer consumes the profile counts to
produce `.hot` or `.unlikely` prefixes.

This implementation covers both x86 and aarch64 asm printer.
2025-03-29 22:07:56 -07:00
Congcong Cai
a80aad2812
[YAML] fix output incorrect format for block scalar string (#132897)
After outputting block scalar string, the indent will be wrong.
This patch fixes Padding after block scalar string to ensure the correct
format of yaml.

The new added ut will fail in main.
```diff
@@ -3,4 +3,4 @@
     Just a block
     scalar doc
-scalar:          a
+  scalar:          a
 ...\n
```
2025-03-27 02:16:27 +08:00
Pranav Kant
0919ab3cb6
[AArch64] Don't try to vectorize fixed point to fp narrowing conversion (#130665)
GCC, correctly, doesn't vectorize in this case. Absence of direct
instructions to convert larger fixed point to lower floating point
precision inadvertently causes rounding leading to subtle differences
across ISAs.

https://godbolt.org/z/ssEchMWrE

Co-authored by: @echristo
2025-03-25 09:53:27 -07:00
Jonathan Cohen
6785951410
[Machine-Combiner] Add a pass to reassociate chains of accumulation instructions into a tree (#132728)
This pass is designed to increase ILP by performing accumulation into
multiple registers. It currently supports only the S/UABAL accumulation
instruction, but can be extended to support additional instructions.

Reland of  #126060 which was reverted due to a conflict with #131272.
2025-03-25 15:58:20 +02:00
Benjamin Maxwell
107260cc29
[AArch64][SME2] Don't preserve ZT0 around SME ABI routines (#132722)
This caused ZT0 to be preserved around `__arm_tpidr2_save` in functions
with "aarch64_new_zt0". The block in which `__arm_tpidr2_save` is called
is added by the SMEABIPass and may be reachable in cases where ZA has
not been enabled* (so using `str zt0` is invalid).

* (when za_save_buffer is null and num_za_save_slices is zero)
2025-03-25 10:09:25 +00:00
Ricardo Jesus
847e46ca01
[AArch64] Add initial support for -mcpu=olympus. (#132368)
This patch adds support for the NVIDIA Olympus core.

This does not add any special tuning decisions, and those may come
later.
2025-03-25 08:09:04 +00:00
David Green
06e2fd962a [AArch64] Regenerate complex-int-to-fp.ll. NFC 2025-03-24 20:35:22 +00:00
Pavel Skripkin
0e63180fa3
Reapply "[Aarch64] [ISel] Don't save vaargs registers if vaargs are unused" (#131459)
This reapplies original commit e122483762b44c7f4386165099ff2a404705d7d4

Second try, but with win64 removed from the scope, since it was somehow
broken by original commit.

### Original PR description

If vaargs are not used there is no need to save them. LLVM already
implements such optimization for x86, as well as gcc [1].

Some ABI tests are kept almost as-is, except for stack offsets, by just
adding llvm.va_start. Only laapcs_vararg_frame.ll test was rewritten to
match new behavior.

[1] https://godbolt.org/z/GWWKr8xMd
2025-03-24 18:13:42 +03:00
Csanád Hajdú
e2e776c867
[AArch64] Always add PURECODE flag to empty .text if "+execute-only" is set (#132196)
Previously, the `SHF_AARCH64_PURECODE` section flag wasn't added to the
implicitly created `.text` section if the module didn't contain any
functions, because no other section had the flag set.

Now, the `SHF_AARCH64_PURECODE` is always added if the "+execute-only"
target feature is set for the module during compilation.
2025-03-24 11:19:26 +01:00
Pierre van Houtryve
c457c88951
[GlobalISel] Combine (sext (trunc x)) to (sext_inreg x) (#131622)
Split from #131312
2025-03-24 09:32:04 +01:00
Jonathan Cohen
7bda9caa49
Revert "[AArch64][MachineCombiner] Recombine long chains of accumulation instructions into a tree to increase ILP (#126060) (#132607)
This reverts commit c4caf949aa934a219e84d4ba0530bd535e698cdb.
2025-03-23 13:58:00 +02:00
Jonathan Cohen
c4caf949aa
[AArch64][MachineCombiner] Recombine long chains of accumulation instructions into a tree to increase ILP (#126060)
This pattern shows up often in media libraries. The optimization should only
kick in for O3. Currently only supports a single family of accumulation
instructions, but can easily be expanded to support additional
instructions in the future.
2025-03-23 13:25:35 +02:00
Ryotaro Kasuga
857a04cd76
[MachinePipeliner] Fix incorrect handlings of unpipelineable insts (#126057)
There was a case where `normalizeNonPipelinedInstructions` didn't
schedule unpipelineable instructions correctly, which could generate
illegal code. This patch fixes this issue by rejecting the schedule if
we fail to insert the unpipelineable instructions at stage 0.

Here is a part of the debug output for `sms-unpipeline-insts3.mir`
before applying this patch.

```
SU(0):   %27:gpr32 = PHI %21:gpr32all, %bb.3, %28:gpr32all, %bb.4
  Successors:
    SU(14): Data Latency=0 Reg=%27
    SU(15): Anti Latency=1

...

SU(14):   %41:gpr32 = ADDWrr %27:gpr32, %12:gpr32common
  Predecessors:
    SU(0): Data Latency=0 Reg=%27
    SU(16): Ord  Latency=0 Artificial
  Successors:
    SU(15): Data Latency=1 Reg=%41
SU(15):   %28:gpr32all = COPY %41:gpr32
  Predecessors:
    SU(14): Data Latency=1 Reg=%41
    SU(0): Anti Latency=1
SU(16):   %30:ppr = WHILELO_PWW_S %27:gpr32, %15:gpr32, implicit-def $nzcv
  Predecessors:
    SU(0): Data Latency=0 Reg=%27
  Successors:
    SU(14): Ord  Latency=0 Artificial

...

Do not pipeline SU(16)
Do not pipeline SU(1)
Do not pipeline SU(0)
Do not pipeline SU(15)
Do not pipeline SU(14)
SU(0) is not pipelined; moving from cycle 19 to 0 Instr: ...
SU(1) is not pipelined; moving from cycle 10 to 0 Instr: ...
SU(15) is not pipelined; moving from cycle 28 to 19 Instr: ...
SU(16) is not pipelined; moving from cycle 19 to 0 Instr: ...
Schedule Found? 1 (II=10)

...

cycle 9 (1) (14) %41:gpr32 = ADDWrr %27:gpr32, %12:gpr32common

cycle 9 (1) (15) %28:gpr32all = COPY %41:gpr32
```

The SUs are traversed in the order of the original basic block, so in
this case a new cycle of each instruction is determined in the order of
`SU(0)`, `SU(1)`, `SU(14)`, `SU(15)`, `SU(16)`. Since there is an
artificial dependence from `SU(16)` to `SU(14)`, which is contradict to
the original SU order, the new cycle of `SU(14)` must be greater than or
equal to the cycle of `SU(16)` at that time. This results in the failure
of scheduling `SU(14)` at stage 0. For now, we reject the schedule for
such cases.
2025-03-21 23:07:41 +09:00
Shubham Sandeep Rastogi
f5f6af8e7c
[InstrRef] Preserve debug instr num in aarch64-cond-br-tuning. (#132081)
The aarch64-cond-br-tuning pass transforms a CBZX instruction into a
conditional branch (B.cond). One of the by products of the
transformation is that the source instruction of the CBZX, which is an
ANDXri instruction, gets transformed into a ANDSXri instruction, however
this transformation doesn't preserve it's debug instruction number.

This patch fixes that issue.
2025-03-20 23:06:10 -07:00
Paul Walker
7dc550473c
[LLVM][CodeGen][AArch64] Improve PTEST removal by looking through copies. (#132041)
The general predicates of the PTEST and PTEST_like instructions may
belong to different register classes. This can lead to the insertion of
a COPY instruction, making them appear different. However, for the
purpose of PTEST removal, such copies are irrelevant, and we can look
through them to improve the likelihood of finding a match.
2025-03-20 12:43:11 +00:00
David Green
53a395fda3
[AArch64][GlobalISel] Legalize more CTPOP vector types. (#131513)
Similar to other operations, s8, s16 s32 and s64 vector elements are
clamped to legal vector sizes, odd number of elements are widened to the
next power-2 and s128 is scalarized.

This helps legalize cttz as well as ctpop.
2025-03-20 07:21:01 +00:00
David Green
0e6ea0945e [AArch64][GlobalISel] Scalarize zext with larger than i64 elements.
Like other operations larger than i64, we scalarize i128 and allow them to
legalize from there. This also helps with v2i64 udiv by constant, which needs a
legalize a umulh.
2025-03-20 06:53:00 +00:00
David Green
6df192c02e [AArch64] Addition gisel tests for udiv by constant and zext/sext/trunc. NFC 2025-03-20 06:52:59 +00:00
David Green
b0876994eb
[AArch64][GlobalISel] Clean up CTLZ vector type legalization. (#131514)
Similar to other operations, s8, s16 and s32 vector elements are clamped
to legal vector sizes, but in this case s64 are scalarized to use the
gpr instructions. This allows vector types to split as opposed to
scalarizing.
2025-03-19 19:28:36 +00:00
Kerry McLaughlin
d09ecb07c2
[AArch64][CodeGen] Add +lsfe atomicrmw tests where the result is unused. (#132022)
Following the discussion on #131174, update generate-tests.py script to
emit atomicrmw tests where the result is unused and add a note to
explain why these do use ST[F]ADD.
2025-03-19 17:10:02 +00:00
Nicholas Guy
3f4b2f12a1
[llvm] Fix crash when complex deinterleaving operates on an unrolled loop (#129735)
When attempting to perform complex deinterleaving on an unrolled loop
containing a reduction, the complex deinterleaving pass would fail to
accommodate the wider types when accumulating the unrolled paths.
Instead of trying to alter the incoming IR to fit expectations, the pass
should instead decide against processing any reduction that results in a
non-complex or non-vector value.
2025-03-19 13:44:02 +00:00
Paul Walker
7e3fe884ac [LLVM] Regenerate CHECK lines for CodeGen/AArch64/sve-ptest-removal-*.mir 2025-03-19 13:33:53 +00:00
Paul Walker
6c773a8701
[LLVM][SVE] Implement isel for bfloat fptoi and itofp operations. (#129713)
NOTE: This PR only considers scalable vectors because SVE VLS does not
support bfloat (see useSVEForFixedLengthVectorVT()).
2025-03-19 11:51:42 +00:00
Ricardo Jesus
74f5a028cb
Reapply "[AArch64][SVE] Improve fixed-length addressing modes. (#129732)" (#130625)
The original patch from #129732 exposed a bug in `getMemVTFromNode`, which was returning incorrect types for fixed length vectors.
2025-03-19 08:25:37 +00:00
Benjamin Maxwell
f406b28f8b
[AArch64][SVE] Fold integer lane extract and store to FPR store (#129756)
This helps avoid pointless fmovs to GPRs, which may be slow, especially
in streaming mode.
2025-03-18 10:10:23 +00:00
Sushant Gokhale
0f34eba48a
[NFC][AArch64] test for fixed-width vector signed division with pow2-divisor and SVE enabled (#130252)
With SVE enabled, this should generate asrd instruction. Subsequent
patch will address this.
2025-03-17 22:31:22 -07:00
David Green
0878dd14b2 [AArch64][GlobalISel] Add coverage for arm64-neon-2velem.ll. NFC 2025-03-17 09:40:46 +00:00
David Green
90e6ba606f [AArch64][GlobalISel] Remove min/max v2s64 clamp
We can now lower the icmp, allowing us to remove the FIXME.
2025-03-16 09:49:22 +00:00
David Green
3fac23505f [AArch64][GlobalISel] Add cttz, ctlz and ctpop test coverage. NFC 2025-03-16 09:49:22 +00:00
Matthias Braun
e6382f2111
SelectionDAG: neg (and x, 1) --> SIGN_EXTEND_INREG x, i1 (#131239)
The pattern
```LLVM
%shl = shl i32 %x, 31
%ashr = ashr i32 %shl, 31
```
would be combined to `SIGN_EXTEND_INREG %x, ValueType:ch:i1` by
SelectionDAG.
However InstCombine normalizes this pattern to:
```LLVM
%and = and i32 %x, 1
%neg = sub i32 0, %and
```
This adds matching code to DAGCombiner to catch this variant as well.
2025-03-14 10:47:56 -07:00
Jeremy Morse
792a6f8119
[RemoveDIs] Remove "try-debuginfo-iterators..." test flags (#130298)
These date back to when the non-intrinsic format of variable locations
was still being tested and was behind a compile-time flag, so not all
builds / bots would correctly run them. The solution at the time, to get
at least some test coverage, was to have tests opt-in to non-intrinsic
debug-info if it was built into LLVM.

Nowadays, non-intrinsic format is the default and has been on for more
than a year, there's no need for this flag to exist.

(I've downgraded the flag from "try" to explicitly requesting
non-intrinsic format in some places, so that we can deal with tests that
are explicitly about non-intrinsic format in their own commit).
2025-03-14 15:50:49 +00:00
Hans Wennborg
52cd27e60b Revert "[Aarch64] [ISel] Don't save vaargs registers if vaargs are unused (#126780)"
This caused miscompiles on windows arm64, see comment on the PR.

This reverts commit e122483762b44c7f4386165099ff2a404705d7d4.
2025-03-14 16:20:03 +01:00
Frederik Harwath
6962cf1700
Rename ExpandLargeFpConvertPass to ExpandFpPass (#131128)
This is meant as a preparation for PR #130988 "[AMDGPU] Implement IR
expansion for frem instruction" which implements the expansion of
another instruction in this pass. The more general name seems more
appropriate given this change and quite reasonable even without it.
2025-03-14 13:11:45 +01:00
Sander de Smalen
9af538420a
[AArch64][GISel] Fix lowering of fp16 intrinsics (#130156)
This addresses the issue described in
https://github.com/llvm/llvm-project/issues/128843
2025-03-14 11:06:10 +00:00
Akshat Oke
87916f8c32
[CodeGen][NPM] Port MachineBlockPlacement to NPM (#129828) 2025-03-14 10:31:53 +05:30
Akshat Oke
5952972c91
[CodeGen][NPM] Port BranchFolder to NPM (#128858)
EnableTailMerge is false by default and is handled by the pass builder.
Passes are independent of target pipeline options.

This completes the generic `MachineLateOptimization` passes for the NPM
pipeline.
2025-03-13 13:41:28 +05:30
Akshat Oke
9f617161aa
[CodeGen][NPM] Port PatchableFunction to NPM (#129866) 2025-03-12 15:11:11 +05:30
sommersun
848ba3854c
[DAG] fold AVGFLOORS to AVGFLOORU for non-negative operand (#84746) (#129678)
Fold ISD::AVGFLOORS to ISD::AVGFLOORU for non-negative operand. Cover test is modified for uhadd with zero extension.

Fixes #84746
2025-03-10 13:01:08 +00:00
Paul Walker
4fee3981a8
[LLVM][SVE] Add isel for scalable vector bfloat copysign operations. (#130098) 2025-03-10 12:34:42 +00:00
Daniel Paoliello
99c6342b5e
[win] Fix EH Cont Guard targets when SEH personality is used (#129612)
There were two issues when `/guard:ehcont` is enabled with the SEH
personality on Windows:
1. As @namazso correctly identified, we bail out of
`WinException::endFunction` early for `MSVC_TableSEH` with funclets,
expecting the exception data to be emitted in `endFunclet`, but
`endFunclet` didn't copy the EHCont metadata from the function to the
module.
2. The SEH personality requires that the basic block containing the
`catchpad` is the target, not the `catchret`.

Fixes #64585
2025-03-07 09:07:47 -08:00
John Brawn
d19218e507
[SelectionDAG] Preserve fast math flags when legalizing/promoting (#130124)
When we have a floating-point operation that a target doesn't support
for a given type, but does support for a wider type, then there are two
ways this can be handled:

* If the target doesn't have any registers at all of this type then
LegalizeTypes will convert the operation.

* If we do have registers but no operation for this type, then the
operation action will be Promote and it's handled in PromoteNode.

In both cases the operation at the wider type, and the conversion
operations to and from that type, should have the same fast math flags
as the original operation.

This is being done in preparation for a DAGCombine patch which makes use
of these fast math flags.
2025-03-07 14:46:32 +00:00
Jonathan Thackray
08a89bb02e
[AArch64] Codegen for 16/32/64-bit floating-point atomicrmw ops (#125686)
Codegen for AArch64 16/32/64-bit floating-point atomic read-modify-write
operations (`atomicrmw {fadd,fmin,fmax}`) using LD{B}FADD, LD{B}FMAX and
LD{B}FMIN atomic instructions.
2025-03-07 11:22:33 +00:00
Ricardo Jesus
21610e3ecc
Revert "[AArch64][SVE] Improve fixed-length addressing modes." (#130263)
This reverts commit f01e760c08365426de95f02dc2c2dc670eb47352.
2025-03-07 09:35:55 +00:00
Daniel Paoliello
16e051f0b9
[win] NFC: Rename EHCatchret to EHCont to allow for EH Continuation targets that aren't catchret instructions (#129953)
This change splits out the renaming and comment updates from #129612 as a non-functional change.
2025-03-06 09:28:44 -08:00
Paul Walker
9ea2da5758 [NFC][LLVM] Refactor llvm/test/CodeGen/AArch64/sve{2}-fcopysign.ll 2025-03-06 12:53:40 +00:00
Ricardo Jesus
f01e760c08
[AArch64][SVE] Improve fixed-length addressing modes. (#129732)
When compiling VLS SVE, the compiler often replaces VL-based offsets
with immediate-based ones. This leads to a mismatch in the allowed
addressing modes due to SVE loads/stores generally expecting immediate
offsets relative to VL. For example, given:
```c

svfloat64_t foo(const double *x) {
  svbool_t pg = svptrue_b64();
  return svld1_f64(pg, x+svcntd());
}
```

When compiled with `-msve-vector-bits=128`, we currently generate:
```gas
foo:
        ptrue   p0.d
        mov     x8, #2
        ld1d    { z0.d }, p0/z, [x0, x8, lsl #3]
        ret
```

Instead, we could be generating:
```gas
foo:
        ldr     z0, [x0, #1, mul vl]
        ret
```

Likewise for other types, stores, and other VLS lengths.

This patch achieves the above by extending `SelectAddrModeIndexedSVE`
to let constants through when `vscale` is known.
2025-03-06 09:27:07 +00:00
Amara Emerson
5422e2c681 [AArch64][GlobalISel] On Darwin don't fold globals into the offset of prefetches.
ld64 doesn't currently support the PAGEOFF relocations on anything but load/stores
so we need to bail-out here to fix the build failures on greendragon.

rdar://145495288
2025-03-05 16:06:08 -08:00