[Flang] Use simple summation by default at all optimization levels
Add a scope option to SimplifyHLFIRIntrinsics and adjust the pipeline to
enable SUM expansion at -O0 while keeping other intrinsic expansions
conditional on array expression optimization. This makes simple
summation the default for SUM expansion across optimization levels.
Previously, floating-point SUM used the runtime's Kahan summation at
-O0, whereas -O1 and higher generally generated loops with simple
sequential addition. This expansion substituted a different algorithm
rather than inlining the runtime implementation, causing numerical
results to depend on the optimization level.
Add -fcompensated-sum to preserve the runtime's compensated algorithm
for REAL and COMPLEX SUM. When enabled, exclude SUM from HLFIR intrinsic
simplification and prevent SimplifyIntrinsics from replacing real SUM
runtime calls with uncompensated reduction loops.
Fixes #176282
[3 lines not shown]
Attributor: Fix inverted liveness lookup in checkForAllInstructions
attributor is 0.1-2.0% and attributor-cgscc 0.1-1.0% faster on CTMark
sources (callgrind).
Assisted-by: Claude
DAG: Don't zero a mostly empty CSE map on every clear
CSEMap never shrinks, so after one large block, clearing it zeroes a
large table even for small DAGs. Mesa hits this since it compiles many
functions with one pass manager.
Add a FoldingSetBase::clear() overload that takes the set's nodes and
zeroes only their probe chains. Use it when CSEMap is less than an
eighth full.
Compile time of radeonsi shader-db shaders: -1.0% (-0.9% cycles).
CTMark instructions:u: +0.01% (-O3), +0.003% (-O0 -g).
Assisted-by: Claude
[lldb][NFC] Don't copy the name index map in Symtab::FindFunctionSymbols (#248745)
GetNameToSymbolIndexMap() returns a reference, but `auto map = ...`
copied the whole UniqueCStringMap for each base name, method name or
selector lookup, which can be millions of entries for a large binary, to
read a few matches.
assisted-by: claude
Mips: Include the stack alignment override in the subtarget key (#248753)
The subtarget depends on the override-stack-alignment module flag, so
modules with different values need different subtargets.
Assisted-by: Claude
EntryExitInstrumenter: Don't pass the return address to __cyg_profile_func_enter_bare (#248706)
__cyg_profile_func_enter_bare does not take any arguments. It was
passed the return address on AArch64, LoongArch and RISC-V because it
shared the mcount path, which started passing it for _mcount in
eafbab6facb0.
Assisted-by: Claude
[ctxprof] Hold the samples lock while the root auto-detector reads them
The root auto-detector means to lock each thread's samples while it reads them, but the lock guard was an unnamed temporary, so the lock was released at the end of the same statement and the samples were read unlocked. Name the guard so the lock is held while the samples are read.
[ctxprof] Avoid blocking on flat profile allocation
Flat profile allocation previously blocked on the function and flat arena mutexes, which can stall or deadlock flat-profile allocation if a user-space fiber holds a lock while a sibling spins, or if a signal handler interrupts a thread holding one of those mutexes. Switch those acquisitions in getFlatProfile to TryLock and fall back to the scratch context when contended, and log the missed activation count on profile fetch when nonzero.
[ctxprof] Preserve live current root across nested and recursive entries
A failed TryLock in tryStartContextGivenRoot previously cleared __llvm_ctx_profile_current_context_root even when the thread already held an outer root, preventing the outer root from unlocking Taken on exit. Keep a live __llvm_ctx_profile_current_context_root intact across nested or recursive root entries and track the entry depth of the held root so Taken is unlocked only on its outermost exit.
[ctxprof] Track under-context depth across nested and contended roots
Entering a root marks the thread as under a root regardless of whether the thread acquires the root's collection lock, but exiting cleared that state only when the thread held the lock. Track a per-thread root entry depth instead, so flat profiling resumes once a contended root exits and stays suppressed across nested or recursive root activations until the outermost root exits.
A function the root auto-detector promotes while one of its activations is already running exits that activation without a matching entry. The depth does not go below zero, but if that activation runs under another root, flat profiling resumes on that thread before the outer root exits. This affects only activations in flight at promotion time; explicitly stated roots are not affected.
[libc] Use FPBits::is_inf() for printf and strfromx inf/nan checks (#248696)
On x86 80-bit `long double` (`X86_Binary80`), `FPBits::get_mantissa()`
excludes the explicit integer bit. Pseudo-infinities (`biased_exp ==
0x7FFF`, `int_bit == 0`, zero fraction) and zero-fraction unnormals
(`biased_exp != 0`, `int_bit == 0`, zero fraction) both satisfy
`is_inf_or_nan()` and `get_mantissa() == 0`, so `printf` and `strfroml`
formatted them as `inf` instead of `nan`.
Switch the inf/nan checks in `float_dec_converter.h`,
`float_dec_converter_limited.h`, `float_hex_converter.h`, and
`str_from_util.h` to `FPBits::is_inf()`, which requires `biased_exp ==
0x7FFF` and `int_bit == 1` with a zero fraction on `X86_Binary80` and
matches the prior check on implicit-bit formats. Rename
`mantissa_is_zero` to `is_inf` in `InfNanFPBitsProperties` and
`FloatHexExpFPBitsProperties`, and add `sprintf` and `strfroml` tests
for canonical infinities, pseudo-infinities, and zero-fraction
unnormals.
Assisted-By: Gemini
[Attributor] Restore the load/store and alloca walks
The callers should not have to know which AAs the seeding relies on.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[X86] Move subvector broadcast load reuse to combineBROADCAST_LOAD (#245000)
Move the ordinary-load fold from `combineLoad` to
`combineBROADCAST_LOAD`, extending its existing base-pointer use-list
search. This avoids walking a Chain use list for every eligible load
when there is no subvector broadcast. Reordering the per-user checks
alone would still traverse that list.
Replace matching loads with extracts from the broadcast and revisit it
to handle remaining loads. The pointer, input-chain, memory-size and
simple-load checks are retained.
Fixes #244549
[AMDGPU] Remove RegBankLegalizeRules::ST and refreshRefs (NFC) (#246265)
RegBankLegalizeRules::ST is only read in the RegBankLegalizeRules
constructor. This patch uses the ST constructor parameter directly and
removes the ST member variable. This patch also removes refreshRefs and
its sole call in getRules because refreshRefs has no remaining member
variables to update.
Assisted-by: Antigravity
[mlir][Presburger] Expand PresburgerRelation::gist unit test coverage
Add tests exercising getValidConstraintsHull with shared and unshared
equalities, local variables (filtering and Simplex column padding),
symbolic variables, and mixed rationally-empty/non-empty context
disjuncts.
[mlir][Presburger] Deduplicate candidate constraints in getValidConstraintsHull
Normalize and deduplicate candidate constraints across disjuncts, skip
trivially valid constraints and empty context disjuncts, and avoid
re-checking a context disjunct's own constraints against its own Simplex.
[mlir][Presburger] Fix universe early returns in PresburgerRelation::gist
- Canonicalize isObviouslyUniverse() inputs to getUniverse(getSpace())
instead of returning *this with redundant extra disjuncts.
- Delegate context.isObviouslyUniverse() to gist(IntegerRelation::getUniverse)
so redundant constraints and empty disjuncts are simplified consistently
with the convex overload.
[mlir][Presburger] NFC: clarify PresburgerRelation::gist docstrings and comments
Document how the PresburgerRelation overload differs from the
IntegerRelation overload via the union-level isSubsetOf check, and note
that the hasOnlyDivLocals() check is a cost guard to avoid expensive
Fourier-Motzkin elimination during subtraction.
[mlir][Presburger] Skip obviously empty context disjuncts in getValidConstraintsHull
Skip disjuncts where isObviouslyEmpty() holds (e.g., failing the equality
GCD test while remaining rationally feasible) before building a Simplex
so they do not needlessly weaken the hull.
[mlir][Presburger] Add PresburgerRelation::gist
Add PresburgerRelation::gist (and PresburgerSet forwarding overloads)
for a convex context and for a context that is itself a union of
disjuncts, following ISL's isl_map_gist / isl_map_gist_basic_map.
For a convex context, each disjunct is simplified separately with
IntegerRelation::gist; disjuncts that become empty are dropped and if any
disjunct becomes the universe, the universe is returned.
For a non-convex context, the trivial cases (universe set or context,
empty context, equal set and context, context being a subset of the
set) are handled first. Otherwise, the context is approximated by a
convex set. Instead of ISL's unshifted simple hull of the context and the
set, we use the universe together with all constraints of the disjuncts
of the context and of the set that are valid for every disjunct of the
context (checked with Simplex); including the constraints of the set
allows removing constraints that are implied by every disjunct of the
context even if they are not implied by the simple hull.
[mlir][Presburger] Restore original division definitions in IntegerRelation::gist
In IntegerRelation::gistAligned, the division-restoration loop only
checked divs.hasRepr(i) after dropping context-implied constraints. If a
local variable lost its original floor-division defining inequalities
because the context implied them, but another remaining constraint (e.g.
an equality) still gave that local a *different* division representation,
the original defining bounds were not restored—changing the local's
meaning and breaking gist(rel, ctx) ∩ ctx == rel ∩ ctx.
Save the initial DivisionRepr alongside divDefs and require the restored
representation to match the original denominator and dividend. Add a
minimal regression test extracted from FuzzTest.
[mlir][Presburger] NFC: clarify and polish IntegerRelation::gist docstring
- Document the universe-context behavior (removeRedundantConstraints
with unused local cleanup) and the case where context is rationally
non-empty but integer-empty.
- Replace FPL with Presburger and normalize bullet punctuation and
backticks.
[mlir][Presburger] Normalize constraints after each pivot in reduceUsingEqualities and gistAligned
Normalize modified rows by GCD after each pivot elimination to prevent
intermediate coefficient growth when eliminating multiple variables with
non-unit pivot coefficients.
[mlir][Presburger] Tighten asserts in rowReduce, eliminateVarUsingEquality, and reduceUsingEqualities
- Validate all column indices up front in IntMatrix::rowReduce so out-of-bounds
columns are still caught when pivotRow == numRows exits early.
- Assert eq.size() == getNumCols() and eq[col] != 0 in
IntegerRelation::eliminateVarUsingEquality(ArrayRef, col) even when the
relation has no constraints.
- Simplify space equality check in reduceUsingEqualities to space.isEqual.