[X86][APX] Test the relocation of an NF add
test_regclass_not_updated_by_regalloc_2 only produced an NDD/NF add
with a GOT operand because the allocator happened to give the add a
destination different from its source. With SlotIndexes compaction it
picks the same register, so the add is compressed to the legacy form
and the CODE_6 TODO lost its test.
Add a function whose add keeps its source live, so it stays NDD and
becomes NF under any allocation.
[X86] Enable SlotIndexes compaction by default
Compacting SlotIndexes before greedy allocation drops the entries of
erased instructions, so live range sizes and instruction distances
reflect the code being allocated rather than how much was erased
before it. AMDGPU has done this since #235806; do the same for X86.
Codegen changes only through allocation: no new crashes, verifier
errors or allocation failures in the lit suites, including
EXPENSIVE_CHECKS, and a stage-2 build of LLVM, clang and lld with
-verify-machineinstrs passes its own tests. On llvm-test-suite at -O3,
spills drop 0.3% and .text 0.06%, with compile time unchanged.
Most test updates are regenerated checks. misched-matmul now inserts
20 spills instead of 24. live-debug-vars-stale-slotindexes.mir gets
one more use of %27 so that accumulate_fit still reaches the stale
index path it was written for.
[AArch64] Avoid folding SRA/SRL into ALU when it can be folded with SHL/AND (#234737)
For the following function
```
int f(int a, int b) {
b -= (a<<26)>>29;
return b;
}
```
LLVM currently generates
```
f:
lsl w8, w0, #26
sub w0, w1, w8, asr #29
ret
```
However, if we don't fold the `asr` into the `sub`, the `asr` can be
folded with the `lsl` instead, and we can avoid generating the
[10 lines not shown]
[clang] fixup -Wunused-private-field (#244427)
-Wunused-private-field will soon be able to flag fields in instantiated
class templates. Land this in preparation.
Link: #237374
Link: #244396
RegisterCoalescer: Drop unused value numbers after joining
Erasing a pruned IMPLICIT_DEF marks its value number unused but leaves
it in NewVNInfo, and LiveRange::join only skipped null entries, so the
joined range kept a dead value number. Skip unused entries in join and
size valnos to the number actually kept. pruneSubRegValues similarly
only marked the pruned subrange value unused, so remove it instead.
The resulting live intervals now will have the same value numbers as a
fresh LiveIntervals computation.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes to fenv libcalls
Treat the fp environment as inaccessible memory.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[TTI] Return zero when query getRegUsageForType() with invalid type. (#243811)
This patch makes `getRegUsageForType()` returns 0 when the type is
invalid.
With this changes, we can remove the type legalization check for
scalable vector (`isElementTypeLegalForScalableVector()`) in the
VPlan-based register model. This allows `i1` scalable vector for RISC-V
can be calculated.
The reason that we don't want to accept `i1` in the
`isElementTypeLegalForScalableVector()` in RISC-V is because this
function also being used to decide if the loop can be scalable
vectorized and RISC-V don't support scalable `i1` vector load/store.
This patch partially fixes
https://github.com/llvm/llvm-project/issues/243706.
The register spill count is close to the generated assembly.
Pruned the test case with AI assistance.
[libc] Fix strtof128_test and GPU shared str_to_float build failures (#244436)
Fix two post-merge buildbot failures after #243955:
1. Define the fallback `float128` alias in `strtof128_test.cpp` when
`LIBC_TYPES_HAS_NATIVE_FLOAT128` is not set (e.g. Clang < 18.1 on
x86_64).
2. Avoid pulling `FPUtil/float128.h` (and transitively `FEnvImpl.h`)
into `str_to_float.h` by turning `ClingerConsts<fputil::Float128>` into
a dependent partial specialization, and undefine
`LIBC_MATH_USE_SYSTEM_FENV` on `LIBC_TARGET_ARCH_IS_GPU` in `FEnvImpl.h`
since GPU targets do not provide system `<fenv.h>` functions.
Also clean up direct includes and sync CMake and Bazel dependencies.
Assisted-by: Gemini
RuntimeLibcalls: Add attributes to libc libcalls
Annotate C library functions with the attributes InferFunctionAttrs
gives. This isn't fully captured in the DeclareRuntimeLibcalls testing
because not all of these functions are yet associated with a library.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes to target memory helper libcalls
Annotate the various target specific memcpy-like functions with known
alignments.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Mark noreturn and pure helper libcalls
Mark the functions which never return as noreturn. Add some nounwind
and cold, mostly following inferLibFuncAttributes. Mark
misc. functions as pure.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes inferLibFuncAttributes gives libcalls (#241618)
Remove more differences with the attributes the InferFunctionAttrs
pass would add to the declared libcalls.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[lldb] Don't crash on a PE image read from memory that llvm::object rejects (#241902)
ObjectFilePECOFF::CreateMemoryInstance builds an object file from the
512 bytes lldb reads at a module's header address. ParseHeader can parse
the headers and section table from that, but
llvm::object::COFFObjectFile often can't; the export table and other
data directories point past the end of the buffer. CreateInstance
rejects a file whose binary can't be created, but CreateMemoryInstance
keeps the object, and m_binary stays null.
ParseSymtab, GetSectionDataSize and GetTlsIndexAddress dereference
m_binary without checking it. Loading such a module makes lldb look for
its symbol file, which parses the symbol table and crashes in
AppendFromExportTable. Check the binary there, as GetUUID and
ParseDependentModules already do.
Meta hit this with a Linux core of a .NET process. .NET assemblies are
PE files, the process maps them as plain files, and the core saved the
first page of one of them. Creating a module from that memory with
[3 lines not shown]
[dsymutil] Undo prefix mapping before resolving paths for ODR uniquing (#242437)
The classic linker resolves the declaration file of a type with
realpath() to tell apart types with the same name, line and size. For
paths remapped by compilation caching, which don't exist on disk,
realpath() fails and only the file name is left, so different types
declared in headers with the same name in different directories were
merged. Undo the prefix mapping from compilation-prefix-map.json first.
[dsymutil] Support compilation-prefix-map.json from compilation caching (#242436)
Compilation caching can prefix map the paths that the compiler sees, so
that cache keys don't depend on where the build happens, for example
/path/to/project becomes /^src. The build system records the mapping in
a compilation-prefix-map.json file in a parent directory of the object
files, as a JSON object from each remapped prefix to the original one.
dsymutil didn't support it, so it used the remapped paths from the
debug info as is: it failed to copy the Swift interfaces that the debug
info refers to, didn't recognize interfaces from the SDK or the
toolchain that it should skip, and wrote the remapped paths into the
dSYM.
Load the compilation-prefix-map.json closest to each object file, and
use it to find Swift interfaces and Clang modules, and to restore the
original paths in the path attributes and line tables of the linked
debug info. Clang modules use the map of the object file that refers to
them. -object-prefix-map still only applies to looking up Clang
[5 lines not shown]
[Support] Add vfs::findFileInParentDirectories() (#242492)
Several tools look for a file in a directory and its parent
directories, for example clang-format for .clang-format and clang-tidy
for .clang-tidy, and each has its own loop for that. Add a function for
it, which dsymutil will use to find the compilation-prefix-map.json
files that compilation caching writes.
[Support] Add PrefixMapper (#242491)
Add a utility for remapping path prefixes, along with MappedPrefix for
parsing "old=new" mappings. Mappings are matched on whole path
components and respect the configured path style, so Windows paths are
matched case- and separator-insensitively.
This will be used by dsymutil to undo the path prefix mapping applied
by compilation caching.
[LLDB] Check for the instrumentation runtime before getting stop info
In `SBThread::GetStopReasonExtendedBacktraces()` check whether the
process still has an instance of the instrumentation runtime before
getting the thread's stop info. The stop info isn't needed if the
runtime has been disabled.
Assisted-by: Claude Code
[SPIR-V] Add temporary SPV_INTEL_bfloat16_arithmetic alias for SPV_EXT_bfloat16_arithmetic (#244006)
This PR adds SPV_INTEL_bfloat16_arithmetic as a temporary alias for
SPV_EXT_bfloat16_arithmetic for consumers that recognize only the INTEL
name. It should be removed once those consumers move to the EXT name.
[LLDB] Clarify plugin enable/disable errors when no process is changed
When enabling/disabling an InstrumentationRuntime plugin in the
`debugger` or `target` domain finds no alive process, the error only
said that no process could be found. Make it clear that the plugin was
not enabled/disabled in any process in that case. Also stop mentioning
the "selected" target because the target comes from the command's
execution context.
Assisted-by: Claude Code
[libc][regex] Harden ExprPool, nullable, and pmatch (#243882)
Evaluating nullable() recursively can blow small stacks on embedded and
GPU targets when a pattern contains a long chain of anchors. Store a
4-bit anchor truth table inside Expr (keeping it at 16 bytes) so
nullable() runs in constant time with no recursion.
ExprPool also used an unseeded hash table with linear probing, letting
crafted patterns cause long collision chains. Mix heap and stack
addresses into a per-pool seed during initialisation and switch to
triangular probing. Narrowing node_count to ExprId frees 4 bytes for the
seed, keeping ExprPool at 72 bytes.
In NDEBUG builds, stripping assertions left invalid ExprIds and ByteSet
indices unchecked. Add runtime bounds checks across ExprPool and the
matcher, and reject unknown anchor bits before interning.
In regexec, a match previously left caller-provided pmatch arrays
unchecked and uninitialised. Check pmatch for null when nmatch is
[9 lines not shown]
RuntimeLibcalls: Mark noreturn and pure helper libcalls
Mark the functions which never return as noreturn. Add some nounwind
and cold, mostly following inferLibFuncAttributes. Mark
misc. functions as pure.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes inferLibFuncAttributes gives libcalls
Remove more differences with the attributes the InferFunctionAttrs
pass would add to the declared libcalls.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[LAA] Skip undef/poison strides behind integer casts. (#244395)
collectStridedAccess only rejected undef/poison strides when the stride
itself is undef/poison. If the stride is an integer cast of
undef/poison, the undef/poison value is still recorded as symbolic
stride, and users crash trying to walk its (non-existent) use-list.
Check the stride with casts stripped instead.
Fixes https://github.com/llvm/llvm-project/issues/241518.
[LLDB] Use the command's execution context target in plugin commands
`plugin list`, `plugin enable`, and `plugin disable` used the command
interpreter's selected target for the `target` domain. That's wrong when
the command's execution context has a different target, e.g. when the
command is run from a breakpoint callback or via
`SBCommandInterpreter::HandleCommand()` with an `SBExecutionContext`.
Use the target from the command's `m_exe_ctx` instead.
Also rename the `selected_target` parameters to `target` because the
target isn't necessarily the selected target.
Assisted-by: Claude Code