[libsycl] Fix unit-test mock after olCreateContext const change (#247208)
PR https://github.com/llvm/llvm-project/pull/244215 made the `Devices`
parameter of `olCreateContext` a
`const ol_device_handle_t *`. The libsycl unit-test mock still defined
the function with a non-const pointer, which declares a separate C++
overload instead of the `extern "C"` entry point, so the unit tests
failed to link with an undefined `olCreateContext`.
Update the mock definition, the gmock method and the test lambdas to
the new signature, and stop casting away const in the default action.
Assisted-by: Claude
[mlir][arith] Narrow arith.select via int ranges
Add a `NarrowSelect` pattern to `populateIntRangeNarrowingPatterns` so
`arith-int-range-narrowing` narrows `arith.select` operations over
signless integer or index scalars, vectors, and tensors when both arms
and the result fit in a narrower target bitwidth under a common signed
or unsigned extension.
`NarrowElementwise` requires all operands to share the result type and
therefore skips `arith.select` due to its `i1` condition operand,
leaving redundant widen/truncate pairs around selects inside narrowed
arithmetic chains.
Assisted-by: gemini-4-carbon
[mlir][IntRange] Unwrap nested shaped value types
Update `ConstantIntRanges::getStorageBitwidth` to recursively unwrap
nested `ShapedType` containers that carry the `ValueSemantics` trait
(such as `tensor<...xvector<...xi32>>`), returning 0 for shaped types
without value semantics (such as `memref`).
This ensures a tensor type and its element type always agree on storage
bitwidth, enabling integer range inference to propagate through
`tensor.extract`, `tensor.from_elements`, `tensor.insert`, and
`tensor.splat` on tensors of integer vectors and removing the
`!isIntOrIndex()` workarounds introduced in 2c7efd6f6e1b.
Tighten `IntRangeOptimizations` to reject types with zero storage
bitwidth during constant materialization and to skip elementwise
narrowing when the immediate element type is not an integer or index.
Assisted-by: gemini-4-carbon
[mlir][SPIR-V] Add SPIRVToLLVM conversions for atomic ops (#243128)
Lower atomics to native LLVM atomics, with scopes mapped to the
syncscope names clang uses for SPIR-V targets
Scopes and orderings LLVM cannot express fail to convert
---------
Co-authored-by: Igor Wodiany <dev at wodiany.com>
[PassBuilder] Fix class name for structurizecfg in PassRegistry.def (#247147)
The class name of the pass is `StructurizeCFGPass`, but it was
registered as `StructurizeCFG`. Because of this the class name wasn't
mapped to the pass name, and `-print-pipeline-passes` printed the raw
class name `StructurizeCFGPass<...>`, which can't be parsed back:
$ opt -disable-output -print-pipeline-passes \
-passes='function(structurizecfg<skip-uniform-regions>)' test.ll
Could not parse dumped pass pipeline: unknown function pass
'StructurizeCFGPass<skip-uniform-regions>'
Fix the class name and add a round trip test.
The AMDGPU new pass manager pipeline test checked for the raw class
name; update it to the pass name.
[mlir][SPIR-V] Reject vector offsets and strides LLVM cannot match (#245547)
LLVM pads `vector<3xf32>` to 16 bytes and aligns `vector<8xf32>` to 32,
so GEPs silently landed at wrong offsets
[mlir][SPIR-V] Convert Load and Store with combined memory access bits to LLVM (#242982)
The pattern matched only single MemoryAccess values, so masks combining
Aligned, Volatile, and Nontemporal failed to convert, test each bit
instead
[Mips] Insert nops for hazards in .set reorder mode (#246539)
In .set reorder mode GNU as inserts the nops that hazards need on the
older ISAs, so hand written assembly does not have to. The integrated
assembler did not, so MIPS I code that was correct with GNU as broke
silently, as did inline assembly, which is assembled in .set reorder
mode.
Track the last two instructions emitted in each section and, before
each instruction, insert the nops that insns_between() in GNU as asks
for:
- one after a load to a GPR on MIPS I before a use of that register,
except between the lwl and lwr halves of an unaligned load
- one after a move from a coprocessor (mfc0, mfc1, cfc1, mfc2, and the
64-bit forms) before a use of the GPR, on MIPS I to MIPS III
- one after mtc1 before a use of the FPR on MIPS I to MIPS III, and the
same after lwc1 on MIPS I
- after a move to a control register (ctc1, mtc0, mtc2), or a load to
[35 lines not shown]
[JumpTableToSwitch] Use ConstGlobalIterator to read jump table entries
Replace JTTS's own jump table parsing with the `ConstGlobalIterator` helper,
which is also used by instcombine's `foldCmpLoadFromIndexedGlobal`.
As a result JTTS now also handles GEPs without nusw/nuw flags, by masking the
index the same way instcombine does.
Note that the helper requires the indices to be in canonical index type, so
JTTS only works with canonical index types now. This is not a problem in
practice as JTTS only runs after instcombine.
[analyzer][NFC] Use range algorithms for annotation checks in ObjC checkers (#246864)
Replace hand-written loops over `specific_attrs<AnnotateAttr>()` and
iterator-pair `std::any_of` calls in DirectIvarAssignment,
IvarInvalidationChecker and LocalizationChecker with
`llvm::any_of`/`llvm::none_of`/`llvm::is_contained`.
Assisted-by: Claude Code
[CIR] Return the value stored to the return slot directly
At -O0, classic codegen returns the value stored to the return slot
directly when that store dominates the return, and then drops the slot
(findDominatingStoreToReturnValue in CGCall.cpp). CIR always lowered the
slot to alloca, store, load and ret, so most scalar-returning functions
differed from classic codegen.
Add a cir-forward-return-slot function pass. In a function with a single
cir.return of a load from the return slot, it returns the stored value
when the only store to the slot reaches the load through a chain of
single predecessors, or when the store immediately precedes the load.
These are classic codegen's rules. The return takes the store's location
only when no code runs between the two; classic codegen keeps the
function-end location when cleanups run there. The pass runs before LLVM
lowering, after FlattenCFG and ABI lowering, so -emit-cir output does not
change. Volatile, atomic, record, array and complex slots are left alone.
The tests change only in their LLVM checks. In files where the LLVM and
[3 lines not shown]
[mlir][gpu] Save and restore the stack around the kernel argument storage (#234399)
In the LLVM translation of `gpu.launch_func`, save the stack before the
allocas for the kernel argument struct and pointer array, and restore it
after the launch call. Allocas outside the entry block are dynamic, so a
kernel launch in a loop grows the stack on every iteration and can
overflow the stack for a large loop.
The driver copies arguments at the launch call, so releasing the storage
after it is safe.
Add a test that checks that a launch in a loop brackets its allocas with
`llvm.stacksave` and `llvm.stackrestore`.
Assisted-by: Claude
Co-authored-by: Claude Fable 5.2 <noreply at anthropic.com>
[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] 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).
[analyzer][NFC] Use LLVM range helpers in a few Core loops (#246897)
Replace hand-written loops with the equivalent LLVM range helpers
(llvm::any_of, llvm::copy_if, llvm::make_second_range, llvm::interleave)
in:
- CheckerHelpers.h: containsStmt<T> uses llvm::any_of.
- CheckerHelpers.cpp: containsMacro/containsEnum/containsStaticLocal/
containsBuiltinOffsetOf share one TU-local anyChild(S, Pred) helper for
the null-child check; tryExpandAsInteger uses llvm::copy_if.
- AnalysisManager.h: isInCodeFile.
- ProgramState.cpp: ~ProgramStateManager.
- DynamicType.cpp: printJsonContainer.
Assisted-by: Claude Code
[LV] Use epilogue plan's scalar-epilogue requirement in iter check (#246041)
Split the Plan argument of addMinimumIterationCheck into Plan, indicates
insertion site for the check, and GuardedPlan, indicates the plan
containing the guarded vector loop. Compute the min-iteration check
using GuardedPlan's scalar epilogue requirement and tail-folding state
instead of Plan's.
Fixes #245054
Split from #213904
Co-authored-by: Florian Hahn <flo at fhahn.com>
[OpenMP] Minimally support detachable tasks in the device runtime
The device runtime has no __kmpc_task_allow_completion_event or
omp_fulfill_event, so a task with a detach clause in a target region
fails to link.
Tasks on the device are executed immediately by the encountering thread
and are complete once their structured block has finished, so there is
no completion event to register. Return a null event handle, and make
omp_fulfill_event do nothing.
Co-Authored-By: Carlo Bertolli <carlo.bertolli at amd.com>
Co-Authored-By: Greg Rodgers <Gregory.Rodgers at amd.com>
Assisted-By: Claude
[Clang][OpenMP] Cast task privates-map arguments to the default address space (#245784)
The privates mapping function of a task takes its arguments as pointers in the default address space, but the temporaries whose addresses are passed to it are allocas, which need not be in that address space: they are in address space 5 on AMDGPU, and in address space 0 on SPIR-V, whose default address space is the generic one (4). Since #200427 those addresses have been passed without a cast, so the call's function type does not match the callee's. A task with a firstprivate (or private, or lastprivate) variable in a target region then faults when run on an affected device.
The fix is to cast the arguments to the default address space at each of the call sites. This is a no-op on targets whose allocas are already in the default address space, such as x86 and NVPTX.
New tests cover compile-time and runtime behaviour.
Assisted-By: Claude
[mlir] Pass analyses to speculation hooks and LICM
Let ConditionallySpeculatable models implement either the simple hook or one that accepts a nullable AnalysisManager. Forward the manager through recursive purity queries and loop-invariant code motion. Exercise the simple external model through both entry points.