[SCEV] Avoid predicate switch (NFC) (#236157)
The logic is basically the same in all four cases, implement it
once using getNonStrictPredicate + getSwappedPredicate.
[DAGCombiner] Fold extract + scalar2vec at lane 0 (#233856)
When extracting a scalar at index 0 from a vector and immediately
creating a new fixed-length vector with one lane only, we can just fold
that pattern into an extract_subvector pattern, given that the vector
element types align.
This removes redundant moves for vector reductions when the return is
handled as a one element vector.
These moves are not required when the result is in lane 0 already.
I used codex to generate the test cases.
[clang][OpenMP] Extend no-loop promotion to the split teams loop
Widen the no-loop promotion to apply not only to the fused target teams
distribute parallel for but include the same region written as separate
directives, other directives promotable to parallel for, and regions
carrying a schedule clause that asks for a mapping a no-loop kernel
already provides.
Use the SPMD_NO_LOOP kernel tag to carry the promotion decision, based
on whether the kernel can get fully promoted to a no-loop kernel. This
eliminates the previous discrepancy where a clause got the tag but not
the promotion.
[IndVarSimplify][NFC] Add tests for loop-invariant samesign compares (#236092)
Add tests for replacing a samesign compare of an IV with a
loop-invariant value by its value on loop entry.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[SCEV] Drop samesign in getLoopInvariantPredicate (#236093)
SCEV's `getLoopInvariantPredicate` tries to replace a comparison of an
IV against a loop-invariant value with the comparison value on loop
entry.
For that it tries to prove that the comparison is:
- (A) monotonic: i.e. if `c_i` is true, then `c_{i+1}` is true,
- (B) guards the backedge: the backedge is taken only if `c_i` is true.
Then each `c_i` may be replaced with `c_0`.
It works for the `icmp` instruction without the `samesign` flag.
With the `samesign` flag, however, the comparison is poison when its
operands have different signs.
To prove the backedge guard (B), we may rely on picking that poison as
true, while proving the monotonicity (A) may need the same poison to be
[28 lines not shown]
[clang][OpenMP] Emit lastprivate final copies in no-loop kernels
Promotion rejected lastprivate because the no-loop branch leaves the
worksharing path before it privatizes or copies out, so the clause would
have been silently dropped.
Privatize the non-counter variables in the parallel region and copy them
out under the last iteration that applyWorkshareLoop publishes, forcing
the exit barrier the copy reads through. Loop counters stay at the
distribute level and reach EmitOMPSimdFinal.
[AMDGPU] Take the VGPR and AVGPR maximum pressure from one point
max() of two GCNRegPressure values takes the VGPR and AVGPR counts from the operand with the larger sum of both. It does the same for the VGPR and AVGPR tuple weights. The SGPR and AGPR components still take the maximum of each component.
dumpMaxRegPressure() resets the maximum of the tracker before each instruction. It now compares the pressure of single instructions and does not depend on how max() combines two values.
Fix the expectations of the GCNRegPressureTest tests for this case. Add sched-max-pressure-different-points.mir and update the checks of the affected tests. rewrite-vgpr-mfma-to-agpr-spill-multi-store-mir.mir now uses the basic register allocator, as its sibling .ll test does since #226913.
[AMDGPU][NFC] Add unit tests for the maximum of GCNRegPressure over a block
The tests run GCNDownwardRPTracker and GCNUpwardRPTracker over one block and check the accumulated maximum pressure. In the block, an AV register is live first and a VGPR is live after it, so only one vector register is live at any point. The tests use 32-bit registers, and 64-bit registers for the tuple weights. The expectations show the current results, with a FIXME: the maximum adds the AV peak to the VGPR peak.
[ConstantFold] Use isImpliedByMatchingCmp() (NFC) (#236149)
Instead of reimplementing it, badly. The non-strict cases had some
incorrect entries (e.g. ule does not imply that ult is true). We got
away with this because those predicates are never returned by
evaluateICmpRelation().
[InstCombine] Remove redundant fold for shift of add of zexts (NFCI) (#236141)
The earlier `(X + Y) / 2 --> (X & Y) iff (X u<= 1) && (Y u<= 1)` fold
subsumes this special case where X/Y are zext of i1.
[MLIR][MathToXeVM][NFC] Remove a dead lit.local.cfg (#232911)
The lit.local.cfg in test/Conversion/MathToXeVM excludes
native-spirv-builtins.mlir when the SPIRV target is not built. #189494
deleted that test, so the file now excludes nothing. Remove it.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[clang][Lex] Skip to the end of directive after diagnosing 'defined' in an #embed parameter (#235934)
The `EvaluatedDefined` error path in `LexEmbedParameters` returned
without
discarding the rest of the directive, the only error path in the
function that didn't.
With any token following the parameter's closing paren, e.g.
#embed <f> limit(defined(x)),
`HandleEmbedDirective` hit its "expected success or to be at the end of
the directive"
assertion (a no-assert build would resume lexing mid-directive).
Discard the remaining tokens like the neighboring error paths do, and
add coverage
for both the `#embed` and `__has_embed` forms.
Fixes #212075
[clang] Fix acceptance of redefinition of a struct with different bit-field width (#235265)
The bug comes from `IsStructurallyEquivalent(Context,
Field1->getBitWidth(), Field2->getBitWidth())`
returning true when both `Field1->getBitWidth()` and
`Field2->getBitWidth()` are ConstantExpr types. Two bit fields were
treated as structurally equivalent even though their widths are
different.
This PR makes sure that two bit-fields with different bit-field width
are treated as structurally unequivalent under `-std=c23`.
Fixes #232748.
[SelectionDAG] avoid rounding exact f32->bf16 (STRICT_)FP_ROUND (#230557)
For f32-to-bf16, DAGTypeLegalizer::SoftPromoteHalfRes_FP_ROUND currently
ignores the Trunc flag and unconditionally lowers ISD::FP_ROUND to
ISD::FP_TO_BF16 as follows:
- On X86 targets with +avx512bf16 or +avxneconvert, ISD::FP_TO_BF16
lowers to vcvtneps2bf16, which is lossy (it flushes subnormals to zero
and quietens sNaNs.)
- On targets without hardware bf16 conversion instructions, it performs
rounding via a runtime libcall (e.g. __truncsfbf2) or a software
rounding sequence (which can also be lossy, e.g. quieting sNaNs).
The above is unnecessary and lossy; bitcasting to i32 and extracting the
upper 16 bits is cheaper and lossless. Do that.
Tested:
[11 lines not shown]
[ELF] Move ELF machine definitions to separate file (#236143)
Unify all definitions and uses with a single file to avoid
inconsistencies. Besides refactoring and deduplication, this:
- Fixes a few typos.
- Adds some names to llvm-readobj that were previously missing.
- Makes arch names consistently lower case.
- Replaces the large slow-to-compile StringSwitch with a static table.
[libc] Move <net/if.h> code and tests to net/if subdirectories (#236126)
This aligns the directory structure with other two-level headers like
<arpa/inet.h> and <netinet/ether.h> (which live in src/arpa/inet and
src/netinet/ether, respectively). It also makes docgen happy, as it
looks for function implementations in src/<header> (src/net/if here).
Previously, it would report all net/if functions as unimplemented.
The test suite is renamed to libc-net-if-tests, to match the directory
name (similar to libc-arpa-inet-tests).
Assisted-by: Gemini
[IVDesc] Return APInt for const-step (NFC) (#236039)
Rename getConstIntStepValue to getConstStepValue, and make it return an
APInt instead of a ConstantInt, improving code.
Reapply "[libc] Assert non-nullness in cpp::unique_ptr dereference operators" (#236083)
Reverts llvm/llvm-project#235768, re-applying #235658. Allocator
mismatches under asan have been fixed by #235777.
The original commit message was:
Add LIBC_ASSERTs to operator*, operator-> and (for the array version)
operator[]. Dereferencing an empty unique_ptr is UB, so we might as well
catch it in debug builds.
The death test is a bit awkward because LIBC_ASSERT fails differently
depending on the build mode. In full builds it exits with 0xFF, while in
overlay builds (or with LIBC_COPT_USE_C_ASSERT) it calls the system
assert, which raises SIGABRT. I've added a small helper macro to the
test to handle both cases.
Assisted-by: Gemini
[AArch64][NFC] Replace StringSwitch with EnumStrings (#236142)
Large StringSwitches generate a lot of code, which takes a long time to
compile (JumpThreadingPass on this function is the slowest pass
invocation in LLVM). Replace the StringSwitch with static strings.
This reduces the size of the object file by ~70 kiB and its compile time
by ~33%.
[ConstantFolding] Remove explicit inttoptr of ptrtoint fold (NFCI) (#236137)
Since #162279 this is already handled by DataLayout-aware
isEliminableCastPair().
[ARM] Check the alignment of generated vld2/4 with MVE. (#235675)
MVE requires element sized alignment on loads and stores, which we
usually work around by using byte size element instructions for larger
element sizes loads. As the same trick cannot be done for vld2/vld4, add
an alignment check which mirrors the code in
ARMTargetLowering::isLegalInterleavedAccessType.
[clang] Remove forward and friend declarations of non-existent types (NFC) (#236009)
This patch removes forward and friend declarations of classes that are
not defined anywhere in the codebase.
Assisted-by: Antigravity
[clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast_if_present (NFC) (#236007)
PointerUnion::dyn_cast has been soft-deprecated in favor of
llvm::dyn_cast and llvm::dyn_cast_if_present. This patch replaces
PointerUnion::dyn_cast with llvm::dyn_cast_if_present in
APINotesManager::findAPINotes.
Note that Readers[*Dir] is set to nullptr for the framework directory
when public or private API notes are found. If a private header is
included from a framework that only provides public API notes, Dir is
not redirected to PrivateDir, and Readers[*Dir] remains null.
This patch also adds a test case to cover that code path.
Assisted-by: Antigravity
[lld-macho] Reject incompatible arm64e object ABI markers
The CPU subtype of an arm64e object carries a pointer authentication ABI
marker. In a dynamic link, ld64 accepts only objects marked userland ABI
version 0, even on macOS and Mac Catalyst, whose executables are marked
version 1. It names any other marker as another architecture
(arm64e.old, arm64e.v1, arm64e.kernel, arm64e.kernel.v1 or unknown) and,
as with an arm64 object, ignores the file with a warning, or reports an
error with -arch_errors_fatal. This applies to archive members too.
lld linked these objects. Check the marker in the same way. ld64 accepts
unversioned and kernel-ABI objects in static links, so those links are
not checked.
Assisted-by: Claude Code