[SPIR-V] Legalize folded byte-offset GEPs for workgroup memory (#227104)
Fix `SPIRVLegalizePointerCast` crashes on constant-index workgroup array
accesses.
Rebuild folded byte-offset GEPs as typed logical access chains. For
example, byte offset `1024` into `[257 x i32]` becomes indices `0, 256`.
This keeps byte-address resource legalization unchanged and adds a
regression test for #227064.
Fixes #227064
Assisted by: Github Copilot
[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.
[X86][APX] Test the relocation of an NF add
test_regclass_not_updated_by_regalloc_2 only produced an NDD/NF add
with a GOT operand because the allocator happened to give the add a
destination different from its source. With SlotIndexes compaction it
picks the same register, so the add is compressed to the legacy form
and the CODE_6 TODO lost its test.
Add a function whose add keeps its source live, so it stays NDD and
becomes NF under any allocation.
[LAA] Check dependences between predicated stores to the same pointer. (#242902)
Vectorization may reorder stores to the same pointer across iterations
if some of them are predicated, e.g. the stores in one branch are all
executed before the stores in the other. This is only safe if the
dependences between them are safe, but they were not checked in two
cases:
* A write is only checked if there is an earlier write in its alias set,
so the dependences between stores to the first written pointer were
never checked.
* Loops with a single written pointer and no reads were treated as safe
without any checks, even if the pointer is written by multiple stores.
Check writes with multiple stores to the same pointer: if any of them is
predicated don't treat as safe. Also only skip the checks for loops with
a single store and no reads.
Sync all data pools before STCNITH
become_passive now syncs every imported data pool on every planned
failover, not only the pools of SMB shares with SMB stateful failover
on. Each pool is synced in its own thread with truenas_pylibzfs, and
all of them share one 10 s limit, so a pool that hangs does not block
the reset.
The SMB steps are unchanged and still need SMB stateful failover:
block SMB and VIP traffic before the sync, and run
`truenas_smbhad mark-synced` after it.
[AMDGPU] Select saturating FP8 converts on gfx1250
The f32 to FP8 and BF8 conversions on gfx1250 also clamp overflow and
infinity to the largest finite value while MODE.FP16_OVFL is set, so
enable the saturating selection there.
gfx1250 selects the True16 forms of these conversions, which need
their own saturating variants. WMMA and SWMMAC depend on FP16_OVFL
without reading the mode register, so restore the default before them
as well.
Change-Id: I2680d540f102adaa9b2293e21cdcbd3b9e4afd09
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
[AMDGPU] Select saturating FP8 converts on gfx950
llvm.convert.to.arbitrary.fp with saturation was expanded generically
because v_cvt_pk_{fp8,bf8}_f32 do not saturate by default. For
E4M3FN, which has no infinity, the non-saturating form is poison on
overflow, so frontends had no way to get the hardware conversion with
defined overflow behaviour.
On gfx950 these conversions clamp overflow and infinity to the largest
finite value while MODE.FP16_OVFL is set. Select them for the
saturating form and let SIModeRegister set the bit, restoring the
default before anything else that depends on the mode and before
calls and returns.
Managing a second mode field exposed that a pending mode change could
be merged into an earlier insertion point without regard for the
instructions in between. Track the bits those instructions depend on.
Change-Id: I502af5acdc1d05de89189b7de63c8fe4e0d55107
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
[HLSL][[202x] Do not emit implicit using directive if hlsl 202x and later (#243154)
Doesn't emit the implicit using namespace hlsl directive if 202x or
later.
Updates all tests which are 202x or later and relied on the implicit
directive with an explicit 'using namespace hlsl'.
Adds a new test showing for all versions of HLSL before 202x the
implicit using directive is included.
Closes #235100
Assisted by Copilot GPT-6.1 Sol
[KnownFPClass] add applyInputSemantics to handle NSZ and the input denormal mode (#242439)
Adds `KnownFPClass::applyInputSemantics` to correctly handle NSZ and the
input denormal mode. It will apply the input denormal mode via
`KnownFPClass::applyInputDenormalMode` first, then it will treat any
+0.0 or -0.0 (and subnormals flushed to zero) as a zero of either sign.
[KnownFPClass] Improve fadd/fsub deductions around infinity classes (#239064)
Part of https://github.com/llvm/llvm-project/issues/242935
Improved `fadd`/`fsub` deductions for ruling out infinity. For example,
`1.0 - FLT_MAX` is not negative infinity. Additionally, we don't need to
worry if one of the inputs is infinity when ruling out finite classes,
because adding or subtracting infinity will only result in infinity or
NaN.
Also adds test coverage for `fadd`/`fsub` NaN deductions.
AI Disclosure:
I used Claude Opus 5 to help write the tests and to help analyze the
correctness of the changes.
SimplifyLibCalls: preserve allocation attributes in optimizeNew
When `LibCallSimplifier::optimizeNew` rewrites an `operator new` call into a
`__hot_cold_t` allocation call, forward the allocation attributes
(`allockind`, `allocsize`, `"alloc-family"`, and parameter `allocalign`) from
the original call onto the synthesized call instruction alongside its metadata.
This is a new patch since 2023 (unlike most of the rest of the stack)
and allows the next patch to remove more specialized C++ knowledge
from the LLVM layer, instead leaving it in clang where it seems more
sensible.
This patch was authored with the assistance of an LLM and was reviewed
by me before posting.
CGExprCXX: emit family and allockind attributes
This allows us to remove the special knowledge about C++ allocation from
LLVM's MemoryBuiltins.cpp, instead trusting attributes to communicate
the important properties.
Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.
Happily, clang now emits allocator family attributes for custom
allocators like the `__hot_cold_t` overloads in `new_hot_cold.cpp`
(which `isReplaceableGlobalAllocationFunction` in clang recognizes),
allowing us to remove that special knowledge from LLVM.
[7 lines not shown]
clang: emit allocalign to LLVM for alloc_align attributes
LLVM is growing knowledge of this, so we should inform it when we have
the information available. As a bonus, since we now check return
alignments in the callee as of an earlier patch of mine, we can now drop
the redundant llvm.assume() that this previously emitted.
This patch is originally from 2023 and was rebased and revised with
assistance from an LLM. I have manually reviewed the diffs to the
limit of my abilities (I don't do much in LLVM, and this is my first
time touching clang in a meaningful way) and they appear sensible. The
commit messages are entirely written by me.
Differential Revision: https://reviews.llvm.org/D119271
clang: also check alloc_align and assume_aligned claims in return (#239729)
Prior to this patch, we only check alloc_align and assume_aligned claims
in the caller. We are about to thread alloc_align information down into
LLVM, which would then have a chance to defeat the sanitizer checks by
performing optimizations. To avoid that, we also check alignment claims
in the called function prior to return.
Per review feedback on D121629:
- Also verify the alignment required by `AssumeAlignedAttr` in
`EmitReturnValueCheck`.
- Add a new `ReturnAlignmentAssumption` (`return_alignment_assumption`)
sanitizer handler in clang and compiler-rt that accepts the dynamic
return statement `SourceLocation` pointer loaded from `ReturnLocation`.
- Only emit the sanitizer check (and not a redundant `llvm.assume`) in
`EmitReturnValueCheck`.
This patch is originally from 2023 and was rebased and revised with
assistance from an LLM. I have manually reviewed the diffs to the limit
[4 lines not shown]
[CIR][CodeGen] Assert static member calls are unexpected in EmitCXXMemberCallExpr (#237420)
### Description
In Clang AST, calls to static member functions (whether written as
`S::func()`, `s.func()`, or `p->func()`) are lowered by Sema into
ordinary `CallExpr` nodes rather than `CXXMemberCallExpr`.
Previously:
- CIR's `CIRGenFunction::emitCXXMemberCallExpr` had an `errorNYI` for
static methods, giving the incorrect impression that static member
function calls were unimplemented (leading to #237402).
- Classic Clang's `CodeGenFunction::EmitCXXMemberCallExpr`
(`CGExprCXX.cpp:200`) retained an `if (MD->isStatic())` defensive
branch.
Per [ClangIR's code duplication
guidelines](https://github.com/llvm/llvm-project/blob/main/clang/docs/CIR/CodeDuplication.md),
this patch replaces the `errorNYI` in CIR and the defensive check in
[4 lines not shown]
[SCEV] Use m_scev_MinMax in applyDivisibilityOnMinMaxExpr (NFC). (#243233)
The lambda checking for a min/max expression with a constant first
operand and one other operand is what m_scev_MinMax with m_SCEVConstant
matches. Use the matcher and take the kind from the expression. The
assertion that the constant is non-negative directly followed the check
for it, remove it. Also pass Divisor by const reference.
Part of an effort to clean up the loop guards logic.
PR: https://github.com/llvm/llvm-project/pull/243233
[libc] Fix FILE mutex, buffering (#238618)
This change fixes some small issues found in FILE while building
programs against LLVM-libc. Specifically:
1) Linux pipes sometimes give less data than was requested, but the FILE
is expected to retry until it gets a blank read.
2) FILE mutexes are expected to be reentrant.
This PR fixes these minor issues and adds appropriate tests to catch
this behavior in future.
Assisted-by: Automated tooling, human reviewed.