[AMDGPU] Assume nonzero EXEC at kernel entry for VA_VDST
Waves are launched with at least one active lane, so in a kernel EXEC
can only become zero at an EXEC write that may produce zero. Until such
a write, VALUs after an always-issued VALU are issued as well and may
credit its accesses as VA_VDST successors.
Track this per bracket. It starts set in entry functions, is cleared by
EXEC writes that may produce zero, and merges by intersection. Blocks of
an entry function propagate their state even with no pending events, so
a cleared fact reaches every merge.
Assisted-by: Claude
[AMDGPU] Ignore EXEC writes that cannot zero EXEC for VA_VDST
Only an EXEC write that may produce zero can cause later VALUs to be
skipped. Moves of a nonzero immediate, ORs and WQMs of EXEC, and
S_OR_SAVEEXEC keep a nonzero EXEC nonzero, so pending VA_VDST accesses
keep their credit across them.
Assisted-by: Claude
[AMDGPU] Stop crediting skippable VALUs as VA_VDST successors
When EXEC is zero most VALUs are skipped and never increment VA_VDST,
but lane accesses, V_NOP, VALUs that write an SGPR, VCC or NULL, and
WMMA/SWMMAC are still issued. A skipped VALU therefore must not count as
a successor of a pending access that was issued, which happens across
EXEC writes and after WMMA/SWMMAC and lane accesses.
Mark pending accesses at EXEC writes, and the accesses of WMMA/SWMMAC
and lane accesses, which access VGPRs regardless of EXEC. The other
always-issued VALUs access VGPRs per lane, so they are assumed to access
none when EXEC is zero; they are counted but do not mark their operands.
A marked access keeps the count it had already earned and is otherwise
credited only by later always-issued VALUs and ordered XDL writes. A
later skippable access to the same register does not clear the mark.
Partial waits keep unsatisfied marked accesses pending, and merges take
the smaller count.
Assisted-by: Claude
[2 lines not shown]
[analyzer][NFC] Build the AST matchers of GCDAntipattern and OSObjectCStyleCast once (#246981)
- `GCDAntipatternChecker` and `OSObjectCStyleCastChecker` rebuilt their
large, heap-allocating matcher trees in `checkASTCodeBody` for every
function body.
- The matchers don't depend on the body, so build them once in the
checker constructors and keep them as type-erased checker fields.
- Fields rather than function-local statics, so no state is shared
between analysis runs in one process (e.g. unit tests).
- The checkers are in `optin.performance` and `optin.osx`, so only users
enabling them benefit; the win scales with the number of function
bodies.
Analysis-time impact (instructions retired in millions,
`unroll-loops=true`; inputs are the reproducers from
llvm/llvm-project#105512; ON = default graph trimming, OFF =
`graph-trim-interval=0`):
file mode before after change
[57 lines not shown]
[clang][PowerPC] Take a soft-float long double va_arg from four GPRs on 32-bit SVR4
With soft float, an IBM long double is passed in four consecutive GPRs,
or on the stack if fewer than four are left, word-aligned. va_arg took
it from GPRs whenever any was left, counted one GPR as used, and aligned
its overflow slot to 16, so the long double and everything after it came
out wrong even between clang-built caller and callee.
Assisted-by: Claude Code
[clang][PowerPC] Take two FPRs for a long double va_arg on 32-bit SVR4
An IBM double-double long double is passed in two consecutive FPRs, which
need not start at an even register, or in a doubleword-aligned slot of the
overflow area. va_arg counted it as one FPR and aligned its overflow slot to
16, so a variadic function read the wrong value for every long double after
the first: summing 1.0L, 2.0L and 3.0L gave 5.
Use two FPRs, send the value to the overflow area once seven FPRs are used,
and align its overflow slot to 8. GCC's va_arg does the same, and both
compilers already pass long double arguments this way.
Assisted-by: Claude Code
[AST][NFC] Use struct as string table for AttrDoc (#246986)
Using a StringRef array has two problems: first, the length evaluation
uses a strlen-like loop from std::string_view at compile time (could be
fixed with StringLiteral); and second, it causes dynamic relocations.
Store all strings in one single global (445 kiB) and store a second
array with the offsets indexed by the attribute kind. This avoids 7.5kiB
of .data.rel.ro and improves compile times of AttrDocTable.cpp.
For compatibility with older MSVC, struct members cannot use an
initializer directly at the member declaration in constexpr contexts but
need to use a separate initializer for the entire struct.
[BPF] Lower sdiv/smod to libcalls with --bpf-allows-libcalls (#245580)
### Summary
The BPF backend rejects signed division and remainder on targets without
native `sdiv/smod` instructions so any code using these operations fails
to compile.
This restriction exists because the kernel rarely has a use case for
signed division/remainder. However, we're using BPF to implement
userspace VMs and could perform software expansion of `sdiv/smod` when
the corresponding native opcodes are not available.
**Rust code snippet**
```
#[unsafe(no_mangle)]
pub fn entrypoint(input: *mut u8) -> u64 {
[57 lines not shown]
[analyzer] Don't charge the step limit for ending lifetimes
With cfg-lifetime, every LifetimeEnds element costs a step, and so does
entering a block that only ends lifetimes.
- Most of the analysis time is spent in entry points that exhaust
max-nodes, so these steps replaced real exploration.
- This lost paths and inlined calls compared to cfg-lifetime=false.
No change with cfg-lifetime=false.
Assisted-By: Claude
[analyzer] Remove dead bindings after lifetime ends at the block start
Dead bindings are always removed at the beginning of a block.
- With cfg-lifetime, a block may begin with LifetimeEnds elements, so its
first statement was no longer considered to be at the beginning.
- The states then kept the dead bindings for longer, so paths merged
later than without lifetimes, spending more of the step budget.
No change with cfg-lifetime=false.
Assisted-By: Claude
[analyzer] Don't let lifetime-only blocks affect the exploration order
The unexplored-first priority queues rank work items by how many times
their block was entered.
- A block that only ends lifetimes had its own visit count, so paths
reaching it got ranked differently than with cfg-lifetime=false.
- With a limited budget this changed which paths got explored, and which
callees got excluded from inlining by the block-count limit.
The unexplored_first stack only distinguishes the first visit of a
block. A lifetime-only block has a single successor and is passed
straight through on its first visit, so it can't change that order.
No change with cfg-lifetime=false.
Assisted-By: Claude
[analyzer] Don't count lifetime-only blocks in the inlining size heuristics
With cfg-lifetime, the CFG builder creates a block just for ending
lifetimes on scope exits that would otherwise need no block, e.g. where
the branches of an 'if' join at the end of a scope.
- These blocks pushed functions over the small/large/huge thresholds,
so enabling cfg-lifetime changed which functions got inlined.
- Through max-times-inline-large, this also starved inlining in later
entry points of the TU.
No change with cfg-lifetime=false.
Assisted-By: Claude
Revert "[AST][NFC] Use struct as string table for AttrDoc" (#246984)
Old MSVC doesn't support this type of assignment in constexpr
constructor.
Reverts llvm/llvm-project#246953
[AST][NFC] Use struct as string table for AttrDoc (#246953)
Using a StringRef array has two problems: first, the length evaluation
uses a strlen-like loop from std::string_view at compile time (could be
fixed with StringLiteral); and second, it causes dynamic relocations.
Store all strings in one single global (445 kiB) and store a second
array with the offsets indexed by the attribute kind. This avoids 7.5kiB
of .data.rel.ro and improves compile times of AttrDocTable.cpp.
[analyzer][NFC] Drop redundant reserve before append_range (#246889)
`llvm::append_range(C, R)` expands to `C.insert(C.end(), begin(R),
end(R))`. For `std::vector`, insert with forward-or-better iterators
computes the distance up front and performs a single allocation of the
exact size, so a preceding `reserve(std::distance(...))` of the same
range is redundant (and only adds an extra `O(n)` traversal for
non-random-access ranges).
The two sites in `RegionStore.cpp` append `map_range()` over an
`ImmutableMap`. `ImmutableMap` iterators are bidirectional and
`mapped_iterator` preserves the underlying iterator category, so the
insert already reserves. No other `append_range` call in the analyzer
has a reserve at the same site.
I didn't measure the perf impact of this, but I'm 100% it doesn't change
anything.
Assisted-by: Claude Code
[analyzer][NFC] Out-line PathSensitiveBugReport call-stack-hint bodies (#246958)
- Move `PathSensitiveBugReport::markInvalid`, `addCallStackHint`,
`hasCallStackHint` and `getCallStackMessage` bodies from `BugReporter.h`
into `BugReporter.cpp`.
- They instantiated `llvm::SmallSet` and `std::map` member functions in
every TU including the header, i.e. every checker.
Build-time impact (instructions retired, 196 `lib/StaticAnalyzer` TUs):
- Total: -0.81% (run-to-run noise ~0.23%).
- 161 TUs change by more than 0.15%, by -1.0% on average.
Assisted-by: Claude Code
[analyzer][NFC] Use DynamicRecursiveASTVisitor in two WebKit checkers (#246951)
RetainPtrCtorAdoptChecker and ForwardDeclChecker were the only checkers
in clang/lib/StaticAnalyzer still instantiating the CRTP
RecursiveASTVisitor. All the sibling WebKit checkers (RawPtrRef*,
NoDeleteChecker, RefCntblBaseVirtualDtorChecker, ...) already use
DynamicRecursiveASTVisitor, which is precompiled in clangAST and avoids
instantiating the full traversal in every user.
These two TUs were by far the most expensive in the analyzer. Converting
them to the same pattern as their siblings drops their compile cost from
~36.0G and ~34.6G to ~12.8G and ~11.6G retired instructions (release
with assertions, arm64, CMake PCH enabled, median of 3 runs):
RetainPtrCtorAdoptChecker.cpp -64%
ForwardDeclChecker.cpp -66%
which is about -1.8% of the total compile cost of all 196 static
analyzer translation units.
[5 lines not shown]
[analyzer][NFC] Out-line AnalysisManager::isInCodeFile (#246960)
- Move the `AnalysisManager::isInCodeFile` body from `AnalysisManager.h`
into `AnalysisManager.cpp`.
- It instantiated `llvm::StringSwitch<bool>` and the `SourceManager`
queries in every TU including the header, i.e. every checker, though
only a handful of places call it.
- The header no longer needs `clang/Basic/SourceManager.h`; include it
explicitly in `CoreEngine.cpp`, `DeadStoresChecker.cpp` and
`PaddingChecker.cpp`, which relied on it transitively.
Build-time impact (instructions retired, 196 `lib/StaticAnalyzer` TUs):
- Total: -0.54% (run-to-run noise 0.2-0.4%).
- 111 TUs change by more than 0.15%, by -1.1% over those.
Assisted-by: Claude Code