[flang][cuda] Defer on_device() folding in host copies of OpenACC routines (#208125)
Add a `defer-acc-routines` option to `cuf-function-rewrite`. When set,
`on_device()` is not folded in the host copy of an OpenACC routine (has
`acc.routine_info`, not in a `gpu.module`), because that body is later
cloned into the device routine and would otherwise bake in the host
value (`.false.`). A later run folds each copy in its own context. Calls
already in a `gpu.module` are still folded.
BPF: Remove unnecessary isReg check on phi operand (#208243)
These must be a register. This pass has quite a lot of
defensive code against invalid MIR that should be deleted.
[mlir][linalg] Fix mask rank for masked contiguous `tensor.extract` (#206207)
### Summary
Note: This fix was made mostly by Claude based on a failure case in
IREE. It addresses issue
https://github.com/llvm/llvm-project/issues/206209
When `vectorizeTensorExtract` lowers a `tensor.extract` recognized as a
*contiguous load*, it builds a `vector.transfer_read` whose permutation
map broadcasts the leading iteration dims and only reads the trailing
`min(dstRank, srcRank)` dims of the source. Until now this read was
returned unmasked and masked later by the generic path, which applies a
**full iteration-space identity mask**. When the source rank is smaller
than the loop nest, that mask is over-ranked relative to the
(rank-reduced) read — e.g. a `vector<1x4xi1>` mask on a read whose
inferred mask type is `vector<4xi1>` — and the op fails verification:
```
[65 lines not shown]
[offload][OpenMP] Improve cross-team reduction grid selection
The default cross-team reduction algorithm benefits from larger and
fewer teams. Implement that by using 2 x the default number of threads
and 1/2 x the default number of teams for reduction kernels. This
doesn't change the default total number of threads, it just
redistributes them.
This is a first, rather simple heuristic, derived from (a subset of)
what AOMP does.
The performance benefits I observed for the reduction tests in
https://github.com/ro-i/xteam-test on a gfx942
(c71339705091500f731e2a39f247d2660bacbdce) are up to a few percent, with
no regressions.
Claude assisted with this patch.
[flang] add some missing stackrestore with -fstack-arrays (#208161)
In the StackArray pass that moves array temporaries from the heap to the
stack under -fstack-arrays, when visiting FreeMemOp to insert
stackrestore, the code was not unwrapping converts as done in other
parts of the code leading to the allocation conversion and stacksave
insertion to happen without the emission of the stackrestore.
Reuse the same utility as in the rest of the pass to get consistent
behavior and fix the memory leak.
[CIR][test] Use global instcombine RUN line in AArch64 neon subtracti… (#207894)
Related to https://github.com/llvm/llvm-project/issues/185382
Follow-up to https://github.com/llvm/llvm-project/pull/207115
Include `instcombine` into the global LLVM RUN line and remove the
separate `LLVM-IC` prefix that only covered the narrowing-subtraction
tests in `clang/test/CodeGen/AArch64/neon/subtraction.c`.
Update LLVM CHECK to match the `instcombine` output: bitcast checks are
dropped, the inferred `nsw` flags are added on the widening subs, and
unused shuffle operands are canonicalized to `poison`.
BPF: Fix misfolding subregisters
This would end up introducing a copy between registers
with mismatched sizes previously. Defends against verifier
failures in a future change.
The actual transform here should be deleted. Optimizations should
not be trying to introduce SUBREG_TO_REG.
[AggressiveInstCombine] Factor out the common part of tryToRecognizeTableBasedCttz and tryToRecognizeTableBasedLog2. NFC (#208123)
They both start with the same GEP+load matching.
Assisted-by: Claude
BPF: Remove unnecessary isReg check on phi operand
These must be a register. This pass has quite a lot of
defensive code against invalid MIR that should be deleted.
[clang][Serialization] Deduplicate loaded header-unit SLoc ranges
Header units that textually include the same large header used to consume loaded SourceLocation address space independently, even when the serialized file contents were identical. Importing many such header units could therefore run out of the loaded SLoc region long before the translation unit was large in any meaningful source sense.
Use the eager SLoc dedup metadata to share already-loaded file ranges when a later header-unit PCM contains a matching dedupable file entry. The reader now builds a per-module remapping from serialized local offsets to the global SourceManager offsets actually used for the import. Fresh entries are packed into the module's allocation, while duplicate file entries map back to the canonical FileID and offset range from the first loaded PCM.
This changes the module-loading model from a single base-offset translation for every loaded location to a segmented translation for PCMs that participate in deduplication. Modules without dedup metadata keep the existing single-add fast path. The SourceManager loaded-entry table only receives slots for entries that are actually allocated, and serialized local FileIDs are remapped to their canonical loaded FileIDs when a file range is shared.
The result is that repeated textual headers in header units no longer multiply loaded SLoc address-space usage when the flag is enabled, while the default path and PCMs without the new metadata continue to load as before.
[AMDGPU] Reimplement icmp and fcmp builtins using ballot (#208231)
Use `llvm.amdgcn.ballot` instead of the deprecated intrinsics
`llvm.amdgcn.icmp` and `llvm.amdgcn.fcmp`.
[cmake] FindLibXml2: fall back to xmlversion.h when pkg-config has no… (#207797)
… version
LLVM's cmake/modules/FindLibXml2.cmake uses PC_LIBXML_VERSION (from
pkg-config) as the VERSION_VAR in find_package_handle_standard_args.
When pkg-config has no libxml-2.0.pc file (e.g. when linking against a
static libxml2-pic.a that ships no .pc file), PC_LIBXML_VERSION is left
empty after pkg_check_modules fails and the >=2.8 version check reports
'Found unsuitable version ""', causing LLDB_ENABLE_LIBXML2 to be set to
FALSE.
Fix: before calling find_package_handle_standard_args, check whether
PC_LIBXML_VERSION is still empty and if so read LIBXML_DOTTED_VERSION
from the xmlversion.h header. This mirrors the version-detection logic
in the system CMake FindLibXml2 module and ensures LLDB is built with
libxml2 support on installations that use a static libxml2 without a .pc
file.
[lldb] Fix assert when `target frame-provider register` succeeds (#208232)
`CommandObjectTargetFrameProviderRegister::DoExecute` never called
`CommandReturnObject::SetStatus()` on its success path.
`CommandObject.cpp` has a `DoExecuteStatusCheck` RAII guard that resets
the result's status to `eReturnStatusInvalid` before `DoExecute` runs,
and asserts on exit that `DoExecute` changed it.
`AppendMessage()`/`AppendMessageWithFormatv()` don't touch status
(unlike AppendError()/SetError(), which call
`SetStatus(eReturnStatusFailed)`), so on the success path the status
stayed eReturnStatusInvalid, tripping the assert.
This went unnoticed because every existing `scripted_frame_provider`
test uses `SBTarget::RegisterScriptedFrameProvider` directly, bypassing
the `target frame-provider register` command entirely. Add a regression
test that exercises the command instead.
Assisted-by: Claude
Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
[clang] Use DynamicRecursiveASTVisitor for AST listing (#202661)
Replace `ASTDeclNodeLister`'s CRTP `RecursiveASTVisitor` with
`DynamicRecursiveASTVisitor` while keeping `ASTPrinter` and
`ASTDeclNodeLister` separate. Set `ShouldWalkTypesOfTypeLocs` to false
to
preserve the previous traversal.
In identical arm64 release builds, standalone clang shrinks by 251,840
bytes
(0.215%), stripped clang by 149,488 bytes, and `ASTConsumers.cpp.o` by
153,352
bytes; linked `__TEXT` falls by 147,456 bytes and linked fixups increase
by
1,040.
The `-ast-list` output is byte-identical on the existing clang-check
input and
`ASTConsumers.cpp` (150,918 lines); two reversed-order ten-run timing
[6 lines not shown]
[libc++][pstl] Default implementation of parallel std::find_first_of (#206328)
This PR adds a default "one-liner" implementation of parallel
`std::find_first_of` expressed as a call to `__find_if`.
The implementation is based on find_if and any_of.
Part of #99938
[RISCV] Avoid let statements in RISCVSystemOperands. NFC (#207890)
Add an optional RV32Only operand to SysReg.
Add AltSysRegName and DeprecatedSysRegName wrappers.
[SelectionDAG][X86] Replace OriginalDemandedBits with DemandedBits in SimplifyDemandedBits ISD::PDEP handling. (#208104)
DemandedBits is set to all 1s if the node has multiple uses.
Fixes regression from #204144. The changed test case reverts back to the
output before that change.
[flang][acc] Emit acc.on_device operation for acc_on_device call
It is important we recognize acc_on_device calls as they need to be
folded during compilation. Emitting this operation helps with the
recognition of the runtime call in the optimizer.
[libc] Move fcntl implementation into the syscall_wrappers layer (#207878)
linux_syscalls::fcntl called SYS_fcntl unconditionally, breaking the
riscv32 full build where only SYS_fcntl64 exists. The syscall selection
and command translation already lived in internal::fcntl, so move that
implementation into syscall_wrappers/fcntl.h, delete the legacy
OSUtil/fcntl.h and OSUtil/linux/fcntl.cpp, and port the callers (fcntl
entrypoint, file.cpp, dup2.h) to linux_syscalls::fcntl.