[Bazel] Remove unnecessary arm-specific select in BUILD (#246329)
and scope x86 BLAKE3 macros to local_defines. This limits defines
propagation to other targets.
- Drop BLAKE3_USE_NEON, dispatched at
llvm/lib/Support/BLAKE3/blake3_impl.h
- Move x86 BLAKE3_* into local_defines to prevent propagation.
[ORC] Add SystemZ ABI for lazy call-through and indirect stub support (#235879)
This PR adds the OrcSystemZ ABI class with a resolver, trampolines, and
indirect stubs for lazy compilation on s390x. Register it in the
indirection utilities, the lazy call-through manager, and the compile
callback and stub manager factories.
Resolves: #231908
[Hexagon] Declare command line options in TableGen (#241871)
Move some cl::opts that the Hexagon CodeGen passes and subtarget read
into HexagonOptions.td. llvm-min-tblgen generates a HexagonOptions
struct from it, so the file-level cl::opt variables for these options
are gone. The default values are the same as before.
HexagonTargetMachine binds its copy of the struct once, from
MCTargetOptions::LibraryOptions. HexagonSubtarget takes the same
reference from its TargetMachine, and the passes read the values through
the subtarget. The struct is registered from
LLVMInitializeHexagonTarget().
A few options needed a different field type to keep their behavior:
- Options that were checked with getNumOccurrences() are std::optional
fields, such as hexagon-hvx-widen and shrink-frame-limit.
- Options where the code needs to know whether the user set a value
(enable-bsb-sched, hexagon-long-calls) are BoolOrDefault.
[30 lines not shown]
[CIR] Use one check for ignorable FP exceptions (#245985)
Speculation and lowering each decided on their own whether a constrained
operation can ignore floating-point exceptions, and they disagreed. An
operation with `fenv<strict_except = false>` was speculatable but
lowered to `fpexcept.maytrap`, and one with masked but strict exceptions
was not speculatable but lowered to `fpexcept.ignore`. `cir.vec.fcmp`
never folded a constrained comparison.
This adds `FenvAttr::canIgnoreExceptions()`, true when exceptions are
masked and not strict, and uses it in all three places:
- Speculation already used this condition and does not change.
- Lowering emits `fpexcept.ignore` when it holds, and otherwise
`fpexcept.strict` or `fpexcept.maytrap` by `strict_except`. Three
hand-written forms change: `fenv<strict_except = false>` goes from
maytrap to ignore, masked exceptions with `strict_except = true` from
ignore to strict, and unmasked or unknown exceptions without
`strict_except` from ignore to maytrap. The first changes an existing
[9 lines not shown]
[AMDGPU][NFCI] Let novm operands be parsed and created
b9b7b31e2368 set AlwaysIgnoreNegative for exp_vm, so novm is
parsed and then dropped without producing an operand. This is not
needed, because vm is already an optional operand.
[X86] SimplifyMultipleUseDemandedBitsForTargetNode - skip unnecessary (VSRLI (VSHLI X, C1), C1) ZERO_EXTEND_INREG patterns (#246639)
If we're clearing the upper bits, but never demanding them, then skip
the shift-pair
Yak shaving for #245048
[AMDGPU] Defer S_WAITCNT_DEPCTR erasure and updates in expert mode (#246081)
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.
Assisted by: Claude Opus 5.5
[CIR] Use the FP environment of a compound assignment for its conversions (#246035)
`ScalarExprEmitter::emitCompoundAssignLValue` emitted the conversions of
a compound assignment, from the left operand to the computation type and
back, without a `CIRGenFPOptionsRAII`. Under `#pragma STDC FENV_ACCESS
ON` the arithmetic was constrained but the conversions of `x *= 0.1` or
`i += x` got the default environment, and lowered to plain `fpext`,
`fptrunc`, `sitofp` and `fptosi` where classic codegen emits constrained
intrinsics.
Install the RAII with the features of the assignment after the left
operand is loaded, as classic codegen does.
Assisted-by: Claude Code (Fable 5.2).
[CIR] Normalize switches before routing gotos
A cir.case below another op inside its switch (Duff's device, or a case
in a scope, loop or if of the switch body) and a label in a switch body
before the first case both enter a block without a CFG or region edge.
cir-goto-elimination now normalizes switches first. A nested case becomes
a fresh label where it was, followed by a scope holding its body, which
normal execution still runs; a direct case with the same values, in a
block at the end of the switch body that nothing falls into, jumps to the
label. Code before a switch's first case that holds a label is reached
only through gotos, so it moves out of the switch, off the normal path:
where it would fall into the first case it jumps to a label at that case's
start, a break that leaves the switch jumps to a label after it, and its
allocas move before the switch. The gotos this creates are routed like any
other.
Assisted-by: Claude Code (Opus 5.5).
[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] Route gotos into regions and between sibling regions
cir-goto-elimination now also handles a goto whose label is not in an
enclosing region: a goto into an if branch, a loop body, a scope, a case
of a switch (including default), or a cleanup scope body as MS
compatibility allows, and any goto that first leaves some regions and
then enters others, such as from one case of a switch to another.
The goto leaves regions up to the closest region that also holds the
label, as before, and then enters each region on the way to the label.
The op that holds a region is steered into it without evaluating
anything the goto skips: its if condition or switch value becomes the
argument of a new block right before it, which normal execution reaches
with the original operand and the goto with a constant. A while or for
loop condition branches to its cir.condition, now in a last block that
takes the condition as an argument, with true. Each entered region
starts, after its allocas, with a dispatch on the destination slot that
sends the goto on. A goto is left to GotoSolver if a value other than an
alloca, defined before the op it would branch to, is used after it, or if
[12 lines not shown]
[CIR] Route gotos out of enclosing regions through a destination slot
A goto whose label is in an enclosing region stays a symbolic cir.goto
until GotoSolver, so every CIR-to-CIR pass sees control flow that neither
the CFG nor RegionBranchOpInterface describes.
cir-goto-elimination now rewrites such gotos without flattening anything.
The goto stores its label's id in a per-function i32 slot marked
goto_dest_slot and leaves each region in between through that region's
normal exit: cir.break for loop bodies, switch bodies and case regions
directly under their switch, cir.yield for cleanup-scope bodies, and a
branch to a block holding only the final cir.yield for if, scope, try and
catch regions. After each crossed op a cir.switch.flat on the slot routes
the goto onward; the last one clears the slot and branches to the label.
Cleanups, catch-handler end_catch and loop cleanups run exactly as for the
goto. cir-fold-goto-dispatch then folds those dispatches after FlattenCFG.
The slot is cleared after the entry block's allocas, before every crossed
op, and after every cir.begin_catch, so an exception thrown by a destructor
[10 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] Add a pass that folds goto destination dispatches
Routing a goto out of nested regions without flattening them needs a
destination slot: the goto stores its label's id, leaves each region
through its normal exit, and a dispatch after each region's op switches
on the slot. After FlattenCFG those dispatches are plain blocks, and at
-O0 they would stay as loads, stores and switches.
Add a goto_dest_slot attribute on cir.alloca that marks such a slot, which
CXXABILowering preserves, and cir-fold-goto-dispatch, a cir.func pass that
runs after GotoSolver. The slot is only ever stored constants and loaded,
so a forward dataflow over the function's blocks gives the constant it
holds on each edge: a case edge of a dispatch carries the case's id, and a
case edge of FlattenCFG's cleanup dispatch carries the id stored together
with that cleanup exit's id, unless some exit to that dispatch stores an
unknown cleanup id. Each edge into a dispatch, looking through blocks that
only forward to it, whose id is known goes straight to the dispatch's
destination. This repeats until nothing changes; then dead dispatches go,
and the slot once nothing loads it. A slot with a non-constant or volatile
[5 lines not shown]
[CIR] Replace same-region gotos with branches
CIRGen emits C/C++ gotos as symbolic cir.goto ops that name a cir.label.
They are not CFG edges, so the core rewrite driver, eraseUnreachableBlocks
and dataflow analyses treat the label's block as dead until GotoSolver runs
after FlattenCFG.
Add cir-goto-elimination, a cir.func pass that runs first in the
CIR-to-CIR pipeline and again at the start of the pre-lowering pipeline for
input that skips it. A goto whose label is in the same region becomes a
cir.br to the label's block. Gotos that cross region boundaries are left
for GotoSolver. The pass then erases each label that no remaining goto
names and whose address is not taken.
A label's address can be taken from a global initializer, which a
function pass cannot read. So cir.label gets an address_taken attribute:
CIRGen sets it for every label that &&label names, in a cir.block_address
op or in a constant, and the function verifier requires it on the label
of each cir.block_address op in the function.
[2 lines not shown]
[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>