[ConstantFolding] Add constant folding for strlen (#244183)
This patch adds constant folding of `strlen` on a string literal. These
are not uncommon, for example coming out of code like
```
std::string s = foo();
if (s == "bar") { ...
```
This patch (plus a follow-up one which exposes libfunc folding to inline
costs) helped resolve a 3% regression in a SPEC2026 benchmark coming out
of disable-pre-lto-vec changes.
netipsec: Apply the rest of a bundle when the PMTU check finds no SA
ipsec{4,6}_check_pmtu() looks up the SA of the last request of a policy to
learn the path MTU. When that request is at level "use" and no SA is
found for it, the lookup returns EJUSTRETURN, and ipsec4_common_output1()
and ipsec6_common_output() took that to mean that the packet needs no
IPsec processing. That holds for a policy with one request. For a bundle
it also skipped the requests before the last one, for example the ESP
tunnel request of "esp/tunnel/A-B/require ah/transport//use", and the
packet was sent without their transforms.
The lookup finds no SA when none is installed, and also when the last
request is a transport request that follows a tunnel request, as in the
example. The lookup fills in the empty addresses of a transport request
from the packet as it is before any transform, while the transform applies
the request after the tunnel request, to the outer header, and the SA is
installed for the addresses of the tunnel. So the bundle above was sent
without its transforms even with an AH SA from A to B in place.
[21 lines not shown]
[PowerPC] fix `ppc_fp128` `FABS` miscompile (#209286)
fixes https://github.com/llvm/llvm-project/issues/209034
On little-endian powerpc the bit position of the sign bit is bit 63, not
bit 127. However, `APFloat` reports that the sign bit is the MSB. As I
understand it, it is actually right about that because in the `APFloat`
internal representation the sign bit is in fact in the MSB, but using
this information for runtime values is incorrect for LE.
All three fix locations are required to get the correct output for this
reproducer.
I'm assuming there are more ways that this can fail, so a more
structural solution would be neat. I don't know how to do that though,
so in the meantime we can accumulate test cases and plug the gaps.
[libc++][pstl] Add a task scheduler based on std::thread (#237313)
This PR adds a simple task scheduler for PSTL.
With that, `std::execution::par` makes algorithms run in parallel on
non-Apple platforms (Apple platforms keep using `libdispatch`).
The implementation uses only the threading facilities provided by the
C++ Standard and contains no platform-specific code.
This code is intended to be a replaceable implementation detail of
libc++, which is not exported and can only be accessed via the
`std::__pstl::__statpart::__apply()` proxy.
The design prioritises correctness and simplicity over peak performance,
while still performing reasonably for typical usage (comparable to
`dispatch_apply_f()` from GCD).
[SPIRV][Offload] Implement `DynSharedMemory` for L0 (#231160)
This PR implements SLM for Level Zero backend. Every kernel in a module
lowered by the new SPIR-V pass receives a trailing `__local` argument,
including kernels that do not use SLM.
In order to support existing code that uses offload, the PR adds an
additional pass to SPIRV backend. The idea is that the pass is searching
for all extern unsized workgroup arrays and then it converts them to a
global variable that is initialized by an additional kernel argument to
every kernel in the module, including kernels that do not reference the
array.
The pass closes the gap between cuda/hsa and level_zero handling of the
dynamically sized workgroup memory, because level_zero (and openCL) only
support the local memory sized through kernel arguments compared to cuda
which configures it during kernel launch. It was inspired by existing
code in intel's fork of llvm.
[9 lines not shown]
[DAG] SimplifyDemandedVectorElts - add ISD::VECTOR_SHUFFLE_VAR handling (#244921)
Simplify the demanded elements of the mask operand using DemandedElts,
and use the mask's constant range to limit the demanded source elements.
The InstCombine part is in #245249.
Fixes #244310
AI Note: I've used Claude Code to help me understand `SelectionDAG`
concepts and the codebase. The implementation and tests are my own.
[X86] Fix miscompile of srl(xor(y, vecreduce_umax(x)), bw-1) (#244835)
In the signbit reduction fold added in #210281, `X` is initialized to
`N0` as the fallback for a failed `m_Not` match, but `sd_match`
overwrites `X` while trying the `xor` operands, even when the match
fails. If the last operand tried is `vecreduce_umax(x)`, the `xor` is
dropped and the shift is lowered to a `MOVMSK` test of `x`.
Set the fallback only after the match fails.
Fixes #244613
Fixes #244753
Assisted-by: Claude Opus 5.5
[DAGCombiner] Bail out in MatchLoadCombine when no bytes come from load (#244857)
Since #200247, calculateByteProvider returns ConstantZero for bytes
masked by AND with 0. This could make `Loads` empty in MatchLoadCombine
and triggers assertion.
Fix by early return when `Loads` is empty.
Fixes: https://github.com/llvm/llvm-project/issues/244804
Assisted-by: Claude Opus 5.5 <noreply at anthropic.com>
[NFC][ExecutionEngine] Fix calloc argument order in jitprofiling.c (#245189)
calloc takes (nmemb, size); the arguments were swapped. No functional
change, but it silences -Wcalloc-transposed-args on newer compilers.
---------
Co-authored-by: Claude <noreply at anthropic.com>
acpi: Tasks: Ensure taskqueue is running before allowing to drain
In AcpiOsWaitEventsComplete(), fix the test controlling whether to call
taskqueue_drain_all(): That must happen only if threads to process the
taskqueue have been created.
In the initial code, there is a very small window where
'acpi_boot_tasks_nb' could be 0 but some task was concurrently enqueued
(e.g., by an interrupt), leading to a call to taskqueue_drain_all()
which would wait forever in the absence of threads processing the
taskqueue.
Reported by: llm-postcr
Sponsored by: The FreeBSD Foundation
[MLIR][OpenACC] Keep private stores of array reductions on one lane (#245438)
Two fixes in the acc-cg-to-gpu lowering of privatized arrays:
- The walk that finds the acc.private_local behind a memref followed
every operand of the defining op. A memref.reinterpret_cast whose
dynamic sizes come from a different private descriptor was therefore
attributed to that descriptor. Scalar operands (sizes, strides, offsets,
indices) only shape an access, so the walk now follows only the view
source, the base entity of a partial access, or non-scalar operands.
- The per-thread partials of an array reduction are combined across the
accumulate's thread dimensions. Storing the reduction identity is safe
on every lane and initializes each partial. Any other store into a
partial is an update, and it is no longer made active on every thread:
it stays on one lane. Previously such an update ran on every lane, so
its contribution was combined once per lane.
[VPlan] Tighten usecase of findRecipe (NFC) (#236810)
Rename findRecipe to findUserRecursively for clarity, noticing that it
is only ever necessary in epilogue-based reasoning, which falls outside
VPlan modeling. Migrate one user to getSingleUser, and improve code
around remaining two users that do epilogue-based reasoning.
misc/hermes-agent: remove the venv's lib64 symlink
CPython's venv creates lib64 as a symlink to lib on 64-bit. The
plist is built with find -type f / -type d, which never enumerates a
symlinked directory, so check-plist reports the path as orphaned --
and an @dir entry for it fails the type comparison, so it is then
reported as both orphaned and missing.
The symlink is a pure compatibility alias: the wrapper invokes the
venv interpreter directly and the stdlib resolves to lib. Remove it
in do-install alongside the other unneeded venv artifacts.
PR: 300998
[LV] Increase test coverage of FOR-tail-folding (#238318)
Fix missing test coverage for the case when first-order-recurrences have
no in-loop users in the tail-folding case.
Assisted-by: llm
[LLD][ELF] Always finalize a .symtab_shndx section. (#245334)
The SymtabShndxSection::isNeeded depends on the number of Output
Sections. In removeEmptySyntheticSections isNeeded may return true, but
later after adjustOutputSections the number of Output Sections can drop
to below SHN_LORESERVE, meaning that finalizeSynthetic will skip the
SymtabShndxSection::finalize.
This results in a redundant .symtab_shndx section with a sh_link of 0,
which prevents the ELF file from being used by some tools including lld.
Removing the Output Section containing .symtab_shndx after
adjustOutputSections is possible, but requires quite a lot of extra code
that handles edge cases that might happen with a linker script to be
repeated.
For now, always run the finalize when we are going to write the
.symtab_shndx section, which will produce a redundant, but benign extra
section.
fixes: #244372
[GVN] Treat possibly overlapping `lifetime.start` as a clobber in MSSA-path (#245978)
Mirroring 5f88e49e8c24c5b799872b4331d35b5406d3c213, ensure that a
`lifetime.start` that partially or possibly overlaps the memory location
of the load being analyzed is treated as clobber in the MSSA-based walk
as well. A PartialAlias overlap may be handled as a definition in the
future.
[lldb][test] Cache the result of _get_macos_sdk_version (#245955)
_get_macos_sdk_version runs 'xcrun --sdk macosx --show-sdk-version' on
every call. It is called for every decorator evaluation on macOS, so
loading a test file spawns one xcrun process per decorated test method.
For example, loading TestConstStaticIntegralMember.py runs xcrun 30
times, which takes ~0.5s on a good day.
The SDK version can't change during a test run, so cache the result.
assisted-by: claude