36246 Commits

Author SHA1 Message Date
Alex MacLean
ccc31278bd
[NVPTX] support switch statement with brx.idx (reland) (#102550)
Add custom lowering for `BR_JT` DAG nodes to the `brx.idx` PTX
instruction ([PTX ISA 9.7.13.4. Control Flow Instructions: brx.idx]
(https://docs.nvidia.com/cuda/parallel-thread-execution/#control-flow-instructions-brx-idx)).
Depending on the heuristics in DAG selection, `switch` statements may
now be lowered using `brx.idx`.

Note: this fixes the previous issue in #102400 by adding the isBarrier
attribute to BRX_END
2024-08-09 11:46:37 -07:00
Thorsten Schütt
6b77531123
[GlobalIsel] Combine G_ADD and G_SUB with constants (#97771) 2024-08-09 20:14:32 +02:00
Kazu Hirata
f4fb735840
[llvm] Construct SmallVector<SDValue> with ArrayRef (NFC) (#102578) 2024-08-09 09:15:42 -07:00
Manish Kausik H
259742a885
[SelectionDAG] Use unaligned store/load to move AVX registers onto stack for insertelement (#82130)
Prior to this patch, SelectionDAG generated aligned move onto stacks for
AVX registers when the function was marked as a no-realign-stack
function. This lead to misalignment between the stack and the
instruction generated. This patch fixes the issue. There was a similar
issue reported for `extractelement` which was fixed in
a6614ec5b7c1dbfc4b847884c5de780cf75e8e9c

Co-authored-by: Manish Kausik H <hmamishkausik@gmail.com>
2024-08-09 15:39:54 +01:00
Pratyay Pande
3e806c827e
[NFC] Use references to avoid copying (#99863)
Modifying `auto` to `auto&` to avoid unnecessary copying
2024-08-09 20:33:05 +08:00
Roger Ferrer Ibáñez
e1a16cd88d
[ExpandVectorPredication] Be more precise reporting changes (#102313)
This is used by PreISelIntrinsicLowering. With this change,
PreISelIntrinsicLowering does not have to assume that there were changes
just because we encountered a VP intrinsic.
2024-08-09 08:01:42 +02:00
Artem Belevich
2756879000
Revert "[NVPTX] support switch statement with brx.idx" (#102530)
Reverts llvm/llvm-project#102400

Causes LLVM to crash on some tests.
2024-08-08 13:31:10 -07:00
Alex MacLean
ba97697189
[NVPTX] support switch statement with brx.idx (#102400)
Add custom lowering for `BR_JT` DAG nodes to the `brx.idx` PTX
instruction ([PTX ISA 9.7.13.4. Control Flow Instructions: brx.idx]
(https://docs.nvidia.com/cuda/parallel-thread-execution/#control-flow-instructions-brx-idx)).
Depending on the heuristics in DAG selection, `switch` statements may
now be lowered using `brx.idx`
2024-08-08 13:19:26 -07:00
Simon Pilgrim
ad00e8a8dd [DAG] Replace m_SpecificInt(1) -> m_One()
For SDPatternMatch there's no difference in undef/poison vector element handling - in fact m_One() just wraps m_SpecificInt(1)
2024-08-08 18:20:46 +01:00
Alexis Engelke
5313d2e6d0
[CodeGen] Fix lower constant intrinsics for dead code (#102442)
lowerConstantIntrinsics does an RPO traveral, which doesn't reach dead
blocks. Remove the assertion that all intrinsics are lowered, because
some intrinsics might remain.
2024-08-08 13:06:33 +02:00
Simon Pilgrim
13d04fa560 [DAG] Add legalization handling for ABDS/ABDU (#92576) (REAPPLIED)
Always match ABD patterns pre-legalization, and use TargetLowering::expandABD to expand again during legalization.

abdu(lhs, rhs) -> sub(xor(sub(lhs, rhs), usub_overflow(lhs, rhs)), usub_overflow(lhs, rhs))
Alive2: https://alive2.llvm.org/ce/z/dVdMyv

REAPPLIED: Fix regression issue with "abs(ext(x) - ext(y)) -> zext(abd(x, y))" fold failing after type legalization
2024-08-08 11:39:05 +01:00
Alexis Engelke
862d822d83
[CodeGen] Don't renumber invalid domtree (#102427)
Machine block placement might remove nodes from the function but does
not update the dominator tree accordingly. Instead of renumbering (which
might crash due to accessing removed blocks), set the domtree to null to
make clear that it is invalid at this point.

Fixup of #102107.
2024-08-08 08:53:45 +02:00
cceerczw
6f8e8faa12
[TargetLowering] Fix the problem of emulated-TLS implementation witho… (#101490)
For a __thread variable x, when emulated TLS is enabled and there is an
access to x, the compiler first looks up the symbol __emutls_v.x within
the module. However, the issue arises with an alias y of x, the compiler
still tries to look up __emutls_v.y instead of __emutls_v.x. As a
result, the lookup returns a nullptr, causing the compiler to crash. The
purpose of this MR (Merge Request) is to ensure that in emulated TLS,
before checking __emutls_v.y, the compiler first identifies which global
value y is an alias of.
2024-08-07 21:56:48 +04:00
Simon Pilgrim
e4e96b3e26 Revert b1234ddbe2652aa7948242a57107ca7ab12fd2f8. "[DAG] Add legalization handling for ABDS/ABDU (#92576)"
Reverting #92576 while we identify a reported regression
2024-08-07 17:11:25 +01:00
Nikita Popov
0564d0665b [SDAG] Transfer gep nusw/nuw to SDAG
The resulting add is nuw if either the gep was nuw or it was
nusw+nneg. Previously only inbounds+nneg was handled.

Test via wasm load offsets, which seems to most directly expose
these SDAG flags.
2024-08-07 09:26:10 +02:00
Alexis Engelke
41491c7723
[CodeGen] Allocate RegAllocHints map lazily (#102186)
This hint map is not required whenever a new register is added, in fact,
at -O0, it is not used at all. Growing this map is quite expensive, as
SmallVectors are not trivially copyable.

Grow this map only when hints are actually added to avoid multiple grows
and grows when no hints are added at all.
2024-08-07 07:56:32 +02:00
weiguozhi
0d471b3f64
Spill/restore FP/BP around instructions in which they are clobbered (#81048)
This patch fixes https://github.com/llvm/llvm-project/issues/17204.

If a base pointer is used in a function, and it is clobbered by an
instruction (typically an inline asm), current register allocator can't
handle this situation, so BP becomes garbage after those instructions.
It can also occur to FP in theory.

We can spill and reload FP/BP registers around those instructions. But
normal spill/reload instructions also use FP/BP, so we can't spill them
into normal spill slots, instead we spill them into the top of stack by
using SP register.
2024-08-06 16:18:20 -07:00
Alexis Engelke
85bf0a6b44
[CodeGen] Fix PreISelLowering not reporting changes (#102184)
expandVectorPredication may change code, even if the intrinsic itself
remains in the code. Report changes whenever such an intrinsic is
encountered, because code could have been changed.

Another follow-up fix for #101652 to fix expensive-checks-only failure.
2024-08-06 19:30:42 +02:00
Alexis Engelke
a4837fe3c1
[CodeGen] Allow PreISel lowering to run without TM (#102150)
Fixes #101652 after build bot failures where TM in the opt pass builder
is nullptr.
2024-08-06 16:21:56 +02:00
Nuno Lopes
2499978aae Convert a couple of undef placeholders to poison [NFC] 2024-08-06 15:03:16 +01:00
Simon Pilgrim
6e60d549d4 [DAG] Add foldSelectToABD helper. NFC.
Pull out of visitVSELECT to allow reuse in the future.
2024-08-06 13:31:53 +01:00
Alexis Engelke
d871b2e0d0
[CodeGen] Use optimized domtree for MachineFunction (#102107)
The dominator tree gained an optimization to use block numbers instead
of a DenseMap to store blocks. Given that machine basic blocks already
have numbers, expose these via appropriate GraphTraits. For debugging,
block number epochs are added to MachineFunction -- this greatly helps
in finding uses of block numbers after RenumberBlocks().

In a few cases where dominator trees are preserved across renumberings,
the dominator tree is updated to use the new numbers.
2024-08-06 13:46:19 +02:00
Hari Limaye
a98a0dcf63
[AArch64] Add streaming-mode stack hazard optimization remarks (#101695)
Emit an optimization remark when objects in the stack frame may cause
hazards in a streaming mode function. The analysis requires either the
`aarch64-stack-hazard-size` or `aarch64-stack-hazard-remark-size` flag
to be set by the user, with the former flag taking precedence.
2024-08-06 11:39:01 +01:00
Simon Pilgrim
b1234ddbe2
[DAG] Add legalization handling for ABDS/ABDU (#92576)
Always match ABD patterns pre-legalization, and use TargetLowering::expandABD to expand again during legalization.

abdu(lhs, rhs) -> sub(xor(sub(lhs, rhs), usub_overflow(lhs, rhs)), usub_overflow(lhs, rhs))
Alive2: https://alive2.llvm.org/ce/z/dVdMyv
2024-08-06 10:18:06 +01:00
Simon Pilgrim
1b85935453 Fix MSVC "not all control paths return a value" warning. NFC. 2024-08-06 09:38:09 +01:00
Alexis Engelke
4c23c1b93d
[CodeGen] Use SmallVector for MBB preds/succs (#101948)
Avoid extra heap allocations for typical predecessor/successor counts.
2024-08-06 10:25:03 +02:00
Alexis Engelke
37e75cdf9f
[CodeGen] Use BasicBlock numbers to map to MBBs (#101883)
Now that basic blocks have numbers, we can replace the BB-to-MBB maps
and the visited set during ISel with vectors for faster lookup.
2024-08-06 10:22:31 +02:00
Alexis Engelke
fa92d51f9e
[VP] Merge ExpandVP pass into PreISelIntrinsicLowering (#101652)
Similar to #97727; avoid an extra pass over the entire IR by performing
the lowering as part of the pre-isel-intrinsic-lowering pass.
2024-08-06 09:27:59 +02:00
Ryotaro KASUGA
1745c8e08d
[MachinePipeliner] Fix instruction order with physical register (#99264)
dependencies in same cycle

Dependency checks were insufficient when reordering instructions with
physical register dependencies (i.e. Anti/Output dependencies). This
could result in generating incorrect code.
2024-08-06 13:46:10 +09:00
Luke Lau
33fc322696
[SelectionDAG] Simplify vselect true, T, F -> T (#100992)
This addresses a TODO where we can fold a vselect to it's true operand
if the boolean is known to be all trues, by factoring out the logic from
extractBooleanFlip which checks TLI.getBooleanContents.
2024-08-06 10:49:20 +08:00
Pavel Labath
0e4c7fabd3
[DebugInfo] (Always) include the dwo name in the hash (#100375)
Since ce0c205813c74b4225180ac8a6e40fd52ea88229, we are doing that if a
single (LTO) compilation contains more than one compile unit, but the
same thing can happen if the non-lto and single-cu lto compilations,
typically when the CU ends up (nearly) empty. In my case, this happened
when LTO emptied two compile units.

Note that the source file name is already a part of the hash, so this
can only happen when a single file is compiled and linked twice into the
same application (most likely with different preprocessor defintiions).
While not exactly common, this pattern is used by some C code to
implement "templates".

The 2017 patch already hinted at the possibility of doing this
unconditionally, and this patch implements that. While the DWARF spec
hints at the option of using the type signature hashing algorithm for
the DWO_id purposes, AFAICT it does not actually require it, so I
believe this change is still conforming.

The relevant section of the spec is in Section 3.1.2 "Skeleton
Compilation Unit Entries" (in non-normative text):

```
The means of determining a compilation unit ID does not need to be
similar or related to the means of determining a type unit signature.
However, it should be suitable for detecting file version skew or other
kinds of mismatched files and for looking up a full split unit in a
DWARF package file (see Section 7.3.5 on page 190).
```
2024-08-05 16:38:08 +02:00
Kai Yan
d808f15828
[llvm][CodeGen] Address the issue of multiple resource reservations In window scheduling (#101665)
Address the issue of multiple resource reservations in window
scheduling.
2024-08-05 17:44:05 +08:00
Alexis Engelke
da0e66e64c
[CodeGen][NFC] Add wrapper method for MBBMap (#101893)
This is a preparation for changing the data structure of MBBMap.
2024-08-04 18:34:26 +02:00
Kazu Hirata
8d1b17b662
[CodeGen] Construct SmallVector with ArrayRef (NFC) (#101841) 2024-08-04 00:41:29 -07:00
Sergei Barannikov
4527fba9ad
Revert "[SDag][ARM][RISCV] Allow lowering CTPOP into a libcall" (#101740)
Reverts the rest of llvm/llvm-project#99752
2024-08-03 01:51:26 +03:00
Fangrui Song
0b92e70dfb Revert "[AMDGPU] Always lower s/udiv64 by constant to MUL (#100723)"
This reverts commit 92fbc963a51683d32f70d0c7f3783bb13983f08d.

The patch also affected ARM and caused an assertion failure during
CurDAG->Legalize
(https://github.com/llvm/llvm-project/pull/100723#issuecomment-2266154211).
2024-08-02 14:43:36 -07:00
Sergei Barannikov
4e93b16f3f
[llvm] Make InstSimplifyFolder constructor explicit (NFC) (#101654) 2024-08-02 16:45:50 +03:00
Kai Yan
58964c8499
Revert "[llvm][CodeGen] Address the issue of multiple resource reservations in window scheduling (#100301)" (#101658)
This reverts commit aa0a33be56f1ef8195eccbca57a103a8e1e302e3.
2024-08-02 20:27:22 +08:00
Alexis Engelke
1525abb9c9
[FastISel] Don't use sizeWithoutDebug() for debug records (#101648)
sizeWithoutDebug() iterates over the entire block, but all we do is to
check whether the number is not equal to one. In times of debug records,
simply check whether the first and last instructions are equal.
2024-08-02 14:06:36 +02:00
Kai Yan
aa0a33be56
[llvm][CodeGen] Address the issue of multiple resource reservations in window scheduling (#100301)
Address the issue of multiple resource reservations in window scheduling
2024-08-02 19:25:34 +08:00
Pierre van Houtryve
92fbc963a5
[AMDGPU] Always lower s/udiv64 by constant to MUL (#100723)
Solves #100383
2024-08-02 12:22:42 +02:00
Sergei Barannikov
92e18ffd80
[SDag][ARM][RISCV] Allow lowering CTPOP into a libcall (#99752)
The main change is adding CTPOP to `RuntimeLibcalls.def` to allow
targets to use LibCall action for CTPOP. DAG legalizers are changed
accordingly.
2024-08-02 12:29:39 +03:00
Zequan Wu
ae6dc64ec6 Reapply "[Clang] Fix nomerge attribute not working with __builtin_trap(), __debugbreak(), __builtin_verbose_trap() (#101549)"
This reverts commit 667598d84b16d1789ce90b231565e9e7bfdbe77d and fixes failed tests: llvm/test/CodeGen/X86/nomerge.ll and llvm/test/MC/AArch64/local-bounds-single-trap.ll.
2024-08-01 15:54:50 -07:00
Haowei Wu
667598d84b Revert "[Clang] Fix nomerge attribute not working with __builtin_trap(), __debugbreak(), __builtin_verbose_trap() (#101549)"
This reverts commit 5e84646982d1ec9bc94e48dde4b47f03c044a156, which
broke 'nomerge.ll' test on llvm bots.
2024-08-01 14:46:36 -07:00
Zequan Wu
5e84646982
[Clang] Fix nomerge attribute not working with __builtin_trap(), __debugbreak(), __builtin_verbose_trap() (#101549)
1. It fixes the problem that llvm.trap() not getting the nomerge
attribute.
2. It sets nomerge flag for the node if the instruction has nomerge
arrtibute.

This is a copy of https://reviews.llvm.org/D146164. This only attempts
to fix `nomerge` for `__builtin_trap()`, `__debugbreak()`,
`__builtin_verbose_trap()`, not working for non-trap builtins.

Fixes #53011
2024-08-01 16:13:39 -04:00
Alexis Engelke
b5fc083dc3
[CodeGen] Merge lowerConstantIntrinsics into pre-isel lowering (#97727)
Currently, the LowerConstantIntrinsics pass does an RPO traversal of
every function... only to find that many functions don't have constant
intrinsics (is.constant, objectsize). In the CodeGen pipeline, there is
already a pre-isel intrinsic lowering pass, which iterates over
intrinsic declarations and lowers all users. Call
lowerConstantIntrinsics from this pass to avoid the extra iteration over
the entire IR and the RPO traversal.
2024-08-01 17:44:32 +02:00
Craig Topper
72ed80866f
[MIR] Remove separate Size variable from parseMachineMemoryOperand. NFC (#101453)
Size is updated in sync with MemoryType. Instead of maintaining a
separate Size, use the size from MemoryType where needed.
2024-07-31 22:57:45 -07:00
Craig Topper
307d1249ea
[LegalizeTypes][RISCV][LoongArch] Optimize promotion of ucmp. (#101366)
ucmp can be promoted with either sext or zext. RISC-V and LoongArch
prefer sext for promoting i32 to i64 unless the inputs are known to be
zero extended already.

This patch uses the existing SExtOrZExtPromotedOperands function that is
used by SETCC promotion to intelligently handle this.
2024-07-31 17:18:27 -07:00
Jiahan Xie
1c66ef9157
[GISEL][RISCV] RegBank Select for Scalable Vector Load/Store (#99932)
This patch supports GlobalISel for register bank selection for scalable vector
load and store instructions in RISC-V
2024-07-31 19:18:42 -04:00
Jiahan Xie
a0d8fa5d3a
[RISCV][GlobalISel] Legalize Scalable Vector Loads and Stores (#84965)
This patch supports legalizing load and store instruction for scalable
vectors in RISCV
2024-07-31 19:00:15 -04:00