[RISCV][P-ext] Promote i32 sati/usati intrinsics to i64 on RV64. (#234346)
Instead of using p(u)sati.w. The trade off here is that p(u)sati.w
sometimes requires its output to be sign extended for ABI or compares.
While sati/usati sometimes requires its input to be sign extended
if it isn't a W instruction or an argument/return with the signext
attribute.
The sign extended input is what we would get a from a manually
written clamp pattern in C code. So there's an argument for
consistency.
It might be possible to have RISCVOptWInstrs convert to p(u)sati.w
if we aren't able to remove the sext.w from the input and only
the lower 32 bits of the result are used.
[ci] Add a workflow to run the LLVM test-suite
This adds a reusable workflow that builds and installs Clang at a given
commit, builds and runs the LLVM test-suite and creates a LNT v5 report.
The pipeline workflow can be dispatched manually or through the GitHub
API -- in the future we can trigger it via a cron job or a fancier system
like libc++'s.
Assisted by Claude
[MemProf] Handle indirect tail calls in missing frame search and ICP (#236256)
Enable cloning of indirect tail calls. Like other tail calls, the
profiled contexts will miss this frame. Set the tail call bit on the
summary edges synthesized from profile metadata to enable the thin link
tail call search to look through them and synthesize callsite records.
In the ThinLTO backend, perform ICP of these indirect tail calls using
those synthesized callsite records, to enable calling the assigned
clone.
Assisted-by: Gemini
[Bazel] Add TargetParser unit tests (#235040)
Adding support for running the existing TargetParserTests on Bazel
(previously only supported in CMake).
Changes were written manually and reviewed by Codex GPT-6.1 Sol.
[BPF] Fix crash on unused results of CO-RE builtins (#236311)
If the result of __builtin_preserve_field_info(),
__builtin_preserve_type_info() or __builtin_preserve_enum_value() is not
used, e.g., for bpf.c:
```
enum E { A = 4 };
void f(void) { (void)__builtin_preserve_enum_value(*(enum E *)A, 1); }
```
'clang --target=bpf -O2 -g -c bpf.c' crashed in BPFAbstractMemberAccess.
Such a call is collected for relocation through its users only, so a
call whose result is not used is not relocated and is left for
removePreserveAccessIndexIntrinsic(). There, it was handled as a
preserve_struct_access_index() call and replaced with a GEP of its first
argument, which is not a base pointer for these intrinsics.
These intrinsics have no side effects, so just remove such calls.
Co-authored-by: Yonghong Song <yonghong.song at linux.dev>
[libc] Declare tcsetattr's termios as const (#236514)
POSIX takes a const struct termios pointer in tcsetattr, and the
implementation already does. Only the declaration in termios.yaml
disagreed, so the generated header rejected a call passing a const
pointer
AI disclosure: this patch was written with Claude Code. I reviewed the
change and checked the declaration against the implementation. There is
no test since only the generated declaration changes
Assisted-by: Claude
[DebugInfo] Salvage replaced urem & srem instructions (#234224)
When `correlated-propagation` removes urem and srem instructions, it
doesn't correctly salvage the debug info. This leads to variables having
incorrect debug info. This patch makes sure we salvage the debug info
before removing the instructions
(See https://github.com/llvm/llvm-project/issues/218631 &
https://github.com/llvm/llvm-project/issues/218633)
[flang][Semantics][Lower] Lower explicit-shape arrays declared with rank-1 integer array bounds (F2023 R818) (#215403)
Part 3 of 3 implementing F2023 explicit-shape-bounds-spec, where a rank-1
INTEGER array of constant size supplies all the bounds of an explicit-shape
array, e.g. `real :: a(n)` or `a(lo:hi)` with rank-1 n/lo/hi declaring an
array of rank size(n). Parts 1 (#188447) and 2 (#203030) added the parsing
and the semantic representation; this part adds lowering, the module-file
round trip, and the folding needed for the feature to be usable end to end.
Executable coverage is in llvm/llvm-test-suite#411.
Representation. Semantics expands such a declaration into one ShapeSpec per
dimension. A bounds array that folds to a constant is folded into ordinary
per-dimension constant bounds at declaration, exactly as if dims(1),dims(2),...
had been written, so every consumer that reads a bound with ToInt64()
(EQUIVALENCE offsets, LBOUND/UBOUND folding, static-shape lowering) sees the
same ShapeSpec the ordinary syntax produces. A non-constant bounds array is
wrapped per dimension in a scalar evaluate::RankOneBoundElement that extracts
element [dim] from the shared rank-1 base; the wrapper is left unfolded so the
module-file writer can emit the original whole-array bound. ArraySpec records
[50 lines not shown]
[Reland][Offload][Omp] Compute getBlockLimit through liboffload (#236559)
Add two new device properties accessible through liboffload:
LAUNCH_MAX_NUM_WORK_GROUPS (max blocks) and LAUNCH_MAX_GRID_SIZE (max
total work-items). Using them compute the getBlockLimit in libomptarget
in a backend agnostic way.
Remove getBlockLimit from the Plugin Interface as it's no longer needed.
Assisted by Claude.
[bazel][lldb] Add the first lldb unit tests (#232715)
Start modeling lldb/unittests in the bazel overlay with the
TestingSupport helper libraries (lldbUtilityHelpers, lldbHostHelpers)
and the unit tests that only need lldb's base libraries: UtilityTests,
HostTests, HostCommonTests, SignalsTests and EditlineTests. The
remaining tests follow in later changes.
There are already tests for llvm folder's binaries with bazel:
https://github.com/llvm/llvm-project/blob/c7da05f9828542daaf634a6f4277212b5f6194d5/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
Test names and dependencies mirror the add_lldb_unittest() calls in the
CMake build, so the two are easy to keep in sync.
Several lldb unit tests read files through
lldb_private::GetInputFilePath(), which looks in an Inputs/ directory
next to the test binary. CMake's add_unittest_inputs() copies them
there; this does the same with copy_file, so the inputs land beside the
test binaries in the runfiles tree.
[12 lines not shown]
[lldb] Return llvm::Error from GenerateWatchpointCommandCallbackData (#235985)
Propagate the error from GenerateFunction instead of a bool, so a
malformed Python one-liner reports the real error instead of "failed to
generate watchpoint callback".
```
(lldb) watchpoint command add -s python 1 -o 'def ('
error: SyntaxError('invalid syntax', ...)
```
Assisted-by: Claude
feat(gisel): Mirror trunc/xor/select demanded bits
Extend scalar demanded-bits simplification to G_TRUNC, G_XOR, and
G_SELECT, following SelectionDAG traversal, known-bit propagation,
shared-use handling, and final folds. Honor GISel legality and target
profitability when rewriting or narrowing operations.
Share AArch64's logical-immediate search through a narrow XOR hook and
adapt XOR/shift profitability queries for both selectors. Preserve
SelectionDAG's constant-shrinking interface and node construction.
Validate TRUNC(LSHR) shift amounts with the existing
GISelValueTracking::getValidShiftAmountRange.
Preserve recursive constant bypasses and use-specific rewrites of shared
producers. Recognize constants at the analysis depth limit, matching
SelectionDAG, and retain KnownBits-based bypasses as a fallback.
Keep G_ASHR of G_SEXT_INREG arithmetic unless the top C + BW - W bits are
[5 lines not shown]
[offload] Add direct-write memcpys to liboffload and implement them on AMDGPU
Let olMemcpy transparently use direct H2D writes. These are unordered
with respect to currently enqueued operations, so only employ them if no
queue is given. The direct transfers are not unordered with respect to
operations that get enqueued afterwards, since they will be completed
upon completion of the corresponding olMemcpy call.
The AMDGPU implementation is a transfer of the ROCr/HIP implementation.
It more or less boils down to a std::memcpy with fences around it.
Claude assisted with this patch.
[sanitizer_common][test] Limit signal_segv_handler test time (#236538)
The test runs 1,000,000 iterations of mprotect + SEGV. On slow software
emulators (e.g. QEMU TCG for arm/aarch64), this can take several minutes
or exceed the 600s test timeout. Check elapsed time every 1,000
iterations and stop after 10 seconds.
Assisted-by: Gemini
[SPARC] Pass the optimization level to the instruction selector (#235249)
SparcDAGToDAGISel is constructed without an optimization level, so
SelectionDAGISel uses the default and the DAG combiner runs as it does
at -O2 even when compiling with -O0. Among other things it then drops a
store that is overwritten by the next one, so a variable assigned twice
has no instruction for its first assignment and a debugger cannot stop
there or see the first value. clang -O0 is not affected because it marks
functions optnone, but rustc and llc -O0 are.
Pass the target machine's level, as RISC-V does.
Fixes #235236
Assisted-by: Claude Code (Claude Opus 5.5)
[libc][math] Implement double precision tanh correctly rounded to all rounding modes. (#235618)
- Evaluate `tanh(x) = 1 - (2 * m) / (e^u + m)` for `|x| >= 2^-3` using
shared exp range reduction and lookup tables from `exp_utils.h` and
`exp2_accurate_128.h`
- For `2^-27 < |x| < 2^-3`, use a degree-5 minimax polynomial in `x^2`
with exact leading cubic split in the fast pass, and a degree-11 minimax
polynomial in Frac128 in the accurate pass.
- Add a no-LUT (N = 0) sinh(x) / cosh(x) evaluation when
`LIBC_MATH_HAS_SKIP_ACCURATE_PASS` is enabled.
Assisted-by: Gemini for analysis and refactoring.
[llvm] Add ELF.def to the module map (#236541)
Follow-up to https://github.com/llvm/llvm-project/pull/236143, which
added the file without listing it. Fixes "expected identifier" errors at
the `ELF.def` include in `ELF.h` in modular builds.
@aengelke Hi there, could you sign this off please?
[AArch64] Disable MADD combine for Apple targets (#235345)
The combine has been introduced by
https://github.com/llvm/llvm-project/pull/231356.
I measured the 2 forms on Apple silicon and the original form performs
better.
[lldb][OpenBSD] Fix sysctl usage for process info (#122534)
The OpenBSD Host code used FreeBSD-style sysctl MIBs, which don't
match OpenBSD's interface, so process lookups failed.
- GetOpenBSDProcessArgs: use {CTL_KERN, KERN_PROC_ARGS, pid,
KERN_PROC_ARGV}. OpenBSD returns a NULL-terminated argv array
whose pointers point into the returned buffer, so iterate it
directly.
- GetOpenBSDProcessUserAndGroup, FindProcessesImpl: KERN_PROC
takes a 6-element MIB on OpenBSD, with the kinfo_proc element
size and element count as the last two entries.
(cherry picked from commit b880f44cbad751b0784a5fbbfbdaacea25e167f8)
[RISCV] Correctly restore libcall CSRs with SCS
Fixes #233318
Before this change, we were restoring some callee-saved registers twice
when using save/restore libcalls with shadow call stack (SCS), and the
second restore was happening after the stack was deallocated using the
wrong register and offset calculation, which was causing lots of access
problems.
The problems were:
- We were using the entire list of Callee Saves rather than just the
subset that would have been restored by the libcall. This caused
duplicate restores because of how the CSI subsetting works.
- We were not using the correct offset calculation in
eliminateFrameIndex, which was causing us to calculate the wrong
address for the saves/restores.
Assisted-by: AI
Co-authored-by: Mitch Briles <mitchbriles at gmail.com>
[RISCV] Ensure Shadow Stack checks correct RA
This primarliy applies to the save-restore case, which was using
`__riscv_restore_<N>` incorrectly, entirely circumventing the software
shadow call stack.
This fix keeps the code size improvements of `__riscv_save_<N>` when
there is a shadow call stack, but it avoids the incorrect use of
`__riscv_restore_<N>`, instead emitting the correct sequence inline.
In the future, when there are better versions of `__riscv_save_<N>` and
`__riscv_restore_<N>` which support the shadow call stack variants (both
hardware and software), then we can revisit this approach and use the
correct pairs in all cases.
[SystemZ][z/OS] Alias for a function needs reference to ADA
When emitting function aliases, the current code misses to set the
reference to the ADA. Thus, the ADA register is 0 in the called
function, causing a crash e.g. when another function is called.
Fix is to set the references to the ADA.
Assisted by: IBM Bob
[AMDGPU] Precommit tests for ordered XDL VA_VDST waits (#233712)
Add MIR tests for VA_VDST waits in gfx1250 expert scheduling mode around
XDL instructions, covering wide and narrow destinations, mixed TRANS,
XDL and core VALU events, matrix scale, partial and explicit waits, and
CFG merges. The checks show the current conservative waits.