[MIR] Round-trip all machine metadata nodes (#219612)
MIR only emitted definitions for a subset of metadata referenced by
machine
functions. Other nodes were printed as pointer values and could not be
parsed
back.
Collect metadata referenced by machine instructions, memory operands,
and
variable debug information. Keep debug locations inline so the output
remains
readable.
Parse each machine metadata item with LLVM IR's metadata parser while
preserving the YAML item boundaries. This supports specialized nodes,
cycles,
and forward references without accepting definitions split across list
items,
and removes the old tuple-only parser.
[docs] Remove stale FIXMEs in LibASTMatchers.md (#219741)
Replace the stale "Introduce link to ASTMatchersTutorial.html" FIXMEs
with a link to the existing LibASTMatchersTutorial, drop the
ASTMatchersCookbook FIXMEs (no cookbook exists), and fix the "macros
(see below)" reference which should point to the AST_MATCHER_P section
above.
[AMDGPU] Reject image load merges with mismatched dim (#219923)
dim was missing from the operand equality check, so loads with different
dim could wrongly get merged into one
InstSimplify: Fold nonnull addrspacecast of null to poison
Perform the definitional fold if the source value is null
in the default address space.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
IR: Intersect and drop the addrspacecast nonnull flag
Teach the flag-propagation controls about the nonnull flag
on addrspacecast.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
IR: Add nonnull flag to addrspacecast
Introduce the nonnull flag on the addrspacecast instruction,
asserting that the source pointer is not the null value of its
source address space. If the source is the source-address-space null
value, the result is poison.
The LangRef does not yet acknowdlege the existence of non-0 null
pointers, or null pointers for address spaces other than default,
but will "soon".
This gives the target a way to omit the runtime null check to map
between the null values. Currently AMDGPU works around the lack of
this flag by introducing the hacky llvm.amdgcn.addrspacecast.nonnull
intrinsic in a late target codegen pass.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
Give the __COUNTER__ pedantic diagnostic a group (#218669)
Adding the pedantic diagnostic after supporting the extension for so
long without correctly diagnosing it is disruptive, so this gives folks
a way to disable just the `__COUNTER__` pedantic diagnostic without
losing all other pedantic diagnostics.
Fixes #196557
[SCEV] Make predicates optional in isKnownMultipleOf (NFC) (#219935)
This allows us to simplify some code in DependenceAnalysis, and brings
the routine in line with other SCEV routines.
RISCV: Pass instruction and operand index to replacePtrWithInt
The helper used the operand's parent instruction as the insertion point.
Pass the containing instruction and operand index directly so it no longer
depends on MachineOperand::getParent().
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
[clang] Find conversion function templates for in-class specializations (#218316)
Allow redeclaration lookup to consider conversion function templates
allowing Clang to match an in-class specialization such as `template<>
operator int()` against a prior conversion function template
`template<class T> operator T()`.
Fixes #218261
[X86] Fix X86CmovConversion sinking volatile loads into conditional branches (#219827)
The `X86CmovConversion` pass unfolds memory operands of `CMOVrm`
instructions and sinks the resulting load into a conditionally executed
basic block. While safe for ordinary loads, doing this for a volatile
load violates the LLVM LangRef since it causes a volatile memory access
to conditionally not execute.
Fix this by not converting with hasOrderedMemoryRef is true.
Fixes #219814
clang/AMDGPU: Stop passing redundant -target-cpu to cc1
Now that the exact target is encoded in the triple's subarch field,
-target-cpu is redundant. This avoids polluting the resultant IR with
unwanted "target-cpu" attributes. The net result is the desired codegen
when compiling libraries for a major subarch and linking it into a
program compiled for a specific arch. e.g., compiling for "gfx9-generic"
would pollute the IR with "target-cpu"="gfx9-generic", so codegen
would ultimately be performed for the generic target even after
linking into the concrete gfx9 cpu. The specialization will now be
achieved by merging the triples without the linker or optimization
passes needing to fixup function attributes.
AMDGPU: Harden assumed subarch triple spelling (#219480)
Guard against values that require multiple hex digits or
don't fit in the IsaVersion struct fields.
Co-Authored-By: Claude <noreply at anthropic.com> (Claude Opus 4.8)
AMDGPU/GlobalISel: Bitcasting G_TRUNC combine
Creating the G_TRUNC that changes type as well. This is really
the LLT::scalar trunc style that we inherited from switching to
extended LLTs, very common on non-true16 targets.
Affects inst-select pattern matching that were blocked by bitcast.
AMDGPU/GlobalISel: Fold (trunc (lshr x, 16)) to unmerge high half
Huge performance impact in some shaders with high register pressure.
What this really does is selects _hi16 register classes, and true16
machinery takes over later. Trunc + shift ends up in _lo16!
This requires allocating an extra register when the _lo16 half of the
original real 32-bit VGPR is still live.
[mlir][LLVM] Tighten the constant verifier's attr and res type match check (#218887)
`llvm.mlir.constant` only checked that the kind of the value attribute
suits the kind of the result type, never that the types themselves
agree. All of the following verified:
```
%0 = llvm.mlir.constant(1 : index) : i64
%1 = llvm.mlir.constant(1 : i8) : i16
%2 = llvm.mlir.constant(dense<1> : vector<4xi32>) : vector<4xi64>
```
Translation ignores the attribute type and uses the result type, so the
attribute type was effectively decorative for integers, and passes that
read it back could observe a type that has nothing to do with the value.
Require exact type equality for integer attributes and exact element
type equality for integer elements attributes, mirroring the
`AllTypesMatch` constraint `arith.constant` gets from ODS. The op cannot
[15 lines not shown]
[AMDGPU] Fix XNACK alignment check in SILoadStoreOptimizer merges (#219886)
Alignment of a merged scalar load depends on the lower offset load, not
whichever load comes first in program order, so checking the first load
could miss cases needing the constrained opcode
RuntimeLibcalls: Remove the dead IsDefault emitter machinery
The IsDefault bit on RuntimeLibcallImpl fed a LibCallToDefaultImpl map in the
TableGen backend that was populated but never read.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
RuntimeLibcalls: Add LibraryRef for dispatch-with-exclusion
Let a SystemRuntimeLibrary dispatch a shared provider library while dropping the
impls the target replaces, since a library reference cannot nest inside (sub ...).
This is a compromise from the ideal of explicitly listing all calls, but getting
to that point is prooving to be difficult.
The opt-out is emitted inside setAvailableLibFuncs_<lib>, so the single library's
logic is self contained.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
RuntimeLibcalls: Dispatch to library functions from SystemRuntimeLibrary
When a SystemRuntimeLibrary names LibcallLibrary defs, setTargetRuntimeLibcallSets
now dispatches each under an isLibraryAvailable guard, so an impl can be homed
into a library without dropping it from the target. Non-library members keep the
inline path. No target names a library yet, so output is unchanged.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
[Clang] Fix wording of ref-qualifier overload diagnostic (#219905)
When a member function is redeclared with a conflicting ref-qualifier,
the diagnostic described the new declaration before the previous
declaration, which read in the opposite order from the source. For
example,
struct C { void f(); };
void C::f() & {}
previously produced:
cannot overload a member function with ref-qualifier '&' with a member
function without a ref-qualifier
Swap the two qualifier descriptions so the previous declaration is
described first, matching source order:
cannot overload a member function without a ref-qualifier with a member
[2 lines not shown]
[IR] `select` should reject token-like types
Target extension types with the IsTokenLike property are meant to behave like
tokens. The change in #154620 already rejected such types in phi nodes, function
arguments, function return types and call parameters. Added this missing check
in SelectInst::areInvalidOperands().
Also refactored PHINode to follow the same pattern, so that the token type is
checked in the constructor, LLParser and Verifier.
Some DirectX lit tests deliberately use token-like types in Phi or Select
instructions, while disabling the verifier. This change breaks all of them
because the check is in more places than just the verifier.
Assisted-By: AI Code Assistant
wip
[C++20] [Modules] Correct the redecl chain (#219926)
Close https://github.com/llvm/llvm-project/issues/219639
The root cause of the problem is the incorrect redecl chain.
A valid redecl chain should be a circle where each decl refers to the
previous one and the first decl refers to the most recent decl (latest
one). However, in the example, the redecl chain became to:
D2 -> D1 -> D1 ....
so that the range of `for (... : D->redecls())` never ends.
The real cause of the issue is we didn't merge correctly in the
ASTReader. Previous code assumes about the most recent decl while the
new code makes the behavior more clearly.