[lld][MachO][NFC] Don't let the output path trip cstring-dedup.s's check-not (#232631)
The __cstring check uses --implicit-check-not foo/bar, but llvm-objdump
prints the input file's full path first. When that path contains "bar"
(e.g. /home/isanbard/...), the test fails. Pass --no-leading-headers so
the path isn't printed. That also suppresses the "Contents of
(__TEXT,__cstring) section" line, so drop that STR check; --section
already restricts the output to __cstring.
Assisted-by: Claude Opus 5.5
[flang][OpenMP] Don't treat different runtime conditions as subsets
When two METADIRECTIVE candidates have the same score and one selector is
a strict subset of the other, the superset wins. Flang ranks every
runtime condition with the same property, so isStrictSubset saw
different conditions as the same:
!$omp metadirective &
!$omp& when(user={condition(a)}, &
!$omp& implementation={vendor(score(4): llvm)}: taskyield) &
!$omp& when(user={condition(b)}, device={kind(host)}, &
!$omp& implementation={vendor(score(3): llvm)}: taskwait)
Both candidates score 5, and `b` was tested first, so TASKWAIT ran when
both conditions were true. Neither selector is a subset of the other, so
clause order should decide.
This patch adds a UserCondition key to VariantMatchInfo, and
isStrictSubset requires equal keys when the first selector has a
[9 lines not shown]
[LFI][MC] Mark .note.LFI.ABI section with SHF_GNU_RETAIN (#233164)
Sections in a COMDAT group are subject to garbage collection during
linking when `--gc-sections` is enabled (even SHT_NOTE sections).
Because nothing references `.note.LFI.ABI.<arch>`, the deduplicated note
was previously removed by the linker with `-Wl,--gc-sections`.
Add `SHF_GNU_RETAIN` to `.note.LFI.ABI.<arch>` so that linkers recognize
it as a GC root while still deduplicating it via COMDAT.
Fixes #233086.
[libc][math] Add integer-only implementation for exp2f.
- Correctly rounded to all rounding mode (statically).
- Share core computations with expf integer-only static-rounding version
- Optimize for code size.
Assisted-by: Gemini for analysis and refactoring.
[libc] Add floating-point bitwise operations to FPUtil.
Add `fp_and`, `fp_or`, `fp_xor`, `fp_andnot`, and `fp_not` to
`src/__support/FPUtil/fp_bitwise.h` to perform bitwise operations on
floating-point values directly in FP/SIMD registers when SSE2 or AArch64 NEON
is available, avoiding GPR round-trips.
[mlir][ArithToLLVM] Preserve defined signed remainder by -1
Select a zero dividend when the divisor is -1 before emitting llvm.srem.
This preserves arith.remsi(INT_MIN, -1) == 0 without introducing LLVM UB.
Support scalar and vector operands, including multidimensional vectors.
Add regression coverage to the existing ArithToLLVM conversion test.
Tests were not run as requested.
[libc][NFC] Fix typo 'implemenation' in comments (#233089)
Fix the misspelling "implemenation" -> "implementation" in comments in
libc/src/__support/mathvec/*.h and libc/src/string/string_length.h.
No functional change.
[llvm-reduce] Parse library options into LLVMContext (#233162)
cl::ParseCommandLineOptions sets library options in T::Global,
no longer read by LibraryOptionsContext::get since #233044.
Switch to cl::parseCommandLineOptions.
[mlir][ArithToLLVM] Preserve defined signed remainder by -1
Select a zero dividend when the divisor is -1 before emitting llvm.srem.
This preserves arith.remsi(INT_MIN, -1) == 0 without introducing LLVM UB.
Support scalar and vector operands, including multidimensional vectors.
Add regression coverage to the existing ArithToLLVM conversion test.
Tests were not run as requested.
[libc++] Granularize <execution> (#229315)
Move execution policies into `__execution/execution_policies.h`
to separate them from upcoming C++26 sender/receiver components.
Also move `__type_traits/is_execution_policy.h` into `__execution`
directory.
This is a prerequisite for #229095.
[OpenMP] Fix construct context at TARGET and repeated-construct subsets
OMPContext has two bugs in how construct selectors are matched. Both can
select the wrong variant:
- The construct context should start at the innermost enclosing TARGET,
but Clang and Flang add every enclosing construct. Inside a TARGET
region nested in a PARALLEL, construct={parallel} matched the outer
PARALLEL. OMPContext::addTrait now drops the constructs recorded before
a target trait.
- A selector that only repeats a construct, such as
construct={parallel do, parallel} over construct={parallel do}, adds no
property. isStrictSubset required fewer properties, so a score tie
between the two fell back to clause order. A shorter ordered construct
sequence now also makes a strict subset. If the shorter selector has a
user condition, or an ISA name the longer one lacks, the tie still falls
back to clause order, since different conditions or ISA names share one
property.
[9 lines not shown]
[mlir][arith] Check overflow when reassociating integer constants
Folding (x + 100 nsw) + 100 nsw to x + (-56) nsw in i8 introduces
poison for inputs such as x = -100 that were previously defined.
Check signed and unsigned overflow when folding constants in the
add/sub/mul reassociation patterns. Retain each common nsw/nuw flag
only when its constant arithmetic does not overflow. Keep index
behavior unchanged for a separate fix.
Add regression coverage for invalid and preserved overflow flags.
[mlir][arith] Check overflow when reassociating integer constants
Folding (x + 100 nsw) + 100 nsw to x + (-56) nsw in i8 introduces
poison for inputs such as x = -100 that were previously defined.
Check signed and unsigned overflow when folding constants in the
add/sub/mul reassociation patterns. Retain each common nsw/nuw flag
only when its constant arithmetic does not overflow. Keep index
behavior unchanged for a separate fix.
Add regression coverage for invalid and preserved overflow flags.
Fix remaining condition identity collisions and mismatches
Follow up on #233038 by preserving Clang's substituted template bindings
when normalizing condition roots. Profile written array bounds through
TypeLoc, including typedef definitions and adjusted function parameters.
Retain bindings in function types and qualified member references, and
include template-specialization qualifiers and array-trait dimensions.
Use the same type normalization for qualified references and aliases.
Normalize Flang intrinsic declarations and implied-DO indices independently
of their scope-local symbol addresses. Preserve resolved procedure identity
and distinguish implied-DO bindings by nesting and type, allowing identical
conditions to participate in the strict-subset tie-break again.
Correct the Clang runtime symbol checks and declare-variant candidate
order. Exercise fresh matching after PCH loading, and add paired distinct
and identical expression controls. Update the implicit-NOTHING test to
check its guarded selection and barrier fallback under source-selector
subset comparison.
[LV] Check stores to invariant addresses before handling unsafe deps (#233142)
canVectorizeMemory validates stores to loop-invariant addresses only
after handling the case where LAA reports the loop as unsafe. The early
exit checking canVectorizeIndirectUnsafeDependences account for
histograms skipped the invariant address checks.
Reorder checks to make sure such accesses are checked even if there
histograms to fix miscompile.
[OpenMP] Preserve condition identity in subset ties (partial #233038)
Subset comparisons previously treated unrelated user conditions with the
same applicability trait as equal. This could select the wrong directive
when candidate scores tied. Add frontend-produced condition keys and
compare source selectors separately from their effective ranking traits.
The standalone Flang reproducer in #233038 now tests a before b and selects
TASKYIELD when both are true. The shared matcher retains the expected
strict-superset result for identical conditions and preserves precedence
when the first candidate has a higher score. This is a partial fix: known
identity defects and failing regression tests remain.
Implemented:
- Add owned condition keys and optional immutable original-selector
snapshots to VariantMatchInfo. Normalize condition truth bits only for
subset comparison, count condition presence once, and require matching
known keys when a prospective subset contains a condition. Keep the
[51 lines not shown]
[VPlan] Don't look through FOR splices in isUsedByLoadStoreAddress. (#233141)
isUsedByLoadStoreAddress incorrectly looked through recurrence splices.
This lead to makeVPlanMemOpDecision incorrectly replicating loads
(instead of widening), while the address is converted to a single-scalar
by legacy decision.
This fixes a miscompile in the added test.
[flang][OpenMP] Make sure that exec METADIRECTIVE is in execution part
A METADIRECTIVE can be in either the specification part or the execution
part, depending on whether the variant directives contained in it are
declarative or executable. The OmpMetadirectiveDirective AST node can
hold any combination of variants, that is it can represent both kinds.
When the parser builds the specification part and attempts to create
an OmpMetadirectiveDirective, once it gets one it puts it in the
specification part regardless of the contents.
When an executable METADIRECTIVE is the first statement of the execution
part, it will end up in the specification part. This is an identical
situation as that for utility directives.
Recognize executable METADIRECTIVEs at the end of the specification
part and move them over to the beginning of the execution part.
Create an isolated implementation branch from refreshed main and record its
base. Preserve existing local files. Keep B's diff separate from A's TARGET
normalization and construct-subset changes, and from C's scoring changes.
**Implementation approach.** Give the original condition an explicit,
frontend-produced structural identity. Preserve it across candidate copies
and transformations. Compare source selector identity separately from the
effective traits used for applicability and scoring.
Prefer an owned structural key with exact equality, or an interned equivalent
whose owner demonstrably outlives every comparison. LLVM should not depend
on Clang or Flang AST types. A hash can accelerate lookup, but hash equality
alone must never prove expression equality.
The largest design work is producing correct keys. Neither a raw source
string, a folded expression, nor the current generic Clang profile satisfies
the required contract. Complete the capture and equivalence checkpoint below
before treating a proposed key format as ready for integration.
[266 lines not shown]
LLVMgold: Parse -plugin-opt options into LibraryOptionsContext (#233144)
Since #233044, the LLVMContexts that LTO creates read the defaults
instead, so passes ignore options like -vectorize-loops.
Parse them into a cl::LibraryOptionsContext and set it as
lto::Config::LibraryOptions and the PipelineTuningOptions' context, as
lld does.
[VPlan] Only hoist from blocks guaranteed to execute in licm (NFC). (#232512)
When hoisting, licm assumes that all top-level blocks of the vector loop
region execute on every iteration, which holds as long as the region is
linearized. Check it explicitly, by only hoisting from blocks that
dominate the region's exiting block.
Currently NFC, but preparation to run LICM before linearization and
support partially linearized CFG.
PR: https://github.com/llvm/llvm-project/pull/232512
[LV] Add test for miscompiles with histograms and scalarization. (#233135)
Add 2 additional tests for miscompile with stores to invariant addresses
and histograms and incorrectly scalarizing loads feeding a first-order
recurrence.
Also modernize check lines while touching the tests.
[LV] Don't emit duplicate negative stride runtime checks
This speeds up x264 by 2.15% on RISC-V by avoiding a duplicate hoisted runtime check.
When hoisting runtime checks we need to check that any strides are non negative. But for a loop like
```c
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
dst[(i * stride1) + j] = src1[(i * stride2) + j] + src2[(i * stride2) + j];
```
We have the pairs [dst, src1] and [dst, src2]. Both pairs end up checking that stride1 and stride2 are non-negative in IsConflict, and because there's other values between the two checks in the chain of ors InstCombine can't deduplicate it. This PR deduplicates the stride checks.
I'm aware some of this memory check stuff is being moved into VPlan but I'm not sure what the plan is with hoisted runtime checks, so it seemed better to just fix it here first.
This helps all targets but the motivating case is this loop in x264:
```c
[82 lines not shown]