[PowerPC] Use 64-bit registers for wide "r" inline asm operands
On PPC64, an integer wider than 64 bits, such as an i128, in an "r" or
"b" operand was given a 32-bit register for each 64 bits of it, so half
of its bits were lost. Give it 64-bit registers instead. AArch64 had the
same problem (#238926).
Assisted-by: Claude Opus 5.5
Check the register class of wide GPR operands in MIR
The assembly prints a GPR the same way whether it is used as a 32-bit or
a 64-bit register, so the old checks couldn't show the fix working. Stop
after isel and check the register class of each inline asm operand.
Also add i64 cases for "r" and "b", an i32 case, and a 32-bit PowerPC
RUN line.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[AArch64] Add the H modifier for the second register of a 128-bit operand
A 128-bit integer in an "r" operand takes two X registers, but an asm
could name only the first, so it couldn't use the other half. GCC has
the H modifier for this, so support it too.
Assisted-by: Claude Opus 5.5
[AArch64] Use 64-bit registers for wide "r" inline asm operands
An integer wider than 64 bits, such as an i128, in an "r" operand was
given a 32-bit register for each 64 bits of it, so half of its bits were
lost. Give it 64-bit registers instead.
Fixes #238926.
Assisted-by: Claude Opus 5.5
[Clang][AArch64] Don't warn about a 128-bit "r" operand
Clang warned that a 128-bit value in an "r" operand didn't fit its
register and suggested %w. But the value takes two X registers, and %H
names the second, so don't warn about it.
Assisted-by: Claude Opus 5.5
[AArch64] Use 64-bit registers for wide FP and vector "r" operands
An fp128 or a 128-bit vector, such as a <2 x double>, in an "r" operand
was still given 32-bit registers, so half of its bits were lost, as with
an i128 before. Give it 64-bit registers too.
Assisted-by: Claude Opus 5.5
[SelectionDAG] Don't crash after an error in a callbr's asm
When a callbr's asm has an error, such as a constraint it can't satisfy,
visitInlineAsm() reports it and returns before creating the INLINEASM_BR.
But the callbr's block still got edges to the indirect targets, which
BranchFolding rejects since nothing branches there, and a landing pad in
an indirect target looked for the registers that the INLINEASM_BR would
have defined.
Don't add the edges to the indirect targets, and make a landing pad's
value poison, since nothing reaches it.
Fixes #98379 and #172657. Part of #173609, whose asm is still rejected,
since LLVM picks the "k" alternative of "+kr", which needs AVX-512.
Assisted-by: Claude Opus 5.5
Don't use VT's register class for an Untyped callbr output
An i128 output in an explicit register pair on SystemZ is Untyped,
which has no register class, so getRegClassFor() asserted when the
indirect target read the pair. Use VT's class only when VT has one.
Assisted-by: Claude Opus 5.5
[SelectionDAG] Read callbr outputs at the top of indirect targets
A callbr's indirect target reads the asm's outputs again, from the
registers that the INLINEASM_BR defines them in. When those are
physical registers, they have to be live into the indirect target, and
the read has to come before anything in the block clobbers them.
Neither was ensured.
Only the registers that an output was assigned were marked live-in. An
x86 flag output ("=@ccz") is assigned an unused GR32 virtual register,
and its lowering reads EFLAGS instead, so EFLAGS wasn't live-in, and
the verifier reported "Using an undefined physical register" (#60827).
AArch64 and SystemZ assign a flag output the flags register itself, so
they weren't affected. The read was also a CopyFromReg in the DAG,
which the scheduler could put after an instruction that clobbers the
register. At -O2, an indirect target that added the asm's carry flag to
a product ran the imul before the adc that reads the carry.
Read the registers the way an EH pad reads its exception registers.
[23 lines not shown]
[X86] Fix EFLAGS copy lowering across INLINEASM_BR indirect edges
An INLINEASM_BR isn't a terminator, so it can branch to an indirect
target from the middle of its block, before the instructions after it
run. The EFLAGS that live into an indirect target are the ones at the
asm, not the ones at the end of the block, but X86FlagsCopyLowering
assumed the latter in two places.
When the pass lowers an EFLAGS copy, it rewrites the copy's uses in its
block and then in every successor that EFLAGS live into. For a copy
after an INLINEASM_BR, that includes the asm's indirect targets, which
the copy never reaches, so the pass removed their live-in and rewrote
their flag reads to use SETCCs computed after the asm, which only the
fallthrough path runs. The pass could also hoist the test position for
a copy in an indirect target into its predecessor, before the
terminator that follows the asm, where the indirect path never goes.
Don't follow a copy from its block into the indirect targets of an
INLINEASM_BR before it, and don't hoist the test position out of an
[11 lines not shown]
Test more outputs that the indirect targets convert
Add the RISC-V shape of #143795, where an i32 output is sign-extended on
each path, a float in a specific physical register on x86, a double in a
pair of registers on i686, and a flag output on AArch64, whose NZCV is now
live into the indirect target. Also check that a callbr with direct and
indirect register outputs now only reports the error.
Assisted-by: Claude Opus 5.5
Remove the stale FollowCopyChain comment and unrelated comment changes
The comment that explained FollowCopyChain's walk was left above
visitCallBrLandingPad() when the walk was removed. Also put the BTI comment
in visitCallBr() back as it was, and fix a double space.
Assisted-by: Claude Opus 5.5
Replay each output's read in the indirect targets
The indirect targets re-parsed the constraints, recomputed each output's
registers and types, and paired them with the recorded registers in order,
so they were right only if both computations agreed. Record each output's
operand info and registers when lowering the callbr instead, and read them
in the indirect targets with the same code as visitInlineAsm().
This also marks a flag output's register (NZCV on AArch64, CC on SystemZ)
live into the indirect targets, as a register output's already was. And the
indirect targets no longer create virtual registers they don't use, which
renumbers some in the AArch64 test.
Assisted-by: Claude Opus 5.5
Regenerate callbr tests for label-must-be-emitted
Main now prints label-must-be-emitted on INLINEASM_BR indirect targets
(#234850).
Assisted-by: Claude Opus 5.5
[SelectionDAG] Read callbr outputs from the INLINEASM_BR's registers
An indirect target of a callbr found the registers holding the asm's
outputs by walking back from the callbr's exported value through COPYs to
the INLINEASM_BR, and asserted that the chain held nothing else ("start of
copy chain MUST be COPY"). An output whose type differs from its register's,
such as a float in a general-purpose register, is converted, e.g. with
MOVDI2SSrr on x86, so the assertion fired. And the target didn't convert the
output to its result type, as visitInlineAsm() does.
After an error in the asm, nothing defines the exported value, so the walk
crashed, and the callbr block kept edges to the indirect targets with no
INLINEASM_BR to branch there, which later passes reject.
Record the registers that the INLINEASM_BR defines its outputs in when
lowering the callbr, and read the outputs from them in the indirect target,
converting each to its result type as visitInlineAsm() does. After an error,
give the indirect targets undefined outputs and no edges from the callbr.
Fixes #98379, #112914, #143795, #170100, #172657, and #173609.
Move the asm error handling to its own PR
This PR now fixes only valid asm whose outputs crash the indirect targets.
Lowering a callbr whose asm has an error, which crashes after reporting
it, moves to its own PR stacked on this one.
Assisted-by: Claude Opus 5.5
[SelectionDAG] Report an error for a callbr's indirect register output
An indirect output with a register constraint, e.g. "=*r", is stored to its
pointer after the asm. But a callbr's asm can branch to an indirect target
before then, so the store was silently skipped on the indirect paths. Clang
emits such an output for a _Complex lvalue with a register constraint:
_Complex float c;
asm goto("" : "=r"(c) : : : l);
Report an error instead. A callbr without indirect targets has no such
path, so it's still allowed.
Assisted-by: Claude Opus 5.5
[MachineCSE] Don't reuse an instruction after an INLINEASM_BR elsewhere
An INLINEASM_BR can branch to its indirect targets before the instructions
after it in its block run, but MachineCSE let those instructions replace
ones in any block that their block dominates, including the indirect
targets. E.g., when both paths out of a callbr sign-extend its output, the
indirect target reused the extension on the path to the default target and
read a register that its own path never wrote.
Reuse an instruction after an INLINEASM_BR only in its own block. MachineSink
already refuses to sink into an indirect target for the same reason.
Assisted-by: Claude Opus 5.5
[InlineAsmPrepare] Fix callbr uses when indirect dest reaches default dest (#235938)
updateSSA() left a use of a callbr's result alone if the callbr's default
dest dominated it. But an indirect dest can reach the default dest too,
e.g. when they're the same block or when the indirect dest branches to it,
so such a use still read the callbr's result on the indirect path.
SelectionDAG copies that result to a virtual register after the
INLINEASM_BR, on the path to the default dest only, so the indirect path
read a register that it never defined.
Leave a use alone only if the edge to the default dest dominates it, and
don't make the result the value at the end of the default dest, so that
SSAUpdater merges it with the landing pad's value there.
Assisted-by: Claude Opus 5.5
[test][llvm-cfi-verify] Test x86 ud1l trap recognition for out-of-line CFI checks (#245404)
Add unit and lit tests verifying that llvm-cfi-verify recognizes UBSan
ud1l traps as non-fallthrough CFI traps and classifies indirect calls
guarded by out-of-line checks branching to ud1l as PROTECTED.
Assisted-by: Gemini