[RISCV][CFI] Implement resetCFIToInitialState for RISCVFrameLowering (#245548)
RISCVFrameLowering enables `CFIFixup` but left
`resetCFIToInitialState()` as a no-op, leaving stale CFA offsets and
callee-saved register rules active when transitioning from a framed
block to a frameless block.
Override `resetCFIToInitialState()` to reset the CFA to SP + 0 and emit
`.cfi_same_value` for callee-saved registers, updating affected test
expectations.
Close #240683
[MLIR][NVVM] Add compare and set Op (#247175)
This patch adds the compare and set Op which perform comparison
and return boolean vector mask of 1's or 0's.
Lit tests are added to verify the lowering to the intrinsics.
PTX ISA Reference:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#comparison-and-selection-instructions-set
Assisted-by: Claude Code
---------
Signed-off-by: DharuniRAcharya <dharunira at nvidia.com>
[clang] Remove unused includes (NFC) (#247478)
This patch removes unused #include directives across .cpp files under
clang/tools/ and clang/utils/. Identified by clang-include-cleaner and
verified locally.
Assisted-by: Antigravity
[bazel] Add -lrt to openmp (#247866)
When using the hermetic toolchain, which targets glibc 2.28 by default,
this is required. It doesn't hurt newer glibc versions
Rank an omitted directive like an explicit NOTHING
A WHEN clause that omits its directive was ranked without its runtime
condition, and the unguarded candidate of a match_any WHEN clause kept
only the condition's key. To still see the condition, isStrictSubset
counted a key without a condition trait as that trait, whatever its
polarity, and an omitted match_any clause whose static traits don't
match lost both its traits and its key. So, unlike an explicit NOTHING:
- An omitted match_none clause with `condition(a)` made a selector with
`condition(a)` a strict subset of it, although it requires `a` to be
false.
- An omitted match_any clause with `vendor(gnu)` didn't make a selector
with the same condition a strict subset of it.
- An omitted clause lost its condition's score.
Build an omitted directive's candidates the same way as an explicit
NOTHING; explicitness still only breaks ties. The unguarded candidate
of a match_any WHEN clause keeps the condition trait without its score,
so every runtime condition key now comes with a condition trait, and
[5 lines not shown]
[AMDGPU] Respect retained occupancy when comparing schedules
The scheduler can discard a schedule that spills fewer registers
because it compares occupancy beyond what the function can retain.
Cap both pressure comparisons at the function's retained occupancy.
A synthetic gfx1200 kernel spills 16 SGPRs instead of 32 at the same
two-wave limit.
AI assisted.
[libFuzzer] Use TerminateProcess for immediate exits on Windows (#247877)
On Windows, `_Exit()` calls `ExitProcess()`, which kills all other threads
and then runs `DllMain(DLL_PROCESS_DETACH)` for every loaded DLL while
holding the loader lock. libFuzzer often exits from a non-main thread
(timeout, RSS limit, or crash handler). If a DLL's detach handler waits on a
lock or a thread that was already killed, the process hangs instead of
exiting. We saw this on ClusterFuzz after `SUMMARY: libFuzzer: timeout`.
Add `ExitImmediately()`, which uses `TerminateProcess()` on Windows to skip
DLL detach, the same way as `internal__exit()` in sanitizer_common. Other
platforms still use `_Exit()`. Use it for all existing `_Exit()` calls in
libFuzzer.
Assisted-by: Gemini
[AMDGPU][NFC] Precommit test for SIFixSGPRCopies PHI-to-AGPR rewrite (#247814)
`processPHINode` moves a VGPR PHI to an AGPR class when all of its uses
are copies to AGPRs. A `DBG_VALUE` use of the PHI blocks the move, so
the class depends on `-g`.
The checks show the current behavior: the PHIs in `phi_agpr_use` and
`phi_agpr_use_64` become `agpr_32` and `areg_64_align2`, while the one
in `phi_agpr_use_dbg_value` stays `vgpr_32`.
This came up in the review of #245761.
Assisted-by: Claude Opus 5.5
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Co-authored-by: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Keep the condition key when a WHEN clause omits its directive
A WHEN clause that omits its directive is ranked without its condition,
and only its match_any unguarded candidate kept the condition's key.
Otherwise its selector lost the condition, so with
```
!$omp metadirective when(user={condition(b)}: taskyield) &
!$omp& when(user={condition(.true.)}, implementation={vendor(llvm)}: taskwait) &
!$omp& when(user={condition(b)}, implementation={vendor(llvm)}:)
```
the first selector wasn't a strict subset of the third, and TASKYIELD
was selected when `b` is true. Keep the key whenever the static traits
match, and let the key stand for the condition trait when it was left
out of the other selector's traits. The first selector then scores
zero, the explicit TASKWAIT wins the tie with the implicit NOTHING, and
TASKWAIT is always selected, as with an explicit NOTHING.
[7 lines not shown]
Only compare tied variants that share a runtime condition
Each tied variant was compared with every other tied variant until a
strict superset was found, trying the supersets found so far first.
When each superset has a different runtime condition, the cache never
hits, so a selection is quadratic in the number of tied variants, and
Flang selects repeatedly to build the ELSE chain. With 160 TASKYIELD
clauses with conditions `x(i)` followed by 160 TASKWAIT clauses with
the same conditions and `kind(cpu)`, MLIR generation took 3.3s instead
of 0.5s before this PR.
A variant with a runtime condition can only be a strict subset of one
with the same condition, so group the tied variants by condition and
scan only that group, keeping the cache per group. A variant without a
runtime condition still scans every tied variant. The example now takes
0.64s.
Co-authored-by: Copilot <223556219+Copilot at users.noreply.github.com>
Keep the condition key when a match_any WHEN clause omits its directive
The unguarded candidate of a match_any WHEN clause keeps its condition
key when the clause has a directive, but not when it omits one. A
selector with a key is then never a strict subset of one without, so
with
```
!$omp metadirective &
!$omp& when(user={condition(a)}, &
!$omp& implementation={vendor(score(4): llvm), extension(match_any)}: &
!$omp& taskwait) &
!$omp& when(user={condition(a)}, device={kind(host)}, &
!$omp& implementation={vendor(score(3): llvm), extension(match_any)}:)
```
TASKWAIT was also selected when `a` is false. Give both unguarded
candidates the key, so the first is again a strict subset of the second
and nothing is selected when `a` is false.
[9 lines not shown]
Add a three-way runtime condition tie to the tests
The first WHEN clause is a strict subset of the third, which ties with the
second. Clause order then tests `b` first, and TASKYIELD is never
selected.
Test ISA names against a retained condition key
A retained condition key counts as a trait, so it can make a selector
require more traits than one with different ISA names. isStrictSubset
now compares the ISA names in that case too, so with
```
!$omp metadirective &
!$omp& when(device={isa("sse4")}, &
!$omp& implementation={vendor(llvm), extension(match_any)}: taskwait) &
!$omp& when(user={condition(a)}, device={isa("avx")}, &
!$omp& implementation={vendor(llvm), extension(match_any)}: taskyield)
```
TASKWAIT is always selected, as when `a` is true. Test this case.
Co-authored-by: Copilot <223556219+Copilot at users.noreply.github.com>
Fold logical user conditions of any kind
EvaluateUserCondition only folded default-kind logicals, so a condition
like .false._8 stayed a runtime check. getConditionKey folded it on its
own and gave it the empty key of a constant, so the WHEN clause was
ranked like a true constant although it can never apply.
EvaluateUserCondition now folds logical constants of any kind, and
getConditionKey only sees runtime conditions.
The tests that expected a constant of another kind to stay a runtime
check now expect it to be resolved statically.
Count a retained runtime condition in the strict-subset check
The unguarded candidate of a match_any WHEN clause keeps its condition
key but not the condition trait, so it had one trait fewer than an
identical guarded candidate and counted as its strict subset. A key
without a trait now counts as a trait. A WHEN clause with an omitted
directive is ranked without its condition, so it no longer gets a key.
[flang][OpenMP] Don't treat different runtime conditions as subsets
When two METADIRECTIVE candidates have the same score and one selector is
a strict subset of the other, the superset wins. Flang ranks every
runtime condition with the same property, so isStrictSubset saw
different conditions as the same:
!$omp metadirective &
!$omp& when(user={condition(a)}, &
!$omp& implementation={vendor(score(4): llvm)}: taskyield) &
!$omp& when(user={condition(b)}, device={kind(host)}, &
!$omp& implementation={vendor(score(3): llvm)}: taskwait)
Both candidates score 5, and `b` was tested first, so TASKWAIT ran when
both conditions were true. Neither selector is a subset of the other, so
clause order should decide.
This patch adds a UserCondition key to VariantMatchInfo, and
isStrictSubset requires equal keys when the first selector has a
[14 lines not shown]
[flang][OpenMP] Compare complex parts and literal substrings by value
Expr equality had two gaps:
- ComplexComponent inherited Operation::operator==, which ignores
isImaginaryPart, so `real(z)` and `aimag(z)` compared equal.
- Substring compared literal parents by StaticDataObject::Pointer, so
substrings of identical literals, such as `'ab'(i:i)`, never compared
equal.
METADIRECTIVE lowering turns `user={condition(...)}` selectors into an
IF/ELSE chain. Since a condition is false on its ELSE path, Flang drops
the other candidates with the same condition there, using Expr equality
to compare them.
The first gap drops a different condition:
```
!$omp metadirective &
!$omp& when(user={condition(real(z) > 0.0)}: taskyield) &
[26 lines not shown]
Compare the condition of an unguarded match_any candidate
A match_any WHEN clause with a runtime condition also gets a candidate
without the condition, since its other traits can still match. That
candidate has no condition trait, so isStrictSubset skipped the key
check, and it became a subset of a WHEN clause with a different
condition. The key is now compared whenever it is set.
[DAG] combineShiftToAVG - match sub(A, not(B)) as avgceil
A - ~B == A + B + 1. DAGCombiner turns add(add(A, B), 1) into
sub(A, not(B)) if preferIncOfAddToSubOfNot is false, as on X86 for
multi-element vectors and on AArch64 for all vectors. D148809 delays
this until after legalization if the add of 1 has nuw or nsw.
combineShiftToAVG does not recognize the sub form, so the ceil average
is lost if the fold runs first. Match the sub form as well. If the not
has other users, only do it when the AVG node is legal or custom.
This shows up when the IR is written as a sub of a not, or when a
freeze is pushed through the adds and drops their flags. With #152107
the latter loses vpavgb/vpavgw in five AVX512F maskz tests of
avg-mask.ll, which match main again with this change.
Where the target expands the AVG node, the sub form now gets the code
of the add form, e.g. on RISC-V P, which has AVGSUBFLOOR but no
AVGCEIL, and for some Hexagon and ARM NEON types.
Assisted-by: Claude Code (Claude Opus 5.5)
[X86][ACEV1] Keep a tile config from resetting a written BSR
ldtilecfg runs bsr_init(), so a config the compiler places between a
BSR write and a read of that value throws the scales away. The config
cannot move above the write, because a call makes it volatile and -O0
puts one at the head of every block that uses tiles.
Mark the configs as writing bsr0, give BSR0 a register class so a
spill has a size, and preserve the value across the configs that
reach a read. Memory forms exist both ways, so this costs four
instructions.
Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
Fix a crash in handling this-pointer captured in nested lambdas in field initializer. (#245491)
Environment.initialize() currently crashes when handling a this-pointer
captured by a nested lambda expression appearing in a field initializer
of a struct. Consider the following example:
```cpp
struct {
int f = int f{[this]() { return [this]() { return 1; }(); }()};
}
```
When handling the this-pointer captured in the inner lambda,
Environment.initialize() tries to get the enclosing record by calling
getLambdaContext() on the lambda's Closure. However, getLambdaContext()
only works for the outermost lambda. For inner lambdas, it just returns
nullptr, which causes a null-dereference.
This PR fixes that issue by introducing a helper function that finds the
outermost lambda and get getLambdaContextDecl() from it.