[TargetInstrInfo] Address review: don't fold a subregister that isn't at the start of the slot
A folded operand refers to the start of the stack slot, which holds the
whole register, so a subregister is only there if it's at bit offset 0 on a
little-endian target. Folding x86's sub_8bit_hi read byte 0 instead of byte
1. Folding several operands at once made this worse: two operands holding
different subregisters of one value (e.g. "Qm"(lo), "Qm"(hi)) both read
byte 0.
Check the subregister in mayFoldInlineAsmRegOp, so the spill weights agree
with what folds. A tied def is covered too, since its tied use has the same
subregister.
Assisted-by: Claude Opus 5.5
[SystemZ] Fix -Wunused-variable in bcb301d (#235171)
Variable ends up only being used in assertions afterwards which fires
-Wunused-variable in release builds.
[llvm-exegesis] Avoid instability from `std::uniform_int_distribution` (#234516)
The standard doesn't require a stable order, and we see active variation
between libstdc++ and libc++ when using this. Follow the pattern of
`llvm::shuffle` and manually clamp with `%` instead.
Also removes an unnecessary `REQUIRES` that gets this to run in
pre-merge CI.
Assisted-by: Antigravity with Gemini
[mlir][scf] add support for unsigned loop for back peeling (#234435)
- add support for unsigned loop for back peeling
- fix sub overflow bug in the signed path
- remove unsigned operation check in dispatcher
- return early if unsigned in `peelForLoopAndSimplifyBounds` since
affine.min/max does not hold for unsigned loops
- add tests for edge cases in unsigned, sub overflow and no bound
simplification for unsigned
from https://github.com/llvm/llvm-project/pull/231100
claude helped me with the tests and correctness.
[MSP430] Update msp430 generator (#228006)
- gen-msp430-def.py was updated to include the CPU type. Current CPU types are msp430, msp430x and msp430xv2. This is useful information for determining whether extended instructions are valid on a given target.
- Adds a new hwmult variant called f5series. The script now maps the HWMPY value of 8 to this variant. This is important because the f5series hardware multiplier has a different base address compared to older MPY32 support.
- Also added new tests with a newer target containing a f5series hardware multiplier. The auto mode will now also correctly map to include f5series support if the MCU supports this.
Based on https://reviews.llvm.org/D108301 by Jozef Lawrynowicz.
Co-authored-by: Jozef Lawrynowicz <jozefl.opensrc at gmail.com>
Assisted-by: Claude Code (Claude Opus 5.5)
[AMDGPU] Fix gfx9-4-generic LDS allocation granule
gfx9-4-generic paired gfx950's 1280-byte allocation granule with
gfx942's 64 KiB LDS capacity. A 64 KiB work-group then rounded to
66560 bytes, was deemed not to fit, and dropped occupancy to 1. The
resulting VGPR budget made 1024-lane dispatches fail.
Use gfx942's 512-byte granule, which matches the capacity.
Fixes LCOMPILER-3031.
Change-Id: Ic8d36fd0921a80abd0debaee1fb2c28cd01604d0
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[ConstraintElim] Split signed min/max across their operands when checking a compare
The existing constraint systems only record the bounds that hold for both
operands of a min/max (smax(a, b) >= a and >= b, smin(a, b) <= a and <= b). The
other direction is a disjunction, which cannot be recorded as a fact. When a
compare of signed decompositions involves a min/max result, split it into its
operands: the decomposition is monotonic in that result, so it is the max or min
of its values on each side, and the relation holds for all or for either side
respectively.
https://alive2.llvm.org/ce/z/zsGkJ-
[ConstraintElim] A signed sum of operands with opposite signs cannot wrap
If one operand is known non-negative and the other non-positive, the signed
sum is between them, so it cannot overflow.
https://alive2.llvm.org/ce/z/ZF5Yqr
[ConstraintElim] Prove sadd/ssub.with.overflow cannot overflow from the exact sum
Decompose the operands and show that the sum lies in the range of the type. This
handles patterns like A + (B - A), as well as sums involving signed min/max
results, which are split across their respective operands using monotonicity
(for example start + smax(end - start - 1, 0) <= end).
https://alive2.llvm.org/ce/z/ze8LCk
[ConstraintElim] Propagate the sign across an icmp samesign
If one operand of `icmp samesign` is known (non-)negative, so is the other. Add
that as a fact in the signed system.
https://alive2.llvm.org/ce/z/xUgGRM
[AMDGPU][Scheduler] Restore local spill rejection in occupancy mode (#233979)
When rematerializing for higher occupancy, the scheduler can retain a
schedule that introduces spills even when the saved order is spill-free.
The `!TargetOcc` guard disables local spill rejection. Since occupancy
is tracked using `max(WavesBefore, WavesAfter)`, global finalization can
still consider the target reached even when the trial schedule is worse.
The guard was introduced in 7cc7a9412893 (#180646) alongside a fix for
rollback using temporary `DBG_VALUE` placeholders. dc34d163d8c9
(#192443) replaced that representation with the shared MIR
rematerializer, removing the placeholder-specific slot-index issue.
Re-enable the existing `mayCauseSpilling` check in occupancy mode to
reject such trials and restore the instruction order saved before
rescheduling, while preserving rematerialization. Global finalization
still handles rematerialization rollback. Add a MIR regression that
spills before the fix and remains spill-free afterward.
[5 lines not shown]
RegAlloc: Fix dead flags of defs after failed allocation (#233796)
After an allocation failure, the error register may be assigned to
multiple defs of the same instruction. If one of these is dead and
another live, the instruction fails the verifier check added in #233110.
In RegAllocBase, add the failed defs to the error register's regunit
live ranges so a later assignment cannot also def it, and make the dead
flags of the error defs agree with any def already assigned the
register. In RegAllocFast, clear the dead flags of registers with a
live def on instructions using an error assignment.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[HLSL] Add the `SV_Barycentric` semantic (#233510)
Implements diagnostics, lowering and serialization of the
`SV_Barycentric` semantic for directx and spirv.
Resolves: https://github.com/llvm/llvm-project/issues/210786
Assisted by: ChatGPT Sol 6.1
[mlir][scf] Add scf.execute_region to the structural type conversions (#234405)
This change adds support for `scf.execute_region` to
`populateSCFStructuralTypeConversions`. `scf.execute_region` seems to be
an omission, so this change simply fills a hole.
Add `ConvertExecuteRegionOpTypes` (patterned after `ConvertIfOpTypes`)
to convert the types of `scf.execute_region` and add that to the list of
patterns in `populateSCFStructuralTypeConversions` and legality in
`populateSCFStructuralTypeConversionTarget`.
Also adds a unit test to check for type conversion in
`scf.execute_region`.
Assisted-by: Claude
RuntimeLibcalls: Fix signatures of fmin/fmax libcalls
These used Floating, which always lowered to float regardless of the
libcall type.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add signatures for simple FP libcalls
Add signatures for the FP arithmetic, fma, powi, fminimum/fmaximum and
sincospi libcalls, and for the conversions between f32/f64/f80/f128/
ppcf128 and i32/i64.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[CIR] Add 'loop-id' to loop and branch types. (#235052)
While working through the loop-hints lowering, I discovered that we need
a way to make each loop get a 'distinct' loop-annotation in LLVM-IR.
This relationship is lost during FlattenCFG when it splits to multiple
branches. #233890 adds this to the LLVM-IR dialect.
I considered/had a patch to do this to FlattenCFG as well, however when
working on further loop hints (parallel in particular), we need to be
able to spread this value inside of the loop itself, so it makes more
sense to generate the ID from the start.
I suspect this ID will come in handy outside of the loop-hints, so it is
left as a separate attribute.
[AtomicExpand] Let targets keep the release fence out of the reservation (#214867)
`expandAtomicCmpXchg` sinks the leading fence into
`cmpxchg.fencedstore`, between the load-linked and the
store-conditional. A strong cmpxchg recovers, because its retry
re-reserves after the fence. A weak cmpxchg has no retry, so where a
fence clears the reservation it can never succeed.
On a 32-bit PowerPC e500v2, `compare_exchange_weak` with any release
ordering never succeeds. One thread, an uncontended cell, a million
consecutive failures:
```
[atomic: compare_exchange_weak] NO PROGRESS after 1000000 tries in 2.28s
[atomic: compare_exchange] ok
[atomic: fetch_or + fetch_add] ok
```
`fetch_update` in Rust's core is a `compare_exchange_weak` retry loop,
[54 lines not shown]
RuntimeLibcalls: Use a single LibcallImpl for long double functions
Replace the per-format <func>l_{f80|f128|ppcf128} implementations with
a single <func>l implementaton. The concrete type is now derived from
the module/triple's LongDoubleFormat, so this is no longer a static
property.
On targets where long double is double, the l-suffixed functions do
not provide a libcall. This could be fixed in principle, but nothing
would use it in the compiler.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Emit signatures per libcall implementation
Index the signature table by RTLIB::LibcallImpl instead of
RTLIB::Libcall. RuntimeLibcallImpl inherits the signature of the
libcall it provides by default, but an implementation can now override
it. This will help avoid having multiple copies of the same libfunc
for every long double type.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Use explicit types for F80, F128 and PPCF128 libcalls
LDbl only makes sense for encoding the long double libm functions. Other
functions have need of the specific type. Separately, LDbl brokenly assumes
double instead of checking the module's long double format. Some functions
are inappropriately using a specific type instead of LDbl. I'll fix both
of these issues separately.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add signatures for atomic libcalls (#233601)
Define type signatures in tablegen for the various atomic
library functions.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>