[CIR] Mark LoweringPrepare init functions strictfp
Classic codegen's StartFunction makes a function that has no
FunctionDecl `strictfp` when the TU-wide default FP environment is
constrained: FP exceptions are not ignored or the rounding mode is
dynamic. Of those functions ClangIR creates `_GLOBAL__sub_I_*`,
`_GLOBAL__I_*`, the C++20 module initializer, `__cxx_global_var_init*`,
`__cxx_global_array_dtor*` and `__tls_init`. It marked only
`__cxx_global_var_init*`, through a `strictfp` attribute on `cir.global`,
so the other functions and the calls in them were not `strictfp`.
Classic also marks the `__dtor_*` stubs, `_GLOBAL__D_a` and
`__GLOBAL_cleanup_*`, which ClangIR does not emit.
LoweringPrepare creates these functions after CIRGen, so it reads the
TU-wide default from `#cir.lowering_options`. `no_trapping_math` already
records whether FP exceptions are ignored, and the new `rounding_math`
field mirrors `LangOptions::RoundingMath`. It is omitted when false, so
the module attribute prints as before without `-frounding-math`.
`buildRuntimeFunction` adds `strictfp` together with the other TU-wide
[8 lines not shown]
[CIR] Keep three-way comparisons constrained in strict FP functions
In a strictfp function ClangIR emitted plain `fcmp` for a three-way
comparison of floating-point values, where classic codegen emits
`llvm.experimental.constrained.fcmp`. `cir.cmp3way` had no `fenv`
attribute, and LoweringPrepare expanded it with a builder that has no
floating-point state.
This gives the operation the optional `fenv` attribute, valid only for
floating-point operands, and the fenv traits of the scalar operations
in place of `Pure`:
- CIRGen attaches the attribute. Like classic codegen it opens no
FP-options scope for the comparison itself, so the comparison takes
the environment in effect around it. In `return x <=> y` under
`FENV_ACCESS ON` alone that is the default of the function,
`fpexcept.ignore`.
- LoweringPrepare expands a comparison of floating-point values into
quiet `cir.fcmp`s, which take the attribute if the operation has one.
[10 lines not shown]
[CIR] Use the pragma FP environment for __builtin_convertvector
`ScalarExprEmitter::VisitConvertVectorExpr` emitted the conversion
without a `CIRGenFPOptionsRAII`, so the cast got the floating-point
environment of the command line instead of the one that pragmas set at
the expression. With `-ffp-exception-behavior=strict` on the command
line and `#pragma clang fp exceptions(maytrap)` plus
`#pragma STDC FENV_ACCESS ON` in the function, ClangIR lowered the
conversions to constrained intrinsics with `round.tonearest` and
`fpexcept.strict`, where classic codegen emits `round.dynamic` and
`fpexcept.maytrap`.
Install the RAII for the conversion, after the source operand is
emitted, as classic codegen does on each floating-point path.
The test converts between float vectors and signed, unsigned, double
and bool vectors, so it covers the `float_to_bool` and `bool_to_float`
casts too. ClangIR and classic codegen share every LLVM check for them,
and the ClangIR run rejects any plain conversion or `fcmp` instruction
[7 lines not shown]
[CIR] Keep complex and bool casts constrained in strict FP functions
In a strictfp function ClangIR emitted plain `fpext`, `fptrunc`,
`fptosi`, `sitofp`, `uitofp` and `fcmp une` for casts between complex
types and for conversions between floating-point values and bool, where
classic codegen emits constrained intrinsics. CIRGen created the
complex casts and `float_to_bool` without the `fenv` attribute,
LoweringPrepare dropped the attribute when it expanded a complex cast,
and the LLVM lowering of `float_to_bool` and `bool_to_float` ignored
it.
`createCast` now takes an optional `fenv` attribute. CIRGen passes the
current floating-point environment for `float_to_bool` and for the
complex cast kinds that convert floating-point values. The kinds that
only select or pack a part, `float_to_complex` and
`float_complex_to_real`, get none, and the verifier no longer accepts
the attribute on them. LoweringPrepare passes the attribute of a
complex cast to the scalar casts of its expansion. With `fenv`,
`float_to_bool` lowers to the quiet constrained `fcmp` and
[10 lines not shown]
[CIR] Keep complex mul and div constrained in strict FP functions
In a strictfp function ClangIR emitted plain `fmul`, `fsub`, `fadd`,
`fdiv` and `fcmp` for complex multiplication and division, where
classic codegen emits constrained intrinsics. `cir.complex.fmul` and
`cir.complex.fdiv` had no `fenv` attribute, and LoweringPrepare
expanded them with a builder that has no floating-point state.
This moves both operations onto `CIR_FenvOp`, which gives them the
optional `fenv` attribute and the fenv traits of the scalar operations.
CIRGen attaches the attribute, and LoweringPrepare passes it to the
scalar arithmetic, comparisons and conversions of the expansion.
The range check of the improved division becomes a quiet
`cir.fcmp ugt`, the predicate classic codegen uses. A `cir.cmp ge` with
`fenv` lowers to the signaling `fcmps` and would raise an invalid
exception for a quiet NaN divisor. Without `fenv` the check changes
from `fcmp oge` to `fcmp ugt`.
[15 lines not shown]
[clang] Use the operator's FP environment for promoted operands
An operator evaluated in a wider type converts its operands to that type
and its result back. This happens for `_Float16` and `__bf16` without
native support, and for complex division with the promoted complex
range. The binary operators and unary plus and minus did these
conversions outside the scope of their FP options, so the conversions
took the ambient options. The right-hand side of a scalar compound
assignment was promoted before its scope too. For `z = x * y` on
`_Float16`, or `c = a / b` on `_Complex float` with the promoted range,
under a file-scope `#pragma STDC FENV_ACCESS ON`, that is the default
environment of the function:
fpext fpexcept.ignore -> fpexcept.strict
fptrunc round.tonearest, fpexcept.ignore -> round.dynamic, fpexcept.strict
`c /= b` and `f(a / b)` already had the strict metadata, because the
scope of the compound assignment or of the call was open. These
operators now open their scope before they promote, when they promote.
[4 lines not shown]
[CIR] Mark calls in strictfp functions strictfp
At -O1, ClangIR folded `erf(1.0)` to a constant under
`#pragma STDC FENV_ACCESS ON`, while classic codegen kept the call. The
difference is the call-site `strictfp` attribute. LangRef requires it on
every call in a function that uses constrained FP intrinsics, and LLVM's
libcall folders look at the call, not at the caller. Classic codegen
gets it from IRBuilder's constrained mode. ClangIR marked only the
function.
The CIR `strictfp` function attribute now lowers to the `strictfp`
attribute of `llvm.func` instead of a `passthrough` entry. After the
conversion, every `llvm.call`, `llvm.invoke`, `llvm.inline_asm` and
`llvm.call_intrinsic` in a `strictfp` function gets `strictfp` too, and
every named intrinsic op such as `llvm.intr.fabs` or `llvm.intr.memcpy`
gets `llvm.strictfp`. That includes indirect calls, constrained
intrinsics, and the calls LoweringPrepare and EH lowering create. CIR
itself does not change.
[7 lines not shown]
[mlir][LLVM] Add llvm.strictfp for intrinsic ops
In a function that uses constrained floating-point intrinsics, LLVM
requires every call to be `strictfp`, including calls of intrinsics such
as `llvm.fabs`, `llvm.memcpy` and `llvm.trap`. The call ops and
`llvm.func` have an inherent `strictfp` attribute, but the named
intrinsic ops have no call-site attributes, so a frontend could not mark
those calls.
This adds a discardable `llvm.strictfp` unit attribute. Export sets the
`strictfp` call-site attribute on the call the op translates to, the way
`llvm.memprof` attaches to the calls an op produces, and import sets it
on an intrinsic op whose call site is `strictfp`. A new
`IntrinsicOpTrait` marks the LLVM dialect's intrinsic ops, and the
verifier accepts `llvm.strictfp` only on them, so the call ops keep a
single spelling.
Assisted-by: Claude Code (Opus 5.5).
[CIR] Lower complex constants through CIRAttrToValue (#246485)
The complex branch of the `cir.const` lowering rebuilt the same
`llvm.mlir.constant` that
`CIRAttrToValue::visitCirAttr(ConstComplexAttr)` already produces. It
now delegates to the visitor, keeping only the zero case, which lowers
to a `[0, 0]` constant rather than `llvm.mlir.zero`. It also drops
`UndefAttr` checks in the array, record and complex branches that the
early undef return makes unreachable.
Assisted-by: Claude Code (Opus 5.5).
[SelectionDAG] Fix big-endian order of split-argument debug fragments (#239512)
This PR addresses a bug discovered while porting LLVM to AVR32
(off-branch). The problem has also been verified on supported big-endian
targets. I relied heavily on Claude code for the porting and for
assessing, isolating, and fixing the bug. I understand the problem, but
lack the knowledge of LLVM internals to do it myself and to assess the
soundness of Claude's fix. The text below has been prepared by the AI
and contains a description of the problem and the fix.
An argument built from two registers with `ISD::BUILD_PAIR` is described
by two `DW_OP_LLVM_fragment`s, assigned at increasing offsets in the
order `getUnderlyingArgRegs()` returns the registers. A fragment offset
counts from the variable's lowest-addressed byte, so on a big-endian
target fragment 0 must be the high half. `BUILD_PAIR`'s operands are
(low, high) whatever the byte order, and they were walked in operand
order, so on big-endian targets the two halves were swapped: a debugger
showed 0x0102030405060708 as 0x0506070801020304.
[13 lines not shown]
[AMDGPU] Defer S_WAITCNT_DEPCTR erasure and updates in expert mode
A pre-existing S_WAITCNT_DEPCTR was erased, or had its VA_VDST and
VM_VSRC fields relaxed, as soon as the incoming state made those waits
look redundant. In a loop header that happens on the first visit, before
the backedge adds the instructions of the loop body. The wait is then
lost when the header is visited again with them pending.
Keep the original operand of every S_WAITCNT_DEPCTR, including
duplicates, while iterating to the fixed point, and only apply the final
encoding or erase the instruction at the end of the pass.
Also reset the VA_VDST field of a duplicate S_WAITCNT_DEPCTR to "no
wait" once its wait has been folded into the first one, instead of
leaving a redundant copy of the combined wait behind.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[mlir][rewriter] Add test for stale deadness cache on nested in-place update (#246626)
Show that invalidating only the op and its ancestors in
DeadnessListener::notifyOperationModified is insufficient:
updateOpInPlace may also change IR nested in the op, leaving descendants
cached as dead and causing the op to be wrongly erased.
Test invalidating #243287
Reapply #244254, reverted in 0a9006272abd after expensive pattern API
checks reported an operation fingerprint change. The original test
changed a nested operation attribute while notifying only its ancestor,
bypassing the required nested operation notification. Instead, change a
block argument type through modifyOpInPlace on its owner.
Assisted-by: Codex
[AArch64] Lower 5 and 7 way interleaving with TBL/TBX (#241926)
Use TBL for the first group of up to four TBL registers, then TBX to
merge bytes from any remaining registers.
With this change generated code now matches or better than the
shufflevector based interleaving.
[lldb] Don't leave the error of GetByteSize unchecked in Type::GetDescription (#246088)
The `llvm::Expected` is not checked which causes assertion builds to
assert in swiftlang.
This patch uses `expectedToOptional`, like other callers in `Type.cpp`
do.
[CIR] Mark LoweringPrepare init functions strictfp
Classic codegen's StartFunction makes a function that has no
FunctionDecl `strictfp` when the TU-wide default FP environment is
constrained: FP exceptions are not ignored or the rounding mode is
dynamic. Of those functions ClangIR creates `_GLOBAL__sub_I_*`,
`_GLOBAL__I_*`, the C++20 module initializer, `__cxx_global_var_init*`,
`__cxx_global_array_dtor*` and `__tls_init`. It marked only
`__cxx_global_var_init*`, through a `strictfp` attribute on `cir.global`,
so the other functions and the calls in them were not `strictfp`.
Classic also marks the `__dtor_*` stubs, `_GLOBAL__D_a` and
`__GLOBAL_cleanup_*`, which ClangIR does not emit.
LoweringPrepare creates these functions after CIRGen, so it reads the
TU-wide default from `#cir.lowering_options`. `no_trapping_math` already
records whether FP exceptions are ignored, and the new `rounding_math`
field mirrors `LangOptions::RoundingMath`. It is omitted when false, so
the module attribute prints as before without `-frounding-math`.
`buildRuntimeFunction` adds `strictfp` together with the other TU-wide
[8 lines not shown]
[UTC] Handle x86 vectorcall labels on Win32 (#235424)
Fixes #31744
`update_llc_test_checks.py` was unable to correctly handle decorated
function labels for `x86_vectorcallcc` functions targeting 32-bit
Windows. These labels can contain suffixes such as `@@0` or `@@4`, while
the function name in the assembly comment does not include the suffix.
This patch fixes the x86 assembly function-label regex to handle these
decorated labels correctly. It also adds a regression test covering
Win32 vectorcall functions with and without integer arguments.
### AI Usage
The root-cause analysis and proposed fix are my own work. I used an AI
assistant to help understand parts of the existing code, review my
changes, and assist with testing and debugging.
[mlir][LLVM] Add llvm.strictfp for intrinsic ops
In a function that uses constrained floating-point intrinsics, LLVM
requires every call to be `strictfp`, including calls of intrinsics such
as `llvm.fabs`, `llvm.memcpy` and `llvm.trap`. The call ops and
`llvm.func` have an inherent `strictfp` attribute, but the named
intrinsic ops have no call-site attributes, so a frontend could not mark
those calls.
This adds a discardable `llvm.strictfp` unit attribute. Export sets the
`strictfp` call-site attribute on the call the op translates to, the way
`llvm.memprof` attaches to the calls an op produces, and import sets it
on an intrinsic op whose call site is `strictfp`. A new
`IntrinsicOpTrait` marks the LLVM dialect's intrinsic ops, and the
verifier accepts `llvm.strictfp` only on them, so the call ops keep a
single spelling.
Assisted-by: Claude Code (Opus 5.5).
[CIR] Mark calls in strictfp functions strictfp
At -O1, ClangIR folded `erf(1.0)` to a constant under
`#pragma STDC FENV_ACCESS ON`, while classic codegen kept the call. The
difference is the call-site `strictfp` attribute. LangRef requires it on
every call in a function that uses constrained FP intrinsics, and LLVM's
libcall folders look at the call, not at the caller. Classic codegen
gets it from IRBuilder's constrained mode. ClangIR marked only the
function.
The CIR `strictfp` function attribute now lowers to the `strictfp`
attribute of `llvm.func` instead of a `passthrough` entry. After the
conversion, every `llvm.call`, `llvm.invoke`, `llvm.inline_asm` and
`llvm.call_intrinsic` in a `strictfp` function gets `strictfp` too, and
every named intrinsic op such as `llvm.intr.fabs` or `llvm.intr.memcpy`
gets `llvm.strictfp`. That includes indirect calls, constrained
intrinsics, and the calls LoweringPrepare and EH lowering create. CIR
itself does not change.
[7 lines not shown]
[IR] Add `alwaysuniform` function attribute (#214644)
The attribute indicates that the function's result is always uniform,
even when its inputs are divergent. This is a stronger guarantee than
nodivergencesource (which only promises the function doesn't introduce
new divergence) and is intended to be emitted by front-end and used by
UniformityAnalysis.
Specifically it allows marking a downstream front-end ballot function such
that the guaranteed uniformity of the result (of the call to the function)
allow optimization of a subsequent consumer.
[X86] Avoid combineSub cycle when ~C2 does not constant fold (#246346)
The X86 fold `sub(C1, xor(X, C2)) -> add(xor(X, ~C2), C1+1)` builds
`~C2` with `getNOT`. When `C2` is a bitcast of a build vector with undef
lanes, `~C2` doesn't constant fold, and the generic xor/add combines
turn the result back into the original sub, so the DAG combiner never
terminates. This only does the fold when `~C2` constant folds. On the
issue's IR, `llc -O2` (default and `-mattr=+sse4.1`) went from killed
after 60s to about 13ms, with no other X86 CodeGen test changes.
Fixes #246312
Assisted-by: Grok Bot (AI coding agent)