[AMDGPU] Add cl option to respect acquires when inferring noclobber
The option is disabled by default, which effectively reverts #219991.
That is unsound and re-introduces miscompilations, but necessary as a temporary
measure to avoid performance regressions while we look into ways to recover
performance.
[AMDGPU] Describe MFMAs with a variant in MAIInstInfoTable (NFC) (#244159)
- Add an MFMAVariant enum. Each MFMA pseudo gets its variant from
MAIInstInfoTable, a TableGen GenericTable. Each real MFMA opcode
inherits the variant of its pseudo through VOP3P_Real.
- Look up an MFMA's co-execution info by its variant, as gfx1250 does
for WMMA, instead of matching every opcode.
- Replace the is_dgemm and is_gfx940_xdl fields with the variant.
- Describe each MFMA row by the first stage at which SALU, memory, VALU
and the next MFMA may issue, plus the window length.
Assisted-by: Claude Opus 5.5
[libc++] Add __new_at_least (#215813)
This adds a variant for `operator new` (spelled as `__new_at_least`,
since this is a library-internal extension) that returns the number of
objects actually allocated. It is being used in
`std::allocator::allocate_at_least`, which then allows `vector` and
`string` to make use of any over-allocations.
Fixes #212790
[MIR] Avoid reusing debug instruction numbers after parsing (#244437)
When a pass allocates a debug instruction number after MIR parsing, it
can get a number that is still in use. Resuming code generation from MIR
can expose this in two ways:
- X86FixupBWInsts, given the substitution 2 -> 1 and only instruction 1,
numbers its replacement 2 and records 1 -> 2. The substitutions now form
the cycle 2 -> 1 -> 2, and LiveDebugValues follows it forever when a
DBG_INSTR_REF reaches it.
- Given a DBG_INSTR_REF to a deleted instruction 2, the same rewrite
numbers its load 2, and LiveDebugValues gives the variable the load's
value instead of no location.
The parser seeds the counter only from the numbers that top-level
instructions carry. It now also counts the numbers on bundled
instructions, DBG_PHI operands, DBG_INSTR_REF operands and
debugValueSubstitutions entries.
This turned up while teaching X86FixupBWInsts to widen MOV16ri, which
made llc hang on dbg-value-superreg-copy2.mir.
[AArch64] Improve fixed-length constant splats (#247571)
Don't lower build-vector splats generated as part of lowering,
as those are transformed into splat_vector by the dagcombiner.
I noticed this when reviewing #246021
[X86] Add X86ISD::PMULUDQ poison handling (#247578)
canCreateUndefOrPoisonForTargetNode - X86ISD::PMULUDQ multiplies the
low 32 bits of each element into a 64-bit product, which can't
overflow, so it can't create undef/poison.
#245048 needs this to drop the movq in vzext_movl_pmuludq.
Assisted-by: Claude Code (Claude Opus 5.5)
[DAGCombiner] Scalarize variable index extracts from sub byte vectors
The type legalizer lowers a variable index extract from an illegal
vector with sub byte elements through the stack, storing one byte per
element. When the vector comes from a bitcast on a little endian
target, element $i$ occupies bits $[i \cdot w, (i+1) \cdot w)$ of the
source, so extract it with a shift of the integer word holding it.
```
t3: v64i1 = bitcast t2
t5: i1 = extract_vector_elt t3, t4
-->
t6: i64 = bitcast t2
t7: i64 = srl t6, t4
t5: i1 = truncate t7
```
On gfx1200 this replaces 64 scratch stores and a scratch load with a
few VALU instructions. Byte sized elements, non bitcast sources and
non power of 2 sizes are left unchanged.
[AMDGPU] Add tests for dynamic extract from sub byte element vectors. NFC
A dynamic extract from an illegal vector of i1/i2/i4 elements can be
lowered to a word select and shift instead of going through scratch.
Cover several widths, uniform and divergent indices, SelectionDAG and
GlobalISel, and negative cases.
[AArch64] Cost narrow two-source shuffles as the widened legal shuffle (#241908)
Widen the mask of a narrow two-source shuffle to the legal type and cost
that, as is done for length-changing shufflevectors.
Assisted-By: Claude Code Opus 5
[RISCV] Do not partially unroll outer loops with a known trip count (#247073)
Follow-up to #244182, which lowered the full-unroll threshold for
outer loops.
Fully unrolling an outer loop is limited to the partial-unroll budget
because it duplicates the inner loops. Partial unrolling duplicates
them as well, so disable it for outer loops with a known trip count.
Loops with an unknown trip count are left unchanged: lowering their
budget as well shrinks llvm-test-suite by less than 0.2% more while
changing 50 translation units.
With -mcpu=sifive-p670 -O3, llvm-test-suite shrinks by 579 KB (2.9%)
across 77 translation units, with fewer GPR spills and reloads.
Assisted-by: TRAE CLI (GLM-5.4)
[lldb][test] Print exit code when build command fails (#247580)
On some macOS nodes, our Make commands randomly fail with no output.
This patch adds the error code of the test build to the test output, so
we at least know what signal killed it.
assisted-by: claude
[X86] Update tests for SlotIndexes compaction
The rebase onto eeee317b1f30 left four tests with upstream's checks
and a stale merge of pdep-vector-128.ll, and missed the new
pr246251.ll. Regenerate them with compaction on; each one's
compaction-off regeneration matches upstream, so only allocation
changes.
[SCEV] Prove min/max Pred RHS and LHS Pred min/max via decomposition. (#208546)
Try to prove "LHS Pred RHS" by decomposing a min/max on either side into
its operands, proving the per-operand comparisons. A min/max equals one
of its operands, so proving the comparison for all of them proves it:
minmax(X0, ..., Xn) Pred RHS if Xi Pred RHS for all i, and
LHS Pred minmax(Y0, ..., Yn) if LHS Pred Yi for all i.
For LT/LE predicates with matching signedness, one operand is
sufficient:
min(X0, ..., Xn) Pred RHS if Xi Pred RHS for some i, and
LHS Pred max(Y0, ..., Yn) if LHS Pred Yi for some i.
The new helper also replaces the custom min/max logic in
IsKnownPredicateViaMinOrMax.
This is used in isKnownViaNonRecursiveReasoning. To avoid recursion in
[14 lines not shown]
[Docs] Add documentation for ptrauth ELF module flags (#237916)
There are four module flags that influence code-generation for PAuthABI
on ELF platforms.
ptrauth-elf-got
ptrauth-init-fini
ptrauth-init-fini-address-discrimination
ptrauth-sign-personality
Although largely self-explanatory, add a section in the documentation to
collect all the available module flags.
The ptrauth-init-fini module flags will work on the Mach-O equivalents,
but they are intended only to be used on ELF platforms.
[CIR] Return the value stored to the return slot directly (#246252)
Classic codegen returns the value stored to the return slot directly
when that store dominates the return, and then drops the slot
(`findDominatingStoreToReturnValue` in CGCall.cpp). CIR always lowered
the slot to an alloca, store, load and ret, so most functions returning
a scalar differed from classic codegen.
This adds a `cir-forward-return-slot` function pass. In a function with
a single `cir.return` of a load from the return slot, it returns the
stored value directly when either:
- the store is the slot's only other use and reaches the load through a
chain of single predecessors, or
- the store immediately precedes the load.
These are classic codegen's rules. Volatile, atomic, record, array and
complex slots are left alone. The return keeps its own location, which
CIRGen already sets to the return statement's.
[5 lines not shown]
[AMDGPU] Describe MFMAs with a variant in MAIInstInfoTable (NFC)
- Add an MFMAVariant enum. Each MFMA pseudo gets its variant from
MAIInstInfoTable, a TableGen GenericTable. Each real MFMA opcode
inherits the variant of its pseudo through VOP3P_Real.
- Look up an MFMA's co-execution info by its variant, as gfx1250 does
for WMMA, instead of matching every opcode.
- Replace the is_dgemm and is_gfx940_xdl fields with the variant.
- Describe each MFMA row by the first stage at which SALU, memory, VALU
and the next MFMA may issue, plus the window length.
Assisted-by: Claude Opus 5.5
[CIR] Add end-to-end tests for the offload passes
Compile real CUDA and HIP host and device code to CIR, combine it with
cir-offload-merge -combine -opt and check dead kernel elimination,
kernel argument constant propagation and launch bounds on the result.
The CUDA test also splits the container and lowers the host module with
a device binary to check that the kernel is registered.
[CIR][CUDA] Attach the device binary when resuming a host .cir module
CIRGen records the device binary named by -foffload-include-binary on a
CUDA/HIP host module. A host module emitted before the device binary
existed, as in the offload-merge pipeline, never runs CIRGen again. Read
the binary when cc1 resumes such a module, so that LoweringPrepare
registers its kernels.
[Driver] Add a ClangIR offload-merge pipeline for CUDA and HIP
With -fclangir --clangir-offload-merge, the host and each device are
compiled to pristine CIR, combined into one offload container with
cir-offload-merge -combine -opt, and split back with -split. Each split
module then resumes from -x cir: device modules are lowered to PTX (or
bitcode for HIP), packaged into the fat binary, and the host module
embeds it with -foffload-include-binary.
CIRMergeJobAction and CIRSplitJobAction record the tool chain, bound
arch and offload kind of each module. The split outputs are named the
way cir-offload-merge -split names them, <prefix>-<kind>-<triple>.cir
with an index for modules that share a triple, and cached per target so
each consumer gets its module.
-fno-clangir-offload-merge-pointer-facts turns off the pointer facts
pass in the merge step.
[CIR] Add a launch-derived pointer facts pass for offload containers
cir-offload-pointer-facts derives facts about the pointer parameters of a
device kernel from its host launches and attaches them to the
parameters. The only fact today is llvm.noalias: at every launch the
pointer arguments come from distinct cudaMalloc allocations, and the
kernel reaches each buffer only through its parameter (no address-taken
global, loaded pointer, forwarded value, escape or in-kernel allocation).
The proof is kernel-wide and conservative: one unprovable launch or body
path drops every fact for that kernel. Unchecked allocations are
accepted, since a failed cudaMalloc makes the launch undefined; only a
free before the launch invalidates a slot. The pass reports statistics
and remarks with a reason for each rejection.
[CIR] Fold cir.if with a constant condition
Splice the taken region of a cir.if whose condition is a constant and
drop the op. Only single-block bodies terminated by cir.yield fold.
[CIR] Run the offload passes from cir-offload-merge -combine -opt
With -opt, combine runs mem2reg and sccp on each nested module, so that
launch arguments reach the stub calls as constants, and then dead kernel
elimination, kernel argument constant propagation, launch bounds
propagation and pointer facts on the container. -disable-cir-prop-kernel-args,
-disable-cir-infer-launch-bounds and -no-pointer-facts turn off the
individual passes.
[CIR] Add launch bounds propagation for offload containers
When every launch of a kernel is visible and uses a compile-time block
size, record the largest block size on the device kernel as
nvvm.maxntid, the bound the user could have written with
__launch_bounds__. This lets ptxas budget registers against the real
block size instead of the 1024-thread ceiling.
All launches must be visible, on the same terms as kernel argument
constant propagation, because a launch that exceeds maxntid fails. An
existing bound is only tightened. Kernels for targets other than NVPTX
are left alone.
[CIR] Add a CIR dialect inliner interface
Add CIRInlinerInterface to the dialect library, exposed through
cir::registerInlinerInterface(registry), and register it in cir-opt.
Legality is conservative:
- launch markers (calls carrying cu.kernel_name) stay calls, because the
offload passes rebuild the kernel binding table from them;
- only single-block bodies ending in cir.return are accepted, because the
generic inliner models a callable's results through that terminator.
The registration also registers the LLVM and func dialects' inliner
extensions. Both dialects promise DialectInlinerInterface, and the
inliner aborts on a promised interface that was never registered.
[CIR] Trace coerced and inlined dim3 launch geometry
On x86_64 the dim3 arguments of __cudaPushCallConfiguration arrive
coerced to integer pairs, and once dim3's constructor is inlined its
fields are stored one by one. Trace both shapes in KernelBindingTable so
launches get their geometry.
[CIR] Add a test-print-kernel-bindings pass to cir-opt
Print the KernelBindingTable of an offload container: each kernel with
its host stub, its device definitions and its launch sites.
[CIR] Add kernel cloning helpers for offload containers
KernelCloning creates a specialized copy of a kernel and redirects a
chosen set of launch sites at it. The original is always kept: the
runtime can reach a kernel by name through hipModuleGetFunction and
similar, so rewriting a kernel defined in the source program in place is
unsound even when every launch in this module is visible. A kernel is
only taken over when all its users are among the redirected sites.
Signed-off-by: Steffen Holst Larsen <sholstla at amd.com>