[analyzer][NFC] Cache the AST-only part of the loop unrolling decision (#246977)
- With `unroll-loops=true`, `updateLoopStack()` runs
`shouldCompletelyUnroll()` every time a path enters a loop.
- Its first half is a pure function of the loop's AST: it rebuilds the
large `forLoopMatcher()` tree, matches it, and evaluates the bound.
- Memoize that half per loop in a `LoopUnrollingCache` owned by `ExprEngine`.
- The path-dependent `isPossiblyEscaped()` still runs on every entry,
but now builds its matcher once per call instead of once per visited
statement.
- `unroll-loops` is off by default, so only users enabling it benefit.
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
ruby-unicode.c ON 22710 21334 -6.1%
[11 lines not shown]
[SLP][modularisation][NFC] Move BoUpSLP class definition to SLPTree.h
Move the BoUpSLP class definition and its nested types out of
SLPVectorizer.cpp into the internal header SLPVectorizer/SLPTree.h. Method
definitions outside the class body stay in SLPVectorizer.cpp.
The header is self-contained: it compiles as the only include of a
translation unit and does not depend on anything SLPVectorizer.cpp defines
before including it.
- The limits MaxMemDepDistance and MinScheduleRegionSize, used by inline
scheduler code, move with the class and become static constexpr.
- ReductionVectorPart moves with the class, since BoUpSLP::vectorizeTree
and removeInstructionsAndOperands take ArrayRef<ReductionVectorPart>.
- DenseMapInfo<BoUpSLP::EdgeInfo> moves after the class, since inline
BoUpSLP code instantiates maps keyed on EdgeInfo.
- The header defines DEBUG_TYPE for the LLVM_DEBUG uses in the inline
scheduler code and undefines it at the end.
- getShallowScore gets a function-local PatternMatch using-directive.
[7 lines not shown]
[X86] Add test coverage for #245048 (part 2) (NFC) (#247144)
More test coverage for #245048. These cases change with it: VZEXT_MOVL
of an and with a constant pool load, of compares and ands of fptosi
results, of an abs or an and of a VTRUNC, of movd/movq loads, and of
PSADBW, PMULUDQ and PHADD results, unary shuffles of a binop with a
VTRUNC operand, and a splat udiv constant under optsize that loses its
broadcast.
Assisted-by: Claude Code (Claude Opus 5.5)
[Clang] Added explanation why is_trivially_copy_constructible evaluated to false (#225487)
Clang now adds notes explaining why is_trivially_copy_constructible fails.
An internal-only trait `IsTriviallyCopyConstructible` is also added to `BuiltinTraits.td`,
with only a `StdName`, to reuse the existing std name table mapping machinery.
Part of #141911.
I used an AI assistant to understand the relevant
parts of Clang and to review my changes.
Co-authored-by: Darshan N <Darshan.N3 at ibm.com>
[MLIR] Fix inlining with missing debug locations (#244207)
Inlining a function without debug info into a caller with debug info can
leave nested calls without required locations. Use line-zero fallback
locations in MLIR to preserve caller scope. Add regression tests.
Assisted-by: Codex
[mlir][bufferization][NFC] Remove dead options branch in OneShotBufferizePass (#247013)
PR #129850 removed the `OneShotBufferizePass` constructor that took a
`OneShotBufferizationOptions`, but kept the private member `options`. It
is always equal to `std::nullopt` and therefore the branch inside
`runOnOperation` becomes redundant as it always takes `if (!options)`
and never reaches `else` block. Remove the unused member `options` and
the `if` statement at the start of the `runOnOperation`.
[mlir][bufferization] Fix memory space crash at function boundaries (#246906)
With `bufferize-function-boundaries`, computing the bufferized types of
function arguments and results dereferences the value returned by
`options.defaultMemorySpaceFn` without checking it. The callback returns
`std::nullopt` under `must-infer-memory-space`, and for unranked tensors
under `use-encoding-for-memory-space`, so both cases crash.
Instead, emit "could not infer memory space for argument #N" (or "result
#N") on the function and propagate the failure, as ops inside function
bodies already do.
Assisted-by: Claude
[GlobalISel][X86] Fix legalizer abort on vector G_CTPOP (#235976)
Fixes #220802.
X86: mark vector `G_CTPOP` legal with AVX512VPOPCNTDQ (D/Q) or
AVX512BITALG
(B/W) at 128/256/512 bits. Without VLX the `avx512_unary_lowering`
widening
patterns in `X86InstrAVX512.td` select the 512-bit instruction; other
vector
forms are still reported unsupported instead of crashing.
AI tool use: developed with Codex CLI assistance under the contributor's
direction.
[mlir][Tensor] Don't merge pads with negative constant padding (#246957)
FoldConsecutiveConstantPadding adds up the paddings of two consecutive
tensor.pad ops. When both paddings are constants, the sum is folded into
the static attribute. A negative constant padding is valid IR as long as
it is passed as an SSA operand (#231389), but merging such a pad can
produce a negative static padding, which PadOp::verify rejects. So
canonicalization turns IR that verifies into IR that does not:
%c = arith.constant -3 : index
%0 = tensor.pad %t low[2] high[0] {...} : tensor<4xf32> to tensor<6xf32>
%1 = tensor.pad %0 low[%c] high[0] {...} : tensor<6xf32> to
tensor<?xf32>
error: 'tensor.pad' op padding must be non-negative, got -1
Do not merge the two ops if either of them has a negative constant
padding. This matches FoldStaticPadding, which keeps negative constants
as SSA operands. An AI assistant was used to help find and fix this, and
I have reviewed the change.
[FuzzMutate] Remove -use-undef (#247129)
As undef is deprecated, we no longer care about undef bugs found by
fuzzers. Remove the untested -use-undef option added in
https://github.com/llvm/llvm-project/pull/84959, it seems pointless to
port this to the new options system. This remove the use of global ctors
from LLVMFuzzMutate.
[SelectionDAG] Look through freeze in CombineExtLoad
Folding an extend of an illegally-wide vector into extending loads only
matched when the extend operand was the load itself. A boolean select is
combined to an OR of a frozen operand and the freeze is pushed down to the
load, so the fold was skipped: the load stayed a plain vector load and each
half of the widened result needed an extract and a register-form extend.
Look through a single-use freeze and re-apply it to the split result.
Freeze is element-wise and extends are deterministic, so freezing the split
loads is equivalent to freezing the extended value.
For the loop in #245064 this replaces four 512-bit loads with their extracts
and register-form vpmovzxwd by memory-form vpmovzxwd, going from 57 to 49
instructions per 128 elements.
Adds llvm/test/CodeGen/X86/vector-extload-freeze.ll and updates the
existing avx512-ext.ll checks.
Fixes #245064
[mlir][tensor] Implement InferIntRangeInterface for scalar/tensor bridge ops (#247004)
Implement integer range inference for `tensor.extract`,
`tensor.from_elements`, `tensor.insert`, and `tensor.splat`, mirroring
the existing `vector` dialect implementations. The range of a tensor
value bounds all of its elements, so:
- `tensor.extract` and `tensor.splat` forward the range of their
tensor/scalar input.
- `tensor.insert` produces the union of the scalar and destination
ranges.
- `tensor.from_elements` produces the union of the element ranges, or
the maximal range for an empty tensor.
This lets integer range analysis flow through scalars that are
round-tripped through tensors, including single-element tensors such as
`tensor<i32>` operated on by elementwise `arith` ops.
Since dynamically shaped tensors can now have a known constant range,
[6 lines not shown]
[analyzer][NFC] Memoize inferred symbol ranges per ProgramState
The inferred range of a symbol is a pure function of the ProgramState, yet
simplifying an SVal queries the range of every sub-expression again and again
against the same state. Memoize the ranges for the most recently queried
state in RangeConstraintManager (a DenseMap<SymbolRef, RangeSet> plus the
state it belongs to; it is cleared when a different state is queried).
SymbolicRangeInferrer takes the cache as an optional, nullable pointer; the
static inferRange() call sites pass none (a stack-local cache there never got
a lookup: 0 hits over 76406 instances on the corpus below).
Why this is safe: the cache holds a ProgramStateRef, so the state stays alive
and its address cannot be recycled for a different state while it is the
cache key. To make that hold at destruction time, ConstraintMgr is now
declared last in ProgramStateManager and is destroyed first, while the state
set, the allocator and the GDM contexts are still alive. ~ProgramStateManager
is declared out of line because the defaulted one needs the complete types
used by the members. Behavior is unchanged: the diagnostics are
byte-identical on every input below, and check-clang-analysis passes
[72 lines not shown]
[analyzer][NFC] Let GDMContextsTy destroy the GDM contexts (#246899)
ProgramStateManager destroyed its GDM contexts by hand in its
destructor. Make GDMContextsTy a small non-copyable class that owns the
map and destroys the contexts in its own destructor, so the ownership is
expressed by the member rather than by the enclosing destructor.
Assisted-by: Claude
[LoopUtils] Check the first outer iteration for co-moving pointer groups
When runtime checks are hoisted out of the outer loop, the range of each
pointer group is widened to cover all iterations of the outer loop. If both
groups of a check advance by the same step in the outer loop, e.g. two rows
of the same image:
```cpp
for (y = 0; y < H; y += 2)
for (x = 0; x < n; x++) {
img[y*S + 3*x] = ...;
img[(y+1)*S + 3*x] = ...;
}
```
the widened ranges overlap as soon as the outer loop runs twice, so the
check always fails and the vector loop never runs.
If all bounds of both groups are affine AddRecs of the outer loop with the
[7 lines not shown]