[CodeGen] Port MIRAddFSDiscriminators to the new pass manager (#247977)
Mostly standard Pass porting.
There is one change to how the pass reports modifications. During Pass1,
the existing algorithm can reset a pseudo probe’s debug location and
then skip the rest of the loop iteration. If that reset was the only
edit, the legacy pass returned false. The shared implementation now
reports a change when the reset actually replaces the DILocation. A
reset alone still does not trigger creation of
@__llvm_fs_discriminator__
1. Is preserving CFGAnalyses sufficiently precise when only a probe’s
debug location changes? The new wrapper returns all() when the helper
reports no change and preserves CFGAnalyses on the changed path. I found
two relevant precedents.
[RemoveRedundantDebugValuesPass](https://github.com/llvm/llvm-project/blob/6974a633957d97df4652fbe38f9432d02740fe18/llvm/lib/CodeGen/RemoveRedundantDebugValues.cpp#L224-L240)
preserves the machine-pass baseline and CFG analyses after removing
debug instructions. The IR-level
[13 lines not shown]
[flang] Mark Cray pointer targets across declarations of the same COMMON block (#248161)
Distinct declarations can give different symbols to the same COMMON
storage.
This is a follow-up for a missed case in #241388
Assisted-by: AI
[flang] Implement FortranObjectViewOpInterface for fir.emboxchar and fir.unboxchar (#248704)
`fir.emboxchar` and `fir.unboxchar` only pass the address of CHARACTER
data through, but alias analysis could not follow an address across
them. Any access through an unboxed address was reported as MayAlias
with everything.
This patch implements `FortranObjectViewOpInterface` for both
operations, using the null view source added in
https://github.com/llvm/llvm-project/pull/248212:
* `fir.emboxchar`: the result is a view of the memref operand at offset
0.
* `fir.unboxchar`: the address result is a view of the boxchar at offset
0. The LEN result has no view source.
`fir.unboxchar` is the first view operation with two results, so two
users of the interface are adjusted:
[43 lines not shown]
[CIR] Support __builtin_elementwise_ctzg and __builtin_elementwise_clzg (#246181)
### Description
This patch adds support for `__builtin_elementwise_ctzg` and
`__builtin_elementwise_clzg` in `CIRGenFunction::emitBuiltinExpr`,
establishing parity with classic Clang CodeGen
(`clang/lib/CodeGen/CGBuiltin.cpp:3438-3505`).
This change:
1. Extends `CIR_BitClzOp` and `CIR_BitCtzOp` in `CIROps.td` to accept
`CIR_ScalarOrVectorOf<CIR_UIntOfWidths<[8, 16, 32, 64, 128]>>`.
2. Casts signed scalar/vector operands to unsigned in
`createBuiltinBitOp` for `cir::BitCtzOp` / `cir::BitClzOp` and casts the
result back to the expression type.
3. Adds `isElementwise` (forcing `poisonZero = true`) and vector
zero-fallback selection (`cir::VecCmpOp` + `cir::VecTernaryOp`) to
`emitBuiltinBitOpWithFallback`.
4. Adds CIR, LLVM IR, and classic CodeGen (`OGCG`) parity tests in
[4 lines not shown]
PowerPC: Use LastSubtargetCache in getSubtargetImpl
Migrate to use the new common infrastructure and pattern which caches
based on the last used subtarget.
Assisted-by: Claude
[RISCV] Add RVV CSRs to the realigned frame chart
The vector callee-saved registers of a realigned frame sit above the
realignment, at a fixed offset from FP, not with the other RVV objects.
Show them there in the frame layout chart, and point to it from the
code that addresses them. NFC.
Attributor: Fix inverted liveness lookup in checkForAllInstructions (#248774)
This was inverted by 2f7ef7b.
attributor is 0.1-2.0% and attributor-cgscc 0.1-1.0% faster on CTMark
sources (callgrind).
Assisted-by: Claude
[CodeGen] Fix -Wunused-variable in 7f4b9a6 (#248970)
528bd82 attempted to fix this but only fixed part of it. This should fix
the issues with the original commit entirely. Just inline the definition
of the variable given it has no other users, the name does not add
significant clarity, and the call should have no side effects.
[SelectOpt] Add support for GEP operands (#237300)
A single-index GEP whose index is a `zext`/`sext` of an `i1` condition C,
or a sign-bit `lshr`/`ashr` checked by C, is `select(C, GEP(P, 1), P)`
(`GEP(P, -1)` for `sext`/`ashr`). Treat it as a select-like so it joins
the select group of the same condition, which lets loop-carried pointer
increments in merge-like loops become branches. The cloned GEP is costed
as an add. GEPs are only used where `shouldTreatInstructionLikeSelect`
accepts them, which this patch enables for AArch64.
Also fix an assert on shift amounts wider than 64 bits, goldbolt link:
https://godbolt.org/z/vzhMha6PP
Assisted-By: Claude Opus 5.5 <noreply at anthropic.com>
[ctxprof] Track UnderContextDepth while root auto-detector is active
Increment UnderContextDepth when entering a function that already has a ContextRoot while the root auto-detector is running, keeping entry balanced with __llvm_ctx_profile_release_context.
[X86] Enable SlotIndexes compaction by default
Compacting SlotIndexes before greedy allocation drops the entries of
erased instructions, so live range sizes and instruction distances
reflect the code being allocated rather than how much was erased
before it. AMDGPU has done this since #235806; do the same for X86.
Codegen changes only through allocation: no new crashes, verifier
errors or allocation failures in the lit suites, including
EXPENSIVE_CHECKS, and a stage-2 build of LLVM, clang and lld with
-verify-machineinstrs passes its own tests. On llvm-test-suite at -O3,
spills drop 0.3% and .text 0.06%, with compile time unchanged.
Most test updates are regenerated checks. misched-matmul now inserts
20 spills instead of 24. live-debug-vars-stale-slotindexes.mir gets
one more use of %27 so that accumulate_fit still reaches the stale
index path it was written for. reloc-opt.ll gets an NF add that keeps
its source live, because compaction compresses the existing one to the
legacy form. inline-spiller-hoist-folded-copy.ll gets four empty asm
[2 lines not shown]
[AMDGPU] Fix notfe being assembled as tfe in buffer loads (#248865)
'buffer_load_dword v[1:2], off, s[4:7], s1 notfe' is currently assembled
as its tfe version. In the asm strings of the TFE variants, tfe is a
token, with parseCustomOperand() parsing it with parseNamedBit() and
validateTargetOperandClass() accepting the resulting operand for the
token -- whatever its value.
The fix makes tfe a normal named-bit operand of the real buffer
instructions, like lds. The TFE variants require it to be set and the
buffer loads and stores that have TFE variants accept notfe.
Side effects:
- notfe is now accepted on the buffer loads that have TFE variants,
e.g., 'buffer_load_dword v1, off, s[4:7], s1 notfe', and rejected on the
TFE variants themselves. Previously, it was only accepted on the TFE
variants. tfe on stores is still rejected.
[4 lines not shown]
CloneFunction: Treat invokes as calls when pruning
The pruning cloner handles a block's terminator separately from its
other instructions, and skipped two pieces of call bookkeeping for an
invoke. #248341 fixed the same omission for memprof metadata.
An indirect invoke was not recorded as an originally indirect call.
Inlining could turn it into a direct call without !inline_history,
unlike the equivalent call.
An invoke also did not set ClonedCodeInfo::ContainsCalls, so the
inliner did not collect the invokes inlined from a callee with no call
instructions. Those invokes were not given inline history or revisited
for inlining. Do the same in the non-pruning cloner.
Assisted-by: Claude
LinuxKPI: pci: implement pci_clear_and_set_config_dword()
Implement pci_clear_and_set_config_dword() as a combination of
read and write config_dword. Note while the read function returns
an error value its current implementation can never fail so we do
not have to deal with the error case.
This is needed by an rtw89 update.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60687
LinuxKPI: add field_get() and FIELD_GET_SIGNED()
An updated rtw89 driver uses both so add them with the added
__FIELD_GET() not doing any extra checks. We assume the Linux
counterpart will do that and drivers will fail them there, so
no need to add assertions here.
MFC after: 3 days
Reviwed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60716
LinuxKPI: firmware: ensure name stays valid
The name argument passed into request_firmware_nowait() may only be
valid locally in the calling function and could be out of scope by the
time the task runs; make a copy to ensure it stays valid over the
callback.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60630
LinuxKPI: add spinlock_bh guard support
We will likely have to add more DEFINE_LOCK_GUARD_1 cleanup.h
defintions for various lock types. Add the one for spinlock_bh
as a wireless driver update needs it.
MFC after: 3 days
Reviewed by: dumbbell
Differential Revision: https://reviews.freebsd.org/D60631
LinuxKPI: rework cleanup.h to use CLASS
After adding DEFINE_CLASS and CLASS in f2a2e02ae54b to cleanup.h
cleanup that file some from the original implementation:
- Rename CLEANUP_NAME to LKPI_CLASS_NAME to (a) match the CLASS
implementation idea and (b) tell it is an internal macro and not
a LinuxKPI one.
- consistently use LKPI_CLASS_NAME() rather than doing multiple ##.
- consistently use _constructor and _destructor instead of _create
and _destroy.
- consistently use _name instead of _n and _type instead of _t; the
latter helps a lot to keep the typedef _type LKPI_CLASS_NAME(_name, _t)
apart.
- With this the former DECLARE now matches CLASS so remove the former
in favour of the latter.
- With this DEFINE_GUARD() can now be implemented as a single
LINUXKPI_]DEFINE_CLASS() call.
- In guard() and scoped_guard() start using __UNIQUE_ID() which was
added in 8b05d84be9e28 rather than manually using ## __COUNTER__.
[7 lines not shown]
[GVN] Scan MemUses of the clobber found by the MemorySSA walker
Previously, if the clobber found in Phase 1 is a MemoryPhi or a
MemoryDef outside the current BB, we proceed directly to Phase
2/3. However, the clobber returned by the walker may still have users
in the current BB, which can be candidates for available values.
As a result, we add support for scanning MemoryUses of the clobber
returned by the walker before proceeding to Phase 2/3.
Assisted-by: Claude # Test
Firewall: Schedules: replace legacy schedules editor with MVC legacy mapper (#11228)
Add a schedule model that preserves the legacy XML structure and assigns UUIDs to schedules and time ranges. Field types expose annual dates, start and stop times, and the current active state while retaining compatible storage.
Add controllers, forms and a responsive master/detail view with calendar inputs, active-state sorting, cloning and bulk deletion. Save changes separately from applying them through an explicit reconfigure action.
Keep schedule names immutable and prevent deletion when referenced by firewall rules. Validate time ranges and provide user-facing errors for missing parent schedules. Add focused field-type tests.
Remove the legacy editor pages and update menu entries, firewall rule links, ACLs and package contents to use the MVC page.
[clang] Make the PCM alignment test independent of the COFF writer
The test relied on the MC COFF writer happening to place the clangast
section at an unaligned offset. That offset depends on which sections the
writer emits and on the codegen of the ASan module constructor, so
unrelated changes could break the test or quietly make it test nothing.
Instead, re-wrap the AST file in a COFF object built with yaml2obj and
llvm-objcopy, which places the clangast section at a known unaligned
offset, and check that offset exactly.
[clang] Ensure the AST file extracted from a PCM is aligned
The COFF object writer doesn't align section contents within the file, so
the `clangast` section of a `-fmodule-format=obj` PCM may start at an
unaligned offset. The readers use the AST file in place, which trips the
on-disk hash table alignment assertion.
Before #242384, the importing compiler instance copied the AST file out of
a freshly built PCM into a (suitably aligned) heap buffer, which hid the
issue for that PCM. However, reading the PCM from disk has always used the
memory-mapped file directly, which happens when:
* reusing the implicit module cache in a subsequent compilation,
* reading a PCM built by another process (while waiting on the lock),
* reading dependencies that already exist on disk,
* loading explicit modules or PCHs,
* building the global module index.
Since #242384, the freshly built PCM is no longer copied either, so the
assertion now fires on the very first compilation. Note that the reads
[8 lines not shown]
[clang] Make `PCHContainerReader::ExtractPCH()` return a buffer (#244697)
`ExtractPCH()` used to return a view into the buffer holding the PCM,
leaving it up to the callers to keep that buffer alive. This patch
changes
it to take the PCM buffer by-value and return the sub-buffer holding
just
the AST file by-value as well. This gives the readers more room to
decide
how the AST file is exposed, e.g. to make a copy when needed. No
functional change intended.
The callers are updated as follows:
* The importing compiler instance, the module manager and the global
module index builder extract the AST file once, up front. The
`SubMemoryBuffer` helper moves to the object file reader, the only one
that needs it.
* `ASTReader::ReadASTCore()` and `ModuleManager::addModule()` now rely
on
[10 lines not shown]
[libc][math] quiet signaling NaN with the sign bit set in exp functions and atanf (#248138)
This is an issue reported when proving libc math correctness via Lean 4
with an agentic workflow.
We try to prove that `expf`, `exp2f`, `exp10f`, `exp10m1f` and `atanf`
return a quiet NaN for every NaN input. However, for a signaling NaN
with its sign bit set, the exp functions return the input unchanged: the
result is still signaling and `FE_INVALID` is not raised. `atanf` does
the same for a signaling NaN of each sign.
<details>
<summary>Derivation</summary>
For `x = 0xFFA00000` (a signaling NaN with the sign bit set) in `expf`:
1. `|x|` is above the overflow and underflow thresholds, so the function
enters the block for large `|x|`.
2. The sign bit is set, so the function takes the underflow side of that
[26 lines not shown]