[LV] Add cost printing test with forced instruction costs (NFC). (#222895)
Add a test printing the cost of all recipes in the vector loop region
with -force-target-instruction-cost. Currently the flag is ignored for
VPDerivedIVRecipe and VPScalarIVStepsRecipe.
[libsycl] USM Aligned allocation functions (#213468)
Adds the `aligned_*` versions of the USM functions, specifically for the
`device` `host` `shared` and free standing `aligned_alloc`.
Most of the overloads delegate between each other, but they slowly end
up being mapped to `aligned` version of API.
Adds more LIT tests in `alloc_functions.cpp` to cover the aligned
version.
Adds unittests for USM in `usm/alloc.cpp`
Assisted by AI for documentation, validation of logic in overloads and
alignment specifications from latest SYCL-Docs and unit tests
[AArch64] Cache repeated subtarget queries (NFC) (#222637)
The existing SubtargetMap caches subtargets using a key built from a subset of
relevant function attributes. Add a single-entry cache keyed by the full
function attribute set to avoid rebuilding that key for repeated queries. This
covers both repeated queries for the same function and queries for different
functions with identical attributes.
Improves CTMark geomean -0.10% on aarch64-O3 and -0.17 on aarch64-O0-g.
https://llvm-compile-time-tracker.com/compare.php?from=87d9c3c24ff5941ac08799850a6549b561c98a81&to=544bb3d9ac28bc1a28248f6b03bcd95fa85b20e0&stat=instructions:u
Assisted-by: codex
[LLVM][CodeGen][SME] Make FMA decision independent of streaming mode. (#222598)
The relevant bfloat instructions are available in streaming mode and
thus we can benefit from the same BFMLAL based lowering.
[libc] Implement pthread_kill (#222625)
The implementation delegates to Thread::kill, which uses tgkill to
target the thread ID.
The main complication is handling zombie threads. POSIX.1-2024 requires
that pthread_kill on a terminated (zombie) thread does not return ESRCH
because the pthread_t handle is still valid. The Linux kernel reaps
threads immediately on exit, so calling tgkill on an exited thread would
return ESRCH (or worse, target a recycled TID). To handle this:
- we check the thread's detach_state first. If it's already EXITING, we
simply return success without calling tgkill (a zombie thread cannot
handle signals anyway).
- if the thread exits concurrently and tgkill returns -ESRCH, we assume
it transitioned to a zombie and treat it as success.
I've also added a tgkill syscall wrapper and replaced one raw usage of
SYS_tgkill.
[2 lines not shown]
[libc++][test] Remove non-functional `constexpr` in three-way comparison test for `variant` (#222837)
When we are just testing SFINAE and do not provide definitions for these
comparison operators, or make them deleted, it is unhelpful to mark them
`constexpr`.
If the implementation uses `std::compare_three_way`, which uses deduced
return type in its `operator()`, in the `operator<=>` for `variant`,
more things in the function body would be instantiated and detected. As
a result, the `-Wundefined-inline` warning or something similar could be
raised. Currently, MSVC STL is doing so.
[lldb] Validate universal Mach-O slice bounds before parsing (#221493)
Opening a corrupt universal (fat) Mach-O file can crash lldb. A fat-arch
header entry's (offset, size) pair is untrusted, and `GetObjectFile()`
passes it straight to `ObjectFile::FindPlugin()` with no check against
the
container's own size.
A slice whose offset is 0 points back at the start of the same fat
header,
so `GetObjectFile()` recurses into itself until the stack is exhausted:
```
$ ./ObjectContainerTests --gtest_filter=GetObjectFileSelfReferentialSlice
#230 ObjectContainerUniversalMachO::GetObjectFile(FileSpec const*) ObjectContainerUniversalMachO.cpp:188
#231 CreateObjectFromContainer(...) ObjectFile.cpp:43
#232 lldb_private::ObjectFile::FindPlugin(...) ObjectFile.cpp:146
#233 ObjectContainerUniversalMachO::GetObjectFile(FileSpec const*) ObjectContainerUniversalMachO.cpp:188
(repeats until the stack is exhausted)
[22 lines not shown]
[AggressiveInstCombine] Require a definitive initializer for table folds (#222826)
tryToRecognizeTableBasedCttzOrLog2 accepted any global that isConstant()
and hasInitializer(), but isConstant() only means the value does not
change at run time -- it does not mean the initializer that is read is
the one that gets linked. An interposable (weak/linkonce) constant, or
an externally_initialized constant, can be replaced with a different
constant table at link or load time, so folding tbl[i] against the
observed initializer is unsound for those.
Assisted-by: Claude Code
[AMDGPU] Optimize i64 uitofp for unsigned byte values
Use v_cvt_f32_ubyte0 when the i64 source is known to fit in an unsigned
byte.
For example:
uitofp (and i64 %x, 255) to float
This avoids the generic i64 to f32 expansion.
[libc++][NFC] Simplify __to_gcc_order by avoiding constexprness (#220940)
We never make use of the fact that these functions are `constexpr`, so
we might as well avoid complicating them for it. Even if we need them to
be `constexpr` at some point, we likely won't require them to be
`constexpr` in C++11, which is the only language mode with the single
statement restriction that caused this to be more complicated.
[OMPIRBuilder] Don't leak a foreign debug loc into the taskwait call (#222586)
A kmp_depend_info array is hoisted to the entry block of the enclosing
function. Pointing the builder into that block also adopts the location
of what is already there, which belongs to whichever construct put it
there rather than to the construct being emitted. restoreIP does not put
the location back either, since it adopts the location of the
instruction it lands on, so in createTaskwait the leak outlives the
excursion and reaches the __kmpc_omp_taskwait_deps_51 call.
Use InsertPointGuard, which restores the location along with the
insertion point.
Fixes https://github.com/llvm/llvm-project/issues/222044
Co-authored-by: Cursor <cursoragent at cursor.com>
[libc++] Make _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE part of the locale base API (#219196)
Whether libc++ has to provide a rune table is really part of the
localization of a platform. Move it there instead of `<__config>`.
DAG: Materialize a directly-lowered gc.relocate in its own block
Fixes machine verifier errors with -early-live-intervals.
A NoRelocate statepoint value is a directly-lowered leaf value. When its
gc.relocate is in another block, it was made available by exporting it from the
statepoint's block. For an invoke this defines the vreg after the call, which
does not dominate the use reached along the unwind edge, giving an invalid live
range (or a silent read of an undefined register without -verify-machineinstrs).
Since the leaf has no chain or operands, rematerialize it at the gc.relocate
instead of exporting it. undef already rematerializes there. A gc.relocate
value is always a pointer, so only the integer-constant and frame-index leaves
are handled.
Co-authored-by: Claude (Claude-Opus-4.8)
[BOLT] Fixed BOLT edge weight estimation in non-LBR mode. (#222538)
Before: When estimating edge weights within `computeEdgeWeights` in
`MCF.cpp`, if the `TotalChildrenCount` is 0, the default edge weight is
`1 / (GraphT::child_end(BB)_ - GraphT::child_begin(BB))` resulting in
integer division and incorrect distribution of estimated edge weights.
After: Correctly estimate edge weights with zero and non-zero values of
`TotalChildrenCount` by enforcing floating point division.
---------
Co-authored-by: Thrrreeee <shijinrui at bytedance.com>
[VPlan] Narrow VPWidenGEPRecipe if only its first lane is used. (#221171)
Extend existing narrowing in legalizeAndOptimizeInductions, already
applied to VPReplicateRecipe and VPWidenRecipe, to VPWidenGEPRecipe as
well. This improves cases where an interleaved access's insert position
shares an address calculation with a strided access (see
RISCV/interleaved-load-masked-store.ll), which previously caused the
legacy cost model to classify the address as non-uniform.
[SLP] Limit second pass to register VF in vectorizeNonVectorizableInsts. (#222755)
The second tryToVectorizeList pass in vectorizeNonVectorizableInsts
would try all roots for each possible VF between 1 and the number of
entries in the list.
This can cause super-linear compile-time, for example when there are
basic blocks with calls taking a large number of loads as arguments.
For example, running SLPVectorizer on a block with 1024 loads passed to
calls (https://llvm.godbolt.org/z/8M53G6WzW) will take a large amount of
time (timeout on godbolt, locally on Apple M1 it takes ~30s). With the
fix, it only takes 0.01s.
On large IR corpus, I did not see any difference in vectorization
decisions on AArch64.
PR: https://github.com/llvm/llvm-project/pull/222755
[flang] Do not hoist fir.field_index out of loops
Lowering a consumer of a !fir.field value inspects its defining operation:
for a record whose layout is known at compile time the field becomes an LLVM
GEP struct index, which must be a constant, and otherwise the `field`
attribute is read off the defining op. A field value therefore may not be a
block argument.
LICM broke that. fir.field_index is Pure and takes no operands, so it is
trivially loop-invariant and was hoisted out of the loop. Lowering emits one
inside each arm of a construct -- for example the CASEs of a SELECT CASE that
each pass a different component of the same derived type as an actual
argument -- so hoisting them left those arms as otherwise-identical blocks
differing only in that operand. Block merging then merged them and threaded
the field through a new block argument, and codegen aborted with "must be a
constant".
Leave producers of a !fir.field where they are. The arms then differ by an
operation rather than by an operand, so they are no longer merge candidates.
[7 lines not shown]
[libc] Implement pthread_attr_[gs]etschedpolicy (#222682)
This patch implements pthread_attr_setschedpolicy and
pthread_attr_getschedpolicy.
This commit only operates on the pthread_attr_t object. It does not
attempt to install the scheduling policy when creating a new thread. I'm
leaving that for a separate patch as it requires a moderately
complicated startup dance to ensure that the scheduling policy takes
effect before the startup code runs.
The validation of inputs in pthread_attr_setschedpolicy is an
interesting question. Glibc accepts only policies explicitly declared in
POSIX, while other implementations let the user pass anything, and rely
on the kernel to validate the arguments. Interestingly, even glibc does
not validate the arguments in pthread_setschedparam.
For llvm-libc, I chose not to validate the arguments either. This is
*mostly* consistent with POSIX, which says (emphasis mine):
[11 lines not shown]