[SystemZ] Add missing CC def to TRANSLATE EXTENDED (TRE)
TRE sets the condition code (0: operand processed, 1: test character
found, 3: CPU-determined amount processed), but its definition did not
list CC as an implicit def.
Adding the def raises TRE's write count from two to three, so update the
TRE scheduling entries for z196 through z17 to match (as for CU41/CU42).
Assisted by: IBM Bob
[flang] Let FIR AA calls access the data of descriptor arguments (#244452)
getCallModRef finds whether a call may access a variable through its
arguments with alias(arg, var). When the argument is the address of a
descriptor, e.g. an allocatable passed to an allocatable dummy, alias()
answers NoAlias for the data that the descriptor describes, because the
address of a descriptor does not alias the address of data. So getModRef
answered NoModRef for the data of an allocatable across a call that may
modify it, and LICM could hoist a read of the data out of a loop that
passes the descriptor to such a call.
An argument that is the address of a descriptor now also passes the data
that the descriptor describes. getCallModRef builds the source of that
data as getSource() does for a fir.box_addr of a fir.load of the
argument, and compares it with the source of the variable using the part
of alias() that compares the sources, which moves into aliasSources().
The intent of the dummy applies to the data as well.
Assisted-by: AI
[flang] A call may access a saved local through another instance of its procedure (#244077)
`fir::AliasAnalysis::getModRef` assumed that a call to a Fortran
procedure cannot access a saved local variable other than through its
arguments, unless the variable is a TARGET or is used in an internal
procedure. That is wrong when the call may invoke the procedure that
owns the variable: all the instances of a procedure share its saved
local variables (F2023 8.5.16), so the other instance may read or write
the variable. For example, LICM hoisted the load of `x` out of the loop
below, and the program printed 0 instead of 6 at `-O1` and above:
```fortran
module m
contains
recursive subroutine work(nested, total)
logical, intent(in) :: nested
integer, intent(out) :: total
integer, save :: x
integer :: i
[62 lines not shown]
[GlobalISel] Use Info.size from getTgtMemIntrinsic for the memory type (#242433)
Handle every value of Info.size like SelectionDAGBuilder does, instead
of always using the size of memVT:
- An unknown size creates an unknown-size MachineMemOperand. Previously
llvm.aarch64.mops.memset.tag was described as a 1-byte store.
- A known size that differs from memVT uses a scalar of that size. This
changes PowerPC, which reports a 31-byte access for llvm.ppc.vsx.lxvd2x,
llvm.ppc.altivec.stvx and related intrinsics.
- A size that matches memVT keeps the type of memVT.
---------
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[lld][MachO] Fix branch extension thunks for ld -r inputs (#243818)
TextOutputSection::finalize() walked each section's relocations
backwards to visit its branches by ascending offset, asserting the
descending order compilers emit. Object files from ld -r do not follow
it, which failed the link with a misleading "thunk range overrun" error.
Sort the relocations of sections that are out of order while parsing
them, so that finalize() can rely on that order.
[CUDA][clang] Remove parenthesized #pragma unroll warning (#244791)
nvcc accepts both `#pragma unroll N` and `#pragma unroll (N)` and
generates identical code, and the CUDA C++ Programming Guide
documents the parenthesized form.
The `-Wcuda-compat` warning matched pre-CUDA-8.0 `nvcc` behavior, when
the unroll factor had to be a literal. CUDA 8.0 added support for integral
constant expressions, so the warning is obsolete.
Assisted-By Claude
[mlir][vector] Allow single-element strided load/store in LLVM lowering (#241579)
The verifier allows a non-unit stride in the most minor memref dim when
`vector.load`/`vector.store` accesses a single element. The LLVM
lowering still asserts unit stride, so this crashes
`-convert-vector-to-llvm`:
```mlir
func.func @f(%m: memref<4xf32, strided<[3]>>, %i: index) -> vector<1xf32> {
%0 = vector.load %m[%i] : memref<4xf32, strided<[3]>>, vector<1xf32>
return %0 : vector<1xf32>
}
```
This patch moves the verifier condition into
`vector::isValidLoadStoreMemRefLayout` and uses it in both places, so
they cannot diverge again.
Fixes #239720
[AMDGPU][AsmParser] Pre-commit tests for v_pk_fmac_f16 fp inline constants. NFC (#245422)
Add GFX11/GFX12/GFX13 MC tests for v_pk_fmac_f16 with fp literal tokens
that are f16 inline constants (0.5, -1.0), a non-inlinable fp value
(1.5), an integer literal (0x3800), and an explicit lit(0.5). The check
lines reflect current behavior, where 0.5 and -1.0 are encoded as 32-bit
literals.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[clang-format] Fix InsertBraces rebinding an else in a preprocessor branch (#239414)
Don't insert braces around a body ending in an `if` whose `else` may
appear in a preprocessor branch skipped in the current formatting pass.
Inserting those braces can attach the `else` to a different `if` or
leave it without a matching `if`.
Fixes #239332.
[clang] Add __builtin_iseqsig (#244875)
Add the __builtin_iseqsig builtin that GCC provides for the C23
iseqsig macro. It takes two real floating-point arguments, with the
usual arithmetic conversions like the other comparison builtins
(__builtin_isless and friends), and returns whether they compare
equal. Unlike those builtins it is a signaling comparison, so emit it
with CreateFCmpS: a constrained fcmps when FP exceptions are modeled,
and a plain fcmp oeq otherwise, the same as ==.
When FP exceptions are modeled, don't constant fold it outside of a
constant context if an operand is a NaN, as for the comparison
operators, so that "invalid" is still raised.
Like GCC's builtin, it does not set errno. A C library can use it to
implement iseqsig when math_errhandling does not include MATH_ERRNO.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[lld/mac] Make order file handling look more like in the ELF port (#242735)
I made a PR to port #241470 to ELF (#242729). In doing so, I realized
that the ELF port's approach of getting symbols from the symbol table
and just local symbols from files is both faster (we don't need to
process symbols that make it into the symbol table many times) and more
correct (it allows handling symbols that aren't in any files, such as
alias symbols. Xcode's ld supports listing those in order_files. We used
to not support that, now we do). So switch to ELF's approach.
In a sense, ports #242729 back to MachO.
Linking Chromium Framework on an M4 Max, with Chromium's order file (5
symbols):
"Sort segments and sections" (median of 7): 41 ms -> 31 ms
Total link (hyperfine, 15 runs): 4.022 s +- 0.046 s -> 4.016 s +- 0.037
s
User time: 7.58 s -> 7.52 s
[9 lines not shown]
[lld/ELF] Look up --symbol-ordering-file symbols in parallel (#242729)
This ports #241470 to ELF.
It uses parallelForEachFineGrained() though, something I'll port back to
MachO :)
Linking Chromium on an M4 Max, with a synthetic ordering file with 6
symbols:
"Sort sections" time trace scope (median of 7): 108 ms -> 24 ms
Total link (hyperfine, median of 15): 2.936 s -> 2.855 s
With a synthetic ordering file listing all 1.56M defined symbols of the
output:
"Sort sections" time trace scope (median of 7): 467 ms -> 183 ms
Total link (hyperfine, median of 15): 3.437 s -> 3.151 s
No behavior change.
[hlsl][spirv] Dont emit string constants for resource names (#243531)
Resource intrinsics (handlefrombinding, handlefromimplicitbinding) take
const char * arguments which get lowered in backend into byte arrays in
the final spirv module. These should be ignored except to provide the
literal to OpName instructions.
Add a pass intentionally before SPIRVRemoveUnusedResources and
SPIRVLegalizeResourceBinding, which converts handle intrinsics to
variants taking a metadata arg for the name instead. This lets us avoid
emitting actual constants in the spirv, which requires int8 capability,
and simplifies, for example, string global removal in the unused
resources pass, and lowering of heap resources to handlefrombinding.
It would be preferable to emit these metadata variants from Clang, but
this is not currently possible due to handlefrombinding generation
taking place in generated initializers, eg __createFromBinding, so a
string arg must be passed initially.
[2 lines not shown]
Move the later folding fixes to their own PRs
1d50fec74e60 added more fixes for folding inline asm register operands
to this PR. They're split into the PRs stacked on this one, one fix
each, to keep this one to the tied operand fix that was reviewed.
This reverts commit 1d50fec74e601c10811a0d58c37a392b2a1ba146.
Assisted-by: Claude Opus 5.5
Test a tie whose def moves when a folded operand is before it
Folding a "+rm" pair before a "+r" pair moves the "+r" pair's def, so
both ends of its tie get new indices. The other tests only moved the
use.
Assisted-by: Claude Opus 5.5
[CodeGen] Fix more hazards in folding inline asm register operands
Nothing in tree marks an inline asm operand foldable until #229632, so
these were found by a review of the stack rather than by tests:
- The spill weights took a register to be foldable into an asm if any one
of its operands there was foldable, while the folder needs all of them
to be. One value passed to an "rm" and an "r" operand could then get
spilled, not folded, and reloaded into a register the asm didn't have.
Add MachineInstr::mayFoldInlineAsmReg(), true if every operand of a
register in an asm can be folded, and use it in the folder,
CalcSpillWeights, and InlineSpiller.
- The folder now folds every operand of the register, including an undef
use that InlineSpiller leaves out of the operands it passes, which was
left behind still referring to the spilled register.
- InlineSpiller rematerialized a value passed to a foldable operand (e.g.
a constant) into a register right before the asm, which the asm may not
have had. It's spilled and folded instead.
- An asm that can fold a register no longer adds to the register's spill
[18 lines not shown]
[TargetInstrInfo] Address review: autogenerate greedy-inline-asm-fold.mir checks
Generate the checks with update_mir_test_checks.py so that the spills and
reloads around each folded inline asm are verified, not just the INLINEASM
itself. Fix the "=r" comment to describe the C "+r" operand, note that which
"+rm" pair greedy folds is its own choice, and add a "+&rm" case on an
uninitialized value showing that folding a pair whose tied use is undef
stores to the slot without loading from it.
Assisted-by: Claude Opus 5.5
[TargetInstrInfo] Address review: write the two-register flag symbolically
Now that the operand count of an inline asm flag can be written in MIR, use
"reguse:GR64 foldable ops:2" instead of an immediate whose register class ID
changes whenever a register class is added. Regenerate the checks, which
now print the five operands of each x86 memory reference as "ops:5".
Assisted-by: Claude Opus 5.5
[TargetInstrInfo] Address review: don't fold one register of a multi-register operand
A memory operand replaces exactly one register, so return nullptr for a
folded operand whose flag holds more than one, rather than relying on an
assert that release builds drop. Also assert that every folded operand
holds the same register, and say that a caller folding a def whose tied use
is another register must store that register's value into the slot.
Test both the new bail-out and folding a rematerialized load into two "rm"
operands, which takes the fold-a-load path.
Assisted-by: Claude Opus 5.5
[TargetInstrInfo] Fix folding inline asm operands next to tied operands
foldInlineAsmMemOperand() swapped a register operand for the target's
memory operands with MachineInstr::removeOperand(), which asserts when a
later operand is tied, because moving it would break the tie. Inline asm
lists every input after every output, so folding any operand that comes
before another tied pair asserted, e.g. an "rm" input followed by the
input of a "+r" operand, or one of two "+rm" operands. Without
assertions, the moved operands kept stale tie indices. Untie the
operands, rebuild the operand list, and re-tie the remaining pairs at
their new positions.
It also gave up when the register appears in more than one operand, e.g.
one value passed to two "rm" operands, which left the greedy allocator
unable to spill that value at all. Fold every such operand into the
stack slot.
Finally, take MayLoad from the folded operands rather than from every
read of the register: a folded def whose tied use is another virtual
[9 lines not shown]
Include STLExtras.h for the range helpers
foldInlineAsmMemOperands uses is_contained, min_element, drop_begin,
and enumerate from STLExtras.h, which the file got only through other
headers.
Assisted-by: Claude Opus 5.5
[TargetInstrInfo] Address review: don't fold a subregister that isn't at the start of the slot
A folded operand refers to the start of the stack slot, which holds the
whole register, so a subregister is only there if it's at bit offset 0 on a
little-endian target. Folding x86's sub_8bit_hi read byte 0 instead of byte
1. Folding several operands at once made this worse: two operands holding
different subregisters of one value (e.g. "Qm"(lo), "Qm"(hi)) both read
byte 0.
Check the subregister in mayFoldInlineAsmRegOp, so the spill weights agree
with what folds. A tied def is covered too, since its tied use has the same
subregister.
Assisted-by: Claude Opus 5.5
[MIR] Round-trip the "func" kind of inline asm operand flags (#237461)
An x86 inline asm call or jmp whose target is a function, given as a "p"
operand or as a "*m" operand that ISel turns into an address, gets a
flag of kind Func. Like a Mem flag, it carries a memory constraint. But
getKindName() returned "mem" for it, and the MIR printer printed the
constraint only for a Mem flag. So this:
call void asm sideeffect "call ${0:P}", "p,~{dirflag},~{fpsr},~{flags}"(ptr @g)
was printed as:
INLINEASM &"call ${0:P}", sideeffect attdialect, mem ops:5, target-flags(x86-plt) @g, 1, $noreg, 0, $noreg, ...
which parses back as a Mem flag with no constraint. Printing that again
hits llvm_unreachable, and the asm printer asserts in
PrintMemReference() instead of emitting "callq g at PLT".
MachineInstr::print() also printed the constraint as a register class
(e.g. "mem:GR8_NOREX").
[8 lines not shown]
[LTO] Check COMDAT key before marking the group non-prevailing (#222568)
Regular LTO currently adds a COMDAT into NonPrevailingComdats when
any member of the group is non-prevailing. This is not correct when
the member is not the COMDAT key.
The problem can be reproduced with the following code.
lto-dtor-comdat.h:
```
struct Base {
virtual ~Base() {}
};
template <int N> struct Derived final : Base {
~Derived() {}
};
```
d0.cc:
```
[44 lines not shown]