[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
reuse known bits result with WithCache
The overloads feel like a bit of a hack, but we need them because ValueTracking
is much more strict about const than ConstraintElimination, and where we'd want
automatic conversion from WithCache<Value*>& to WithCache<const Value*>& we
can't even do it manually. See: https://github.com/llvm/llvm-project/pull/235158#discussion_r4449759101
[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
[lit] Specify endianness in `int.to_byte` (#239388)
Complement to #239364. Adds on other non-default argument to
`int.to_bytes`, which are needed for Python versions <= 3.10.
[llvm-diff] Compare function and call-site attributes (#238928)
Compare the function, return and parameter attributes and the calling
convention of the diffed functions, and of their call sites. Print the
attributes that are on only one side. This resolves the FIXMEs for
attributes and calling conventions.
AI-assisted.
RuntimeLibcalls: Add signatures for size returning new and GPU profiling (#238642)
__size_returning_new and its variants return __sized_ptr_t, a pointer
and size pair. The GPU profiling functions use the compiler-rt
prototypes.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[libc][sys/shm] Implement shmget syscall wrapper on Linux. (#239380)
`shmget` is a POSIX function (see
[docs](https://pubs.opengroup.org/onlinepubs/9799919799/functions/shmget.html#))
that returns a shared memory identifier created for a particular key.
On Linux, it can be implemented as a simple wrapper around `SYS_shmget`
syscall.
This is the first function from the newly added `<sys/shm.h>` header,
other functions / constants
will be added in the follow-up PRs.
[clang codegen] Fix MS ABI with deleted template constructor (#237634)
Under the Microsoft ABI, a class with a user-provided constructor cannot
be returned in a register. This check was fixed in 3ab4ae9e58c09 to also
handle template constructors. That fix missed a special case of the
special case: a deleted template constructor does not count as
user-provided.
Fixes #237188
[GlobalISel] Fold urem x, (shl pow2, y) to a mask (#238879)
Fixes #236466
This PR mirrors SelectionDAG's `OrZero` semantics to allow folding where
`d` is known to be a power of two or zero.
Prior to this, for a shift, `isKnownToBeAPowerOfTwo` only matched `1 <<
y` (which can only lose its bit where `y` is out of range, which is
poison), as shifting any other power of two may produce zero. Thus
`urem_pow2_to_mask` did not fire, and on AMDGPU GlobalISel fell back to
the full ~18 instruction division expansion whereas SelectionDAG
produces `x & (d - 1)`.
This patch adds an `OrZero` flag to `isKnownToBeAPowerOfTwo`, which now
recurses through `G_SHL`, `G_LSHR`, and `G_TRUNC` into the value being
shifted or truncated when said flag is set (or the result is known never
to be zero). The inclusion of `G_TRUNC` in this patch is necessary to
handle the `i64` case where `bypass-slow-division` truncates the
[7 lines not shown]
[ARM] Enable SlotIndexes compaction by default (#238515)
Greedy measures live ranges in slot indexes, and the entries left by
instructions erased before allocation make some ranges look longer than
they are. Opt ARM into dropping those entries, as was done for AMDGPU,
so allocation reflects the code actually being allocated.
The test updates are register assignment and spill placement changes.
[SelectionDAG] Add opcode class metadata to DOT nodes (#228965)
SelectionDAG DOT graphs only expose printed node labels, so tools cannot
reliably distinguish SelectionDAG opcodes from machine opcodes.
Add `llvm_opcode` and `llvm_is_machine_opcode` attributes to each node
without changing the rendered graph. Add X86 coverage before and after
instruction selection.
[Analysis] Allow WithCache<const T*> to bind by reference to WithCache<T*>. NFC
Much like how `T *` implicitly converts to `const T *`, we now allow the same
conversion when wrapped in a `WithCache<>`. To achieve this, `WithCache<T *>`
now derives from `WithCache<const T*>` so that a reference to the former may
bind to the latter while sharing the same cached KnownBits. Slicing across the
two types via a copy or assign is deleted, since that would duplicate the cache.
This should simplify adoption in passes like ConstraintElimination, where the
existing infrastructure within the pass uses `Value*` throughout, but the APIs
it calls in ValueTracking expect a `const Value *` by virtue of them taking a
`const WithCache<const Value *> &`.
[CIR] Match classic codegen for saturating fixed-point negation and padded conversions
Three CIR fixed-point paths diverged from classic codegen. Unary minus on a
saturating fixed-point type emitted a plain subtraction instead of a
saturating 0 - x. With -fpadding-on-unsigned-fixed-point, float to unsigned
fixed-point conversion produced the fptosi.sat result in an unsigned CIR
type, so its clamp to 0 compared as unsigned and never fired; it now
converts and clamps in a signed type, like llvm::FixedPointBuilder, and
casts to the unsigned type afterwards. A saturating fixed-point conversion
that kept the width but changed signedness returned a value of the source
CIR type, which broke the cir.cmp verifier and needed a pointer bitcast to
store; it now casts to the destination type.
Assisted-by: Claude Code (Claude Opus 5.5).
[CIR] Store nsw/nuw as an OverflowFlags bit enum and split out saturated add/sub
cir.add, cir.sub and cir.mul carried nsw and nuw as two separate unit
properties, and lowering mapped them to LLVM with an early return that
picked nuw over nsw, so an op with both flags lowered to `overflow<nuw>`
and lost nsw. cir.add and cir.sub also carried a `sat` flag that changed
the operation's result rather than adding a poison condition.
Store the flags as one OverflowFlags bit-enum property, mapped flag by
flag onto mlir::LLVM::IntegerOverflowFlags in lowering so both survive.
The property uses the default EnumProp syntax with a space separator,
printed as `nuw`, `nsw` or `nuw nsw` as in LLVM IR, so no custom parser
or printer is needed. cir.mul now shares the add/sub base class and so
becomes Pure.
Saturating arithmetic moves to new cir.add.sat and cir.sub.sat ops, which
lower to the signed or unsigned saturation intrinsics by element type.
cir::OverflowBehavior and its operators go away; createAdd, createSub and
createMul take cir::OverflowFlags.
[7 lines not shown]
[libc][docs] Check entrypoints and filter stubs in docgen (#238908)
docgen previously checked for matching .cpp and *-macros.h files to mark
symbols as implemented. That counted ENOSYS placeholder stubs as
complete while missing shared entrypoints, Clang freestanding headers,
and macros defined in hdrgen YAML or .h.def templates.
Check exported entrypoints.txt symbols scoped to each header (excluding
TODO stubs) for functions, and include hdrgen YAML, .h.def templates,
and freestanding headers for macros. Point Furo View and Edit links on
generated pages to their docgen YAML definitions instead of build-tree
paths.
Assisted-by: Automated tooling, human reviewed.
RuntimeLibcalls: Add signatures for the memcpy variants and __stack_smash_handler
The XCore and Hexagon memcpy variants take the usual destination,
source and size, except hexagon_memcpy_forward_vp4cp4n2 which takes a
word count. __stack_smash_handler uses the OpenBSD prototype.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add signatures for the SME ABI support routines
Use the prototypes from the AArch64 SME ABI. __arm_sme_state returns two
64-bit values.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>