[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>
[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]
[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.
[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 a literal parent's StaticDataObject::Pointer, so
substrings of two identical literals, such as `'ab'(i:i)`, never
compared equal.
METADIRECTIVE lowering uses Expr equality to drop candidates whose
runtime condition already failed. With
```
!$omp metadirective &
!$omp& when(user={condition(real(z) > 0.0)}: taskyield) &
!$omp& when(user={condition(aimag(z) > 0.0)}: taskwait)
```
the ELSE path of `real(z) > 0.0` dropped the TASKWAIT candidate, so
[9 lines not shown]
[GVN] Treat Deadblock as Available
PRE insert load instruction if there is only one predecessor cannot be
eliminated. A deadblock can actually be treat as Available so that it
doesn't count into the BB that needs to insert load.
[AMDGPU] Precommit test for SIFixSGPRCopies PHI-to-AGPR rewrite
processPHINode moves a VGPR PHI to an AGPR class when all of its uses
are copies to AGPRs. A DBG_VALUE use currently blocks the move, so the
chosen class depends on -g.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[flang][semantics] Ignore a !DIR$ ALIGN directive that cannot be applied, with a warning (#247762)
The semantic checks of `!DIR$ ALIGN` (244506) made it an error to name
something the directive cannot align, or to put the directive after an
executable statement or outside a program unit. Existing code that other
compilers accept has such directives, for example `!DIR$ ATTRIBUTES
ALIGN` on a named constant, on the name of a derived type or on a
function result, and it no longer compiled.
Make these cases warnings under `-Wignored-directive`, and ignore the
directive for that name. The request is not recorded, so module files
and lowering do not see it. This follows what #180994 did for a
misplaced `IGNORE_TKR`. An alignment that is not a valid power of two
and two different alignments for one name stay errors.
A directive that follows a program unit was checked in the scope of that
program unit. Issuing a warning there aborted the compiler, which
`IGNORE_TKR` already did. Such a directive is now checked in the global
scope. There `IGNORE_TKR` gets its "must appear in a program unit"
[7 lines not shown]
[libc] Reject CPU affinity mask sizes above INT_MAX (#247852)
On Linux, `SYS_sched_getaffinity` and `SYS_sched_setaffinity` take a
32-bit `unsigned int` mask length, while
`linux_syscalls::sched_getaffinity` returns the written byte count as
`int`. Sizes above `INT_MAX` don't fit in `ErrorOr<int>` and narrow to
32 bits at the syscall boundary past `UINT_MAX`.
Return `EINVAL` for mask sizes above `INT_MAX` in
`linux_syscalls::sched_getaffinity` and
`linux_syscalls::sched_setaffinity`, and clear trailing mask bytes with
`inline_memset` in `sched_getaffinity`. Also add tests for trailing
zero-fill and for zero and `> INT_MAX` mask sizes.
Assisted-By: Gemini
[Clang] Check address space overlap for C-style casts to references (#244964)
In OpenCL and SYCL, `TryAddressSpaceCast` rejects a pointer cast between
two address spaces that don't overlap, but a C-style cast to a reference
is not checked (there is a FIXME for it). As a result, `(__local int
&)global_var` is accepted and we emit an `addrspacecast`.
This PR checks such reference casts in the same way. We only check the
case where the reference binds to the operand directly, i.e. the two
types are related. Other casts to a reference are not affected.
This PR was assisted by AI but I reviewed all the changes.
[llvm-rc] Allow '+' in identifiers (#247298)
Unquoted resource names and filenames in Windows resource scripts can
now contain '+' characters (for example, "libc++.dll" in user-defined
resources). Microsoft rc.exe accepts '+' within unquoted resource
identifiers.
Previously, Tokenizer::canContinueIdentifier() did not handle '+',
splitting "libc++.dll" into "libc", '+', '+', ".dll" and failing with
"expected int or identifier, got +".
Allow '+' in Tokenizer::canContinueIdentifier(), matching how '-' and
'/' are already handled.
Assisted-by: Antigravity, especially for tests and review
[VPlan] Insert induction end values to the end of the preheader
After future #182595 `VPWidenInductionRecipe` might reference `VPValue`s
defined in the preheader, so live-out value calculations must be
inserted at the end of the preheader to avoid def-after-use errors.
I believe modifying this transformation instead of adjusting #182595 is
the right fix that avoids any unnecessary implicit dependencies between
VPlan transformations. One possible fix in #182595 would be to emit
something like
```llvm
br i1 %stride.check, label %scalar, label %stride.expand.scevs
stride.expand.scevs:
%x = ...
...
br label %vector.preheader
[11 lines not shown]
[libc] Check upper key limit in TSSKeyMgr::is_valid_key (#247857)
`TSSKeyMgr::get_dtor`, `TSSKeyMgr::remove_key`, and `get_tss_value`
check `key >= TSS_KEY_COUNT` before indexing key storage, while
`TSSKeyMgr::is_valid_key` indexed `units[key]` directly. Check `key >=
TSS_KEY_COUNT` in `is_valid_key` as well so `set_tss_value` returns
`false` for keys at or above `TSS_KEY_COUNT`, and add `pthread_tss_test`
covering `pthread_key_*` and `tss_*` key validation.
Assisted-By: Gemini
[Clang][AMDGPU] Remove redundant isAMDGCN checks. NFC (#246818)
After the r600 target removal, AMDGPUTargetInfo is only created for
the amdgcn triple, so every `isAMDGCN()` check in it is always true.
Drop those checks and the helpers that only wrapped them.
```
if (hasFMAF())
Builder.defineMacro("__HAS_FMAF__");
-->
Builder.defineMacro("__HAS_FMAF__");
```
RFC: https://discourse.llvm.org/t/rfc-amdgpu-deprecating-and-removing-llvm-s-r600-terascale-backend/92840
RuntimeLibcalls: Add attributes to ObjC runtime calls (#244695)
Mark the ObjC runtime functions nounwind, and mark the argument of
the functions whose intrinsics mark their argument returned.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes to operator new and delete (#244712)
Annotate operator new and delete implementation variants. The nothrow
variants are nounwind. No library registers these yet so they don't
appear in the DeclareRuntimeLibcalls tests.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[Clang] Check address space overlap for C-style casts to references
In OpenCL and SYCL, `TryAddressSpaceCast` rejects a pointer cast between
two address spaces that don't overlap, but a C-style cast to a reference
is not checked (there is a FIXME for it). As a result,
`(__local int &)global_var` is accepted and we emit an `addrspacecast`.
This PR checks such reference casts in the same way. We only check the
case where the reference binds to the operand directly, i.e. the two
types are related. Other casts to a reference are not affected.
This PR was assisted by AI but I reviewed all the changes.