[TableGen] Fix depfile escaping test on MinGW (#242919)
The test assumed that native Windows paths use backslashes.
LLVM_WINDOWS_PREFER_FORWARD_SLASH=ON, the default for MinGW builds,
converts separators to forward slashes before escaping, causing the
depfile check to fail.
Run the test with both separator preferences explicitly selected. Check
forward-slash output on Windows while retaining literal backslash checks
on other platforms, independently of the configured default.
Addresses
https://github.com/llvm/llvm-project/pull/160834#issuecomment-6902350571
[AArch64] Restore STI after emitting a PAuth IRELATIVE resolver (#242420)
The resolver can be emitted while emitting a function, whose
instructions then used the subtarget freed at the end of
emitPAuthRelocationAsIRelative. Found by -Wlifetime-safety.
Assisted-by: Claude Opus 5.5
Co-authored-by: Gabor Horvath <gaborh at apple.com>
release/23.x: [LV] Have ExtractValue match the shape of the operand. (#229927)
Previously, BuildStructVector would create a vector of a wide struct
type, where each element is widened.
This can cause issues, if a transform turns an extractvalue of a wide
call into a single-scalar (e.g. makeScalarizationDecisions), because we
currently cannot extract lane 0 from a struct of vectors.
Instead of relying on BuildStructVector, we can instead have the
ExtractValue match the shape of its operand (either widen if the operand
is wide, or replicated if the operand is scalar). If a vector value is
needed, we can directly use the existing BuildVector.
This fixes a number of crashes in the newly added tests, including
https://github.com/llvm/llvm-project/issues/229609.
Depends on https://github.com/llvm/llvm-project/pull/229925
PR: https://github.com/llvm/llvm-project/pull/229927
[X86][APX] Fix commuting SHLD/SHRD NF, NF_ND and EVEX variants (#233873)
All SHLD/SHRD rri8 variants are marked commutable, but
commuteInstructionImpl only rewrote the legacy and _ND opcodes as SHLD
B, C, I <-> SHRD C, B, (BitWidth - I). The _NF, _NF_ND and _EVEX
variants fell through to the generic commute, which only swaps the
sources and changes the result.
This is reachable when optimizeCompareInstr converts an EFLAGS clobber
to its NF form (e.g. SHLD16rri8_ND -> SHLD16rri8_NF_ND) and RA assigns
the destination to the second source: X86CompressEVEX commutes it to
drop the redundant NDD destination and emits the wrong shift. The
TwoAddressInstruction pass can hit the same bug when commuting the
non-NDD _NF and _EVEX forms.
Assisted-By: Claude Opus 5.5 <noreply at anthropic.com>
[ELF] includeInSymtab: Fix crash for SHF_MERGE section symbol with out-of-range addend (#240732)
includeInSymtab passes a section symbol's st_value, which is not
range-checked, to getSectionPiece. A value at or past the end of the
SHF_MERGE section causes an assertion failure or crash.
A local section symbol is not copied to .symtab, and a non-local one
gets the "offset is outside the section" error from getSymVA.
Fix #235203
(cherry picked from commit 4423d417a23c193b234c2a8c6fa566e2d60c0ab9)
[libc++] Use section-based overridden function detection on Mach-O (#240482)
PR #208330 switched the non-ptrauth implementation of
__is_function_overridden to a mechanism that defines a local alias at
the same address as the weak function f.
Recent Mach-O linkers (e.g. the one in Xcode 27.0) bind references to a
weak definition directly when that definition has a local alias at the
same address, instead of going through a weak-def-coalesced stub or GOT
entry. Older linkers like the ones in Xcode 26.6 (which we use in the
CI) don't do that, which is why this wasn't caught by the CI. This means
that we always resolved `__is_function_overridden` to false with newer
linkers, which breaks the detection mechanism.
Assisted by Claude
(cherry picked from commit de513b8f794ed75611475fea0f4ff2746a7c663f)
[mlir][affine] Fix sibling fusion with multiple loads (#226759)
Sibling fusion missed nests that load the shared memref more than once,
e.g. two loops that both read `A[i]` and `A[i + 1]`. Such siblings were
filtered out, and even when one of the nests had a single load, the
slice was computed as the union over all load pairs. That union spans
several source iterations per destination iteration and gets rejected as
an incorrect slice.
Sibling nests don't depend on each other, so compute the slice from a
single pair of loads instead, preferring one that gives a maximal slice,
and drop the single-load restriction.
Fixes #219356
Used Claude to help with helper function and tests
[libc++] Add __checked_int and replace uses of the overflow builtins with it (#234585)
This makes it easier to check for overflow, since we can write
operations as usual and just check once in the end instead of calling
hard to read builtins everywhere.
[mlir][LLVM] Canonicalize llvm.br and add standalone merge pass (#242139)
Add BrOp::canonicalize, merging branches to single-predecessor blocks,
and llvm-merge-branch-blocks, a pass applying only those patterns.
CIR lowering needs block merging before LLVM IR translation so the
optimizer sees a smaller CFG: the equivalent post-translation sweep
shrank pre-opt dumps 11 to 15 percent and saved about 2 seconds of
optimizer time across five translation units. Full canonicalization
would pay for every pattern and fold the whole module, so running the
patterns standalone, with folding off, gets that win without changing
other operations.
[CIR] Annotate AMDGPU printf ops with constant strings before lowering (#242111)
Resolve constant format strings while producers are still CIR, so the
AMDGPU printf lowering does not meet converted producers under one-shot
conversion. This is required work for the one-shot LLVM conversion flip:
record one string per operand on each op and read the annotation in the
lowering, instead of walking producers there.
Direct constants use matchPattern and single widening steps use
CastOp::fold; the cast chain walk stays hand written because CastOp is
not ConstantLike and its fold folds narrowing casts. New tests cover
int-array globals, stale annotations, and a narrowing cast that must not
fold.
[MemCpyOpt][EarliestEscapeAnalysis] Properly invalidate EEA on moves (#238026)
EarliestEscapeAnalysis cache can become stale whenever we move instructions
or introduce new instructions. It can only happen if the newly inserted instruction
can indeed be an escape. In that case, we drop the cache. Arguably, this is a rather
crude solution, but it might be not easy to introduce a solution that tracks which
pointers escape the same way the original analysis does and handles depth cut-offs
conservatively. Moving escape points shouldn't be very frequent to begin with, so
this trivially conservative solution seems to strike a good balance.
Fixes #238018.
[ORC] Avoid -Wlifetime-safety false positive in addGenerator (#242264)
Return the reference from inside the locked lambda instead of binding it
to the moved-from unique_ptr parameter. NFC.
Co-authored-by: Gabor Horvath <gaborh at apple.com>
[Clang][ABI][X86] Fix arg extension incompatibility with platform psABI (#236450)
This resolves a long-standing incompatibility between the argument
passing ABI used by Clang and the platform psABI, primarily for x86-64
SysV targets. The psABI specifies that the caller does not need to
extend small integers, and the callee can make no assumptions about the
high bits. However, Clang instead extended small integers in the caller,
and assumed that the extension is present in the callee.
The platforms affected by this change are:
* x86-32 and x86-64 targets using the SysV ABI, except Darwin and
PlayStation. For Darwin/Playstation, the Clang ABI is now the platform
ABI. (The x86-64 SysV ABI is nowadays very explicit about high bits
being unspecified. On x86-32 SysV this is specified "by omission".)
* x86-32 Windows. I don't believe this has any ABI spec worth
mentioning, but the emergent MSVC behavior seems to be that it performs
extensions in the callee, i.e. does not assume that the high bits are
extended. (This is inherited from the previous version of the patch, so
I'm mostly trusting that it's correct.)
[69 lines not shown]
[RISCV][P-ext] Legalize splat shift amounts during vector lowering (#242996)
Vector legalization can create splat BUILD_VECTOR shift amounts with
illegal scalar operand types. Use `DAG.getSplatValue` with
`LegalTypes=true` to obtain a legal scalar before creating packed shift
nodes.
Fixes #242983
[BOLT][RISCV] Preserve hot fallthrough paths when placing cold jump stubs (#236726)
RISC-V long-jump stubs for cross-fragment edges are currently inserted
immediately after their source blocks, which can interrupt hot
fallthrough paths and force hot execution to branch over cold stubs.
Place stubs for zero-count edges at the end of the source fragment when
the source has a fallthrough successor in the same fragment and a
conservative distance bound fits within the conditional branch range.
This follows BOLT's existing AArch64 strategy of keeping cold
trampolines out of hot paths whenever branch reach permits.
[libc] Move the fork gettid call into a syscall wrapper (#242606)
Move the uncached gettid syscall used by fork() to refresh the child TID
into linux_syscalls::gettid. Register the wrapper in CMake and Bazel.
[DebugInfo] Invalidate debug info of users when an icmp predicate cha… (#238019)
…nges
Fixes https://github.com/llvm/llvm-project/issues/218620
When an `icmp` predicate changes, future calculations using that value
could change. Any debug records relying on the results of those
calculations would then be incorrect.
`CorrelatedValuePropagation` goes through the user chain to see what the
range of values could be, which lets it decide if it can make this
optimisation. This PR changes that so that the debug records of those
users are also collected as it goes through the chain. Then, if the
optimisation is taken, we invalidate those debug records to prevent
incorrect values from being reported.
[LV] Pre-commit tests for FP derived IV index conversion (NFC) (#240741)
Add a test for an FP induction with a trip count above INT32_MAX, which
is currently miscompiled because the iteration index is converted with
sitofp. Also add an X86 cost test for converting an i64 index of an FP
derived IV.
The fix is in #240743.
Assisted-by: Claude Code
[CIR] Use memory types for bool aggregate constants (#236082)
CIR lowers scalar bool values to `i1`, but bool objects use byte-sized
storage. For example, a `bool[3]` becomes `!llvm.array<3 x i8>`, so its
dense initializer must use `tensor<3xi8>` rather than `tensor<3xi1>`.
Thread the converted element type and module-scoped data layout through
aggregate constant lowering so bool arrays and record members use the
memory type selected by `convertTypeForMemory`. This keeps constant
attributes consistent with their LLVM container types and retains bool's
`i1` value representation.
---------
Co-authored-by: Steffen Larsen <sholstla at amd.com>