[CIR][OpenMP] Add support for omp single construct (#243797)
**Issue**: emitOMPSingleDirective was Not-Yet-Implemented, so #pragma
omp single hit error NYI in ClangIR codegen.
**Fix**: Lower OMPSingleDirective to omp.single, adding an emitNowait
clause emitter. allocate, copyprivate, firstprivate, and private clauses
remain NYI. Add CIR and LLVM lowering tests.
**Note**: In the LLVM IR tests, the outlined parallel function is
checked separately for ClangIR (LLVM-CIR) and classic codegen
(LLVM-OGCG). The control flow is the same in both, but the blocks are
named and ordered differently. See the test case comments for more
details.
Assisted by Claude.
Towards: #246586
[Sparc][MC] Check line and column of errors in assembler tests (#247426)
Pin the line and column of the expected errors in the SPARC assembler
tests, instead of only checking the message (or, in sparc-asm-errors.s,
the line with any column).
Also add --implicit-check-not=error: where it was missing so unexpected
errors are caught, and fix the gaps this shows:
- sparcv9-synthetic-instructions.s did not check the V8 error for the
second setuw.
- sparc-mem-asi-instructions.s did not check the V8 error for
"lduba [%i0+%i1] %asi, %o2".
- sparc-directive-xword.s had the same .xword test twice and only
checked the error for the first. Keep one, and use one check prefix
for sparc64 and sparcv9.
- sparc-vis3.s had --implicit-check-not=error: on the run that has no
errors instead of the one that does.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[LoongArch] Select [X]VSAT for vector clamps to narrower ranges
[x]vsat.{b/h/w/d} clamps each element to [-2^imm, 2^imm - 1], and
[x]vsat.{bu/hu/wu/du} to [0, 2^(imm + 1) - 1]. Select them for smin/smax
pairs and umin with such constant bounds, so that e.g.
```
lu12i.w $a0, -8
vreplgr2vr.w $vr1, $a0
vmax.w $vr0, $vr0, $vr1
vldi $vr1, -2433
vmin.w $vr0, $vr0, $vr1
```
becomes:
```
vsat.w $vr0, $vr0, 15
```
[4 lines not shown]
[LoongArch][NFC] Add tests for vector saturation to narrower ranges
Add tests for clamping vector elements to the range of a narrower signed
or unsigned integer, as produced by portable implementations of the
[x]vsat intrinsics.
Assisted-By: LLM
[LoongArch] Fold offsets past debug uses in LoongArchMergeBaseOffset
With `-g`, a DBG_VALUE of the base address counts as a use, so the
`hasOneUse()` check in `detectAndFoldOffset` rejects folding a following
ADDI/ADD into the address materialization, and the generated code differs
from `-g0`:
pcalau12i $a0, %pc_hi20(a)
addi.d $a0, $a0, %pc_lo12(a)
addi.d $a0, $a0, 5
Only count non-debug uses there and in the check for two ADDIs in a row.
After the fold the base register holds the address plus the offset, so
salvage its debug users by appending the negated offset to their
expressions, as RISCVMergeBaseOffset already does. In the two-ADDI case,
also redirect the debug users of the intermediate ADDI to the folded
register with the second immediate subtracted, instead of leaving them on
an erased definition.
Assisted-By: LLM
[LoongArch] OptWInstrs: Sign-extend outer PHI operands to remove sext.w in loops
A sext.w inside a loop often cannot be removed only because one of the
values reaching it comes in through a PHI from outside the loop and is not
known to be sign-extended, e.g. an i32 argument that is only any-extended:
preheader:
...
loop:
%p = PHI %x, %preheader, %next, %loop
%s = ADDI_W %p, 0
%next = ADD_D %p, ...
If every other value reaching the sext.w is sign-extended, sign-extend
those PHI operands in their incoming blocks instead and remove the sext.w.
This trades a sext.w executed on every iteration for one executed once per
entry into the loop.
Only incoming blocks with a smaller loop depth than the sext.w are
[8 lines not shown]
[RISCV] Preserve replicated masks in demanded bits simplification (#247452)
A replicated AND mask can be shrunk when the resulting constant has
an equal materialization cost. Queries at different recursion depths
can then shrink it further and restore the replicated mask, causing
DAG combining to loop indefinitely.
Keep the existing mask when it already matches the replicated
candidate. Add a regression covering both -O0 and -O2.
Fixes #247417.
Assisted-by: TRAE CLI (GPT-6)
[LoongArch] Avoid store forwarding blocks in small copies
Store-to-load forwarding fails when a load is wider than the store that
wrote its bytes, for GPR, FPR, LSX and LASX accesses alike. On LA664 such
a load takes 14-17 cycles instead of 7-10.
Small memcpy/memmove are lowered to ld.d/st.d, fld.d/fst.d, vld/vst or
xvld/xvst copies. Add a pass that breaks such a copy into smaller copies
when its load is likely to read data from in-flight narrower stores:
- A narrower store shortly before the load writes inside the copied bytes
through the same base register or frame index: break the copy around
the store.
- In a loop, a store of the previous iteration of at least 8 bytes may
write the same buffer, as in LZ77 back-reference copies: break the copy
into 8-byte pieces.
The pass runs at -O1 and above and can be disabled with
-loongarch-disable-avoid-sfb.
[6 lines not shown]
[LoongArch][NFC] Pre-commit tests for store forwarding blocks in copies
Small copies whose load reads data from in-flight narrower stores,
including LZ77-style overlapping copy loops reduced from the rustc-perf
bufreader benchmark.
[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][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
[Clang][Sema] Accept weak reference after declaration (#228809)
GCC accepts a weak reference even after there is a declaration. In here,
we use Check*Decl to do the required check and merge the NewDecl to
declaration chain.
Assisted-by: Claude # Tests ReleaseNote
Fixes: #56760
[InstCombine] Respect input denormal mode when folding ldexp (#247219)
InstCombine folds `ldexp(x, K)` into `fmul x, 2^K`. When `2^K` is
subnormal and the function's input denormal mode is not IEEE, the
multiply flushes the constant to zero so the result becomes zero instead
of the correctly scaled value.
We'd skip the fold in that case. The fold is unchanged under the default
IEEE mode and for normal scale factors.
Fixes #238186.
[clang] Do not use atomicrmw for compound assignment to a bool enumeration (#245856)
Fixes #245854.
`EmitCompoundAssignLValue()` allows `atomicrmw` for integer-like types
that are
not `_Bool`, so an enumeration with a fixed bool underlying type is
updated as a
plain integer and never renormalized to the bool representation:
```c
_Atomic enum E : bool { F, T } b;
b += 2; /* gives 0 at -O2, expected 1 (both are 1 at -O0) */
```
The IR is `atomicrmw add i8 2`, which leaves the object representation
as 2.
`b |= 2` is affected in the same way.
[6 lines not shown]
[lld][ELF][SPARC] Use the PLT for R_SPARC_WDISP30 calls (#246805)
Non-PIC code uses R_SPARC_WDISP30 for a call. It was handled as a plain
PC-relative reference, so a call to a function in a shared object got a
canonical PLT entry, a call to a protected function failed with "cannot
preempt symbol", and -shared rejected the call.
Handle R_SPARC_WDISP30 like R_SPARC_WPLT30. R_SPARC_WDISP30 is only used
by call, which never takes the function's address, so a non-canonical
PLT entry is enough.
This differs from GNU ld on purpose. GNU ld gives such functions
canonical PLT entries in an executable, and with -shared it emits
dynamic R_SPARC_WDISP30 relocations, which need DT_TEXTREL.
Assisted-by: Claude
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[clang][bytecode] Split up registering locals (#247160)
Split it into allocating the local and registering it in the
`VariableScope`. In the future, we will need to know if evaluating the
initializer failed before registering the local.
[mlir][vector] Do not fold contiguous gather/scatter on non-unit strides (#241601)
`FoldContiguousGather` and `FoldContiguousScatter` rewrite a
gather/scatter with indices `[0, 1, ...]` into
`vector.maskedload`/`vector.maskedstore` without checking the memref
layout. When the most minor memref dim has a non-unit stride, the result
fails verification.
This patch skips the fold unless `vector::isValidLoadStoreMemRefLayout`
(added in #241579) accepts the layout, so single-element gathers still
fold.
Fixes #240189
Assisted-by: Claude Opus 5.5