[CIR][OpenMP] Fix critical region cleanups at -O2 (#236140)
A local in a `critical` body broke CIR verification at -O2. Emit its
cleanups before `omp.terminator`, using a new `omp::CriticalOp` body
builderEmit the body inside an omp.critical region
[IVDescriptors] Allow non-compare conditions in any-of selects (#236420)
`isAnyOfPattern` only matched `select(cmp, phi, inv)`. Since #204927,
InstCombine turns `zext(and(trunc nuw %flag, %c))` into `select(%c,
%flag, 0)`. A bool flag kept as i8 and updated with `flag &= (x >= a) &
(x <= b)` then becomes `select(and(cmp, cmp), %flag, 0)`, and the loop
is no longer vectorized. LLVM 22 vectorized it as an and reduction.
The vectorizer only uses the condition as a mask, so it can be any i1
value, including one defined outside the loop. It can't be part of the
reduction chain, since the vectorizer replaces the chain and the
condition would become poison. A compare is the exception: the
vectorizer rewrites a compare of the reduction phi to compare the start
value. AddReductionVar checks this once the reduction walk is done.
The first commit adds the tests, so the second shows the change in
output.
Reported in https://github.com/JuliaLang/julia/issues/64384, where the
[2 lines not shown]
[MLIR] Include <unordered_map> in LevelZero runtime wrapper (#247290)
The file uses std::unordered_map but included <unordered_set> instead.
Follow up to review comment on #243623.
[VectorCombine] Make TryEarlyFoldsOnly parameter printable and parseable (#247180)
Print the option in `-print-pipeline-passes` and parse in
`-passes='vector-combine<early-folds-only>'`.
[sanitizer] apply clang-format to some files (#243081)
Separate the clang-format of those files to simplify the review of later
additions targeting QNX in them.
Issue: https://github.com/llvm/llvm-project/issues/243075
[ConstraintElim] Add tests for more induction facts (NFC) (#247272)
Add tests for PN >= Start with PN < B compares, exiting compares in
blocks dominating the latch and loops that exit in their first
iteration. Also adjust existing tests whose loops would exit
immediately.
[mlir][SPIR-V] Fix BitFieldUExtract lowering for Count equal to the width (#245727)
he convert-spirv-to-llvm lowering of spirv.BitFieldUExtract builds its
mask as ~(-1 << count). When count is the full bit width (legal with
offset 0, it just means "take everything") that is a shift by the bit
width, which LLVM treats as poison. The SPIR-V spec says the result is
base. At -O0 the issue's example happens to print the right value only
because the JIT picks a bzhi for that pattern on a BMI2 host and bzhi
saturates at the operand width, at -O3 the optimizer makes something
arbitrary out of it.
Build the mask as lshr(-1, width - count) instead. That one is exact for
count in [1, width] and only out of range for count == 0, where the spec
says the result is 0, so a single select covers it. For every input the
spec defines (offset + count <= width) all remaining shift amounts are
in range, and the poison arm at count == 0 is never selected.
CHECK lines in bitwise-ops-to-llvm.mlir are updated. I also ran every
legal (offset, count) pair on i8 for a few bases through mlir-runner at
[7 lines not shown]
[mlir][SPIR-V] Fix BitFieldSExtract lowering for Count 0 (#245726)
The convert-spirv-to-llvm lowering of spirv.BitFieldSExtract shifts the
field up to the sign bit and then does ashr by width - count. With count
== 0 that is a shift by the full bit width, which LLVM treats as poison
(and with offset 0 the left shift is as well). The SPIR-V spec says the
result is 0 in that case. At -O0 the issue's example (base 7, offset 1,
count 0) prints INT_MIN, at -O3 the optimizer produces arbitrary values.
Add a select that returns 0 when count is 0. The existing shifts are in
range for every other input the spec defines (offset + count <= width),
so they stay as they are; the poison arm is never picked by the select.
CHECK lines in bitwise-ops-to-llvm.mlir are updated. I also ran every
legal (offset, count) pair on i8 for a few bases through mlir-runner at
-O0 and -O3 against a spec model, all match after the change.
BitFieldInsert and BitFieldUExtract have related problems (#238834,
#238836), fixed in separate PRs. The small count-is-zero select block is
[3 lines not shown]
[mlir][SPIR-V] Fix BitFieldInsert lowering for unmasked Insert and Count 0 (#245723)
The convert-spirv-to-llvm lowering of spirv.BitFieldInsert computes
(base & ~mask) | (insert << offset). The second half never trims insert
to count bits, so any high bit of insert lands on top of a bit of base
that is supposed to stay unchanged (base 3, insert -1, offset 0, count 3
gives -1 instead of 7).
The mask itself is built as ~(~(-1 << count) << offset). For count ==
width (legal with offset 0) and for count == 0 with offset == width
(also legal, the spec says the result is just base) those are shifts by
the full bit width, which LLVM treats as poison. At -O0 this happened to
produce base | (insert << offset), at -O3 the optimizer makes something
arbitrary out of it.
This builds the low mask as lshr(-1, width - count) instead, ANDs the
shifted insert with the field mask, and selects base when count is 0.
For every input the SPIR-V spec defines (offset + count <= width) all
remaining shift amounts are in range. When count is 0 the computed arm
[13 lines not shown]
[MC][NFC] Make MCAsmInfo non-virtual (#247084)
Configuration should be done through member variables and not through
expensive virtual functions. Saves 1.8kiB of .data.rel.ro.
[PowerPC][XRay][test] Add CR-bit and CTR conditional return tests
The if-converter predicates a return on a single CR bit (BCLR/BCLRn)
or on CTR (BDZLR8/BDNZLR8). PATCHABLE_RET emits these as bare bclr,
bdzlr and bdnzlr, so the function exit is not instrumented, and
getInstSizeInBytes reports a full sled for them, which the object
emitter's size check rejects on assertions builds.
Assisted-by: Claude Code
[mlir][spirv] Fix assertion on non-signless integer memref memory spaces (#222433)
The default memory space to storage class mappings in
MapMemRefStorageClassPass read the numeric memory space with
IntegerAttr::getInt(), which asserts unless the attribute type is
signless
(or index). The memref verifier accepts any IntegerAttr as memory space,
so
a type like memref<10xf32, 1 : ui64> makes
map-memref-spirv-storage-class
(and convert-gpu-to-spirv, which reuses the same mappings) abort in an
assertions build:
```mlir
%alloc = memref.alloc() alignment = 64 : memref<10xf32, 1 : ui64>
```
Read the raw APInt with tryZExtValue() instead, so signed and unsigned
spellings map exactly like the signless one (1 : ui64 -> Generic, like
[12 lines not shown]
[MLIR] Fix LevelZero runtime wrapper build with MSVC (#243623)
MSVC needs explicit include for \<string\> header.
Symbols were not exported correctly for MS Windows.
[CIR][OpenMP] Add support for OpenMP reduction clause
This patch adds support for the OpenMP reduction clause on the teams and for
directives for reductions with built-in identifiers on local scalar integer and
floating-point variables. Other cases, such as user-defined reductions,
modifiers, arrays and globals, are reported as not yet implemented.
Assisted-by: Cursor / Claude Opus 5.5 Medium
[CIR] Add inner-unroll-and-jam loop lowering to CIRGen (#235149)
While looking into the Lower-to-LLVM for loop information, I discovered
that the unroll-and-jam handling is particularly difficult to do once
we've lost the loop state. I had initially hoped we could do without a
lot of this (and have lowering manage it), but that doesn't seem to be
the case without a ton of complexity.
This patch adds the scope objects to do the calcuation for this info.
When a loop is unrolled and jammed by the loop around it, its hints are
split like classic codegen does in LoopInfo::finish(): the loop keeps
the hints for what happens before the jam, and the hints for what
happens after it are kept by the outer loop in a new
'unroll_and_jam_inner' parameter of '#cir.loop_hint'.
The hints in 'unroll_and_jam_inner' are for a different loop than the
one they are attached to, so they record that loop's 'loop_id' (and
whether it was vectorized). To have the id available, it is now created
by the scope object when the loop's hints are, instead of when the loop
op is created.
[lld][ELF] Fix use-after-free in section spilling
SHF_MERGE sections are finalized using code that uses try_emplace on a
DenseMap, but the second argument is based on an iterator into the same
map. Since try_emplace takes its arguments by reference and may
reallocate the map, this causes a use-after-free when SHF_MERGE sections
may spill between output sections. Fix this by copying the argument
first. Add a regression test that catches the issue under ASan.
Fixes #245888
[DAG] isGuaranteedNotToBeUndefOrPoison - load(constant_pool) add DemandedElts handling (FIXED) (#247209)
Reported on #245048 + #246154 - #243498 failed to return true if all the
demanded elements were constant and not undef/poison (so most of the
test changes were always returning false and relying on followup
isGuaranteedNotToBeUndefOrPoison calls after lowering to shuffles etc.).
[mlir][ComplexToStandard] Lower complex.sqrt without trigonometric functions (#246204)
The lowering of `complex.sqrt` goes through `atan2`, `cos` and `sin`, so
exact results are lost to rounding, e.g. `sqrt(-1)` is `(-4.37114e-08,
1)` in `f32`. This patch uses the algebraic form that the comment above
`SqrtOpConversion` already cites:
t = sqrt((|z| + |re|) / 2)
u = |im| / (2 * t)
sqrt(z) = re >= 0 ? (t, copysign(u, im)) : (u, copysign(t, im))
**Overflow:** the operand is scaled by a power of two, so the overflow
fixed in https://github.com/llvm/llvm-project/pull/88480 does not come
back.
**Accuracy:** in a C model compared against glibc `csqrt` on random
inputs, the new expansion is within 3 ulp. The old one is off by 3 ulp
or more for about 30% of them.
[54 lines not shown]
[LAA] Decouple isNoWrap from getStrideFromAR (NFC) (#229903)
The call to getStrideFromAddRec in isNoWrap is unnecessary, and the
responsibility can be shifted to callers for clarity. The
createCheckForAccess use-site previously had a misleading nullopt Stride
argument.
[docs] Document some C++ standard library intrinsics (#247115)
This adds documentation for `__builtin_launder`, `__builtin_bit_cast`,
`__builtin_is_constant_evaluated`, and `__builtin_is_within_lifetime`
(ordered by their age within the C++ standard).
For each intrinsic, the description simply delegates to the cppreference
documentation for the standard library function, such as for
`std::launder`. Otherwise, we would need to maintain our own
documentation of behavior, which would be quite challenging.
[mlir][LLVM] Add an inherent strictfp attribute to intrinsic ops
Prototype alternative to the discardable llvm.strictfp attribute: give
every LLVM_IntrOp an optional `strictfp` UnitAttr in its arguments. Export
sets the call-site strictfp attribute, import reads it back. Constrained
and debug intrinsics opt out with `requiresStrictfp = 0`.
Ops that spell their own arguments now append baseArgs, assembly formats
without prop-dict print `strictfp`, and callers of builders that lost
their defaults pass the attribute explicitly.
Assisted-by: Claude Code (claude-opus-5-5).
[CUDA][HIP] Mangle language address spaces by name on the device
For a kernel that takes a pointer in a language address space, such as
`__attribute__((opencl_global)) int *`, the device mangles the address space by
number (`_Z6kernelPU3AS1i`) but the host mangles it by name
(`_Z6kernelPU8CLglobali`). The host registers the kernel with its own name, so
the kernel can't be found at launch. The host can't use the numbers instead,
since it doesn't know how the device maps them, e.g. SPIR-V chooses its map
based on the device's language options.
I understand this is not a typical CUDA code, because CUDA doesn't have the
concept of address spaces because of the "unified pointer" design, but I still
think the host and device code should be able to use the same mangling for the
same kernel.
This PR was assisted by AI but I reviewed all the changes.