[CIR] Reduce the fenv interface to an accessor and fix the unit test
The interface now declares only getFenv() and shares getConstrainedFenv(); callers read effective field values through the FenvAttr helpers. The identity constBuilderCall moves onto CIR_DefaultValuedFenvAttr, the only place that needs it. FenvOpTest used fenv<> to mean constrained; it now sets a field and checks that the empty fenv has no effects.
Assisted-by: Claude Code (Opus 5.5).
Revert "[libc][cmake] Respect the configured optimization level for the Linux thread and TLS objects" (#236604)
Reverts llvm/llvm-project#234382
See discussion in the PR thread - removing `-O3` from TLS initialization
and thread exiting code leads to crashes (from callee functions that are
build with stack protection enabled, or from accessing the local
variables after the stack is unmapped).
Co-authored-by: Prabhu Rajasekaran <prabhukrllvm at gmail.com>
[openmp] Disable affinity on WebAssembly Linux targets (#235840)
`KMP_AFFINITY_SUPPORTED` is turned off for WASI and Emscripten, but not
for clang's WebAssembly Linux target (`wasm32-unknown-linux-*`, WALI),
which defines `__linux__`. libomp then enables affinity there and the
build stops in `kmp_affinity.h`:
```
openmp/runtime/src/kmp_affinity.h:326:2: error: Unknown or unsupported architecture
```
because there are no `sched_{set,get}affinity` syscall numbers for
WebAssembly. WebAssembly has no way to pin a thread to a CPU on any of
these targets, so this change turns affinity off by architecture
(`KMP_ARCH_WASM32` / `KMP_ARCH_WASM64`) instead of by OS. WASI and
Emscripten are always WebAssembly, so nothing changes for them.
Testing:
- Built libomp for `wasm32-unknown-linux-musl` with upstream clang.
[8 lines not shown]
[CIR] Simplify the fenv default and use the interface for complex ops
Spell the empty fenv inline in the default instead of adding a no-argument builder, and give the complex FP binary ops the fenv interface so their lowering uses getConstrainedFenv() like every other op.
Assisted-by: Claude Code (Opus 5.5).
[Clang][CodeGen] The predicate 'IsScalarOrAggregate' is always true
IsScalarOrAggregate checks whether *any* 'TEK_*' evaluation kind is set,
which it always will be. Go ahead and remove it and assume it's true.
[AMDGPU] Select the op_sel version of v_mad_u16 on GFX9 (#236042)
On GFX9, select v_mad_u16 (V_MAD_U16_gfx9) for i16 multiply-add instead of
v_mad_legacy_u16, so that sources taken from the high half of a packed
register can be read with op_sel, as on GFX10+.
The legacy opcode is still selected when the result is zero-extended,
since it zero-fills the high 16 bits of the destination.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply at anthropic.com>
[Clang][NFC] Don't create RecoveryExprs when checking CCE (#236631)
The previous fix seems a layer violation and we shouldn't let
RecoveryExprs sneak into BuildConvertedConstantExpression.
This reverts both fba1a4b1292 and 9472490520b while keeping their tests.
[mlir][Python] Use the existing package-prefix variable for stub generation
Read MLIR_PYTHON_PACKAGE_PREFIX from the caller's CMake scope instead of
introducing a separate add_mlir_python_modules argument.
Signed-off-by: Twice <twice at apache.org>
[Clang][CodeGen] Fix volatile and size of inline asm struct output stores
There are two issues fixed by this PR: one where 'volatile' is dropped
and the other where an output tied to a larger input is stored
out-of-bounds:
- Struct outputs returned as integers are stored through an unqualified
integer lvalue. Two write to a volatile struct collapse into one
non-volatile store at -O2.
- A tied input larger than the output makes the asm return the input's
type, and the whole value is stored, resulting in an out-of-bounds
write.
Fix these by propagating the 'volatile' qualifier correctly and storing
only the destination's bits instead of relying upon the input's size.
Assisted-by: Claude Opus 5.5
[X86][SDAG] Fix result scalarization of <1 x ty> vectors for partial reductions (#236187)
Without custom lowering, we were crashing for <1 x ty> vector
scalarization for partial reduction results for the X86 backend. This
patch implements the necessary function to fix that, including when the
input type is wider than the accumulator/result type.
[libc] Give struct sockaddr its full sa_data (#236518)
sa_data was one byte, with a comment saying it stood in for a longer
array, which made sizeof(struct sockaddr) four rather than sixteen. Code
sizes address buffers against that: the kernel's sockaddr_vm computes
its padding by subtracting the known fields from sizeof(struct
sockaddr), which underflowed to an array of 2^64 elements
A real address is passed as one of the per-family structures, so the
array only has to fix the size. Fourteen bytes is the size the kernel
and every other libc give it
AI disclosure: this patch was written with Claude Code. I reviewed the
change. There is no test since this is a type definition
Assisted-by: Claude
Attach mbuf to the end-of-packet descriptor when sending packets and
swap the DMA mapping accordingly. This prevents a potential use-after-free
by the DMA engine of the network interface discovered by Acts1631.
Fix based on a suggested diff by Acts1631.
ok mvs@
[CIR] Default the fenv attribute and elide it when empty
Floating-point operations carried `fenv` as an optional attribute, so an
attached `#cir.fenv<>` that set no field still printed as `fenv<>` and
lowered to a constrained intrinsic. Make `fenv` a default-valued attribute
whose default is the empty `#cir.fenv<>`: it does not constrain the
operation and is not printed. Codegen always sets every field of the fenv
it attaches, so its output is unchanged. Verifiers, folding, memory effects
and lowering now use the new `getConstrainedFenv()` interface method, which
returns null for the empty attribute. The custom builders that only passed
an empty fenv are dropped; the generated ones default it.
Assisted-by: Claude Code (Opus 5.5).
[CIR] Fix cir.try successor regions (#231449)
`TryOp::getSuccessorRegions` sent every exit from the try region back to
the parent, so nothing led from the try region to the handlers. A
`cir.resume` ending the try region, left there once FlattenCFG has
flattened an inner cleanup scope, unwinds into a handler, and
`CIRTryOpFlattening` branches it to the handler dispatch block. Most
handlers are entered by an unwind out of a call in the try region
instead, which is not a region branch point, so the edges from the
parent and from every try-region exit stand in for it. Without them,
generic MLIR passes treat such a handler as dead, and `cir-opt
-remove-dead-values` empties it. Take this try:
```mlir
cir.try {
cir.brcond %cond ^normal, ^unwind
^normal:
cir.call @may_throw() : () -> ()
cir.yield
[28 lines not shown]
[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 used fptoui and compared against 0 as unsigned, so the
clamp to 0 never fired; it now converts and clamps as signed, like
llvm::FixedPointBuilder. 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 (Opus 5.5).
[mlir][tosa] Move RESCALE zero-point value checks from the verifier to tosa-validate (#234443)
Part of #233457.
Move the RESCALE input/output zero-point value constraints out of
`RescaleOp::verify()` into the `ERROR_IF` checks in `tosa-validate`,
matching the TOSA specification, where these are conformance rules
rather
than dialect well-formedness requirements.
- `TosaOps.cpp`: drop the zp value checks from `RescaleOp::verify()`;
type checks stay in the verifier.
- `TosaValidation.cpp`: add the same checks to `checkErrorIfRescale()`,
reusing the op's verify helpers, gated on `strict-op-spec-alignment`.
The accepted/rejected set and diagnostics are unchanged.
- `TosaToLinalg.cpp`: add a fail-closed backstop in `RescaleConverter`
so
conversion without validation rejects invalid zps instead of silently
lowering incorrect arithmetic.
[5 lines not shown]
[mlir][tosa] Avoid copying profile compliance metadata (#232774)
Return compliance maps by const reference and pass matching inputs
through ArrayRef to avoid copying entire maps and nested type signatures
during validation.
[OpenMP][offload] Size only reductions that fill the device by their size
A cross-team reduction whose loop is too short for one block per compute
unit now gets the grid of a kernel without a reduction. In SPMD mode,
that is the low-trip-count rule, which lowers the number of threads per
block to spread the iterations over more compute units. Keeping all
threads made such reductions, e.g. one of 1792 iterations, up to 2.5x
slower on MI210.
Claude assisted with this patch.
[OpenMP][offload] Size the grid of cross-team reductions by their size
Every block adds to the cost of combining the partial results of a
cross-team reduction. Launch one block per compute unit for reductions
that work with a reduction data size of more than 32 bytes, and enough
blocks for a per-device number of waves per compute unit (16 on AMDGPU)
for the smaller reduction data sizes, capped by the trip count. Such
kernels keep their number of threads: the low-trip-count reduction of
threads does not apply to them. libomptarget reads the number of compute
units and the platform backend of the device through liboffload, as part
of its geometry properties.
This is an upstream port of the corresponding downstream.
Claude assisted with this patch.
[Clang][CodeGen] Update the TBAA info for potential aliases
The stores of a _Complex number were tagged as "unsigned long", but
loads were tagged as "float". TBAA reports no aliases if the store and
loads went through different pointers and GVN forwards a stale value.
Fix this by giving the "store" the "omnipotent char" tag, so that TBAA
treats it as aliasing every access to the destination's members. Using
that tag over "Dest.getTBAAInfo()" because it doesn't depend on how
CodeGenTBAA happens to tag struct and _Complex types.
Assisted-by: Claude for testcases.