[LLVMABI] Add Clang 23 compatible handling for matrix types (#224121)
This change updates the LLVM ABI library to enable Clang 23 compatible
classification of matrix types when the `-fclang-abi-compt=23` option is
used. Clang versions 23 and earlier did not accept matrix types as base
types for homogeneous aggregates, but the current version does. The LLVM
ABI library use the new behavior when isHomogeneousAggregate was
introduced there. This change adds an ABICompatInfo setting to allow
version 23 compatibility to be implemented.
This change also moves X86-specific ABI compatibility options into an
X86-specific subclass of ABICompatInfo.
Assisted-by: Cursor / various models
[mlir][xegpu] Derive load_nd lane_data from the hardware block variant (#223164)
setupLoadNdAnchorLayout copied lane_data from the consumer layout. But
lane_data follows from the element width and the block variant the
hardware will use, not from what the consumer wants.
This PR adds get2DBlockLoadLaneData, deriving lane_data from the packing
size the uArch already reports: the load's packed format size along the
innermost dim for a regular 2d block load, the general packed format
size along the second-innermost dim for transform (VNNI), or along the
innermost dim for transpose.
On the fallback path, where the consumer's inst_data is not a usable
block, also pick the variant that can host that lane_data. DPAS_MX
scales land here: width 16 for an 8-bit scale cannot spread 16 lanes of
2 elements over 32 columns, so it is loaded transformed, packing down
the column instead.
scale_a inst_data = [16, 32], lane_layout = [16, 1], lane_data = [1, 4],
[11 lines not shown]
[libc][math][NFC] Fix duplicated class names in math tests. (#224666)
This might cause ODR issues when we put all the tests together into a
single test.
Assisted-by: Gemini
Revert "[alpha.webkit.UnretainedCallArgsChecker] Emit a warning for a non-const RetainPtr member (#184243)" (#224464)
This reverts bf005a1227a4822c7c2535dd5f5f3626fbe441b2 as it introduced
too many new warnings.
[RISCV] Remove combineTruncToVnclip. (#224418)
This is very similar to foldToSaturated but operating on RISCVISD _VL
nodes instead of generic nodes.
combineTruncToVnclip handled some additional cases that the middle end
doesn't consider canonical. This was necessary for VP intrinsics that
skipped middle end canonicalization.
For patterns that saturate a signed value into an unsigned value the
canonical form uses an smax to make negative values positive followed by
a umin.
I have updated the tests to be in canonical form or remove if there was
already a canonical test. I had to update one other transform to emit
code in canonical form.
[CIR] Source LoweringPrepare target facts from the module (#219078)
LoweringPrepare reads a few target-derived facts (guard-variable width,
COMDAT format, _tlv_atexit/__cxa_thread_atexit selection) from the
ASTContext's TargetInfo.
This builds a LowerModule from the module's own cir.triple and reads
those facts from it instead, so target-derived lowering is consistent
with how the module was created rather than with the current invocation.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply at anthropic.com>
[DAG] Constant fold ISD::PARITY (#224387)
Context: Starting a claude assisted sweep for small gaps in SDAG's core
routines, starting with constant folding. This is the first of a small series
of patches covering small obvious seeming gaps. My main motivation
is simply making sure we have full coverage and as an exercise in
getting myself re-started upstream as I've been inactive for a few
months.
ISD::PARITY was missing from getNode / FoldConstantArithmetic which
meant it wasn't being constant folded at construction. Also implement
the DAG combine so that an already created PARITY node can be folded
if it's arguments become constant. This is the path which actually
triggers outside of type legalization.
Since PARITY doesn't have an IR form, we have to form tests in a way to
let the DAG combine from ctpop form them. This results in somewhat
fragile tests which is unfortunate.
[2 lines not shown]
Mix bits in FileID::getHashValue() (#224654)
FileID's identity hash was fine under DenseMap's old quadratic probing,
but #200595 switched DenseMap to linear probing with backward-shift
deletion. FileID's bucket index under an identity hash is just its low
bits, so two runs of file IDs can map to the same buckets, which can
turn into a long clustered probe chain under linear probing.
Multiply by 37 to spread the low bits, which matches
SourceLocation::getHashValue(). This fixes a 2.6x compile-time
regression observed with -Wdocumentation on an ObjC++ file.
Reapplies #223794, which was reverted because it broke tests in
clang/test/Analysis/html_diagnostics. It is safe to reapply now that
#224510 fixed the underlying issue.
rdar://187026883
Co-authored-by: Fred Riss <friss at apple.com>
[clang][SYCL] Implement address space attributes for SYCL (#200849)
This PR adds SYCL address space attributes. These attributes are
intended for use in the implementation of SYCL run-time libraries and
should not be used in any other context.
The following attributes were added - [[clang::sycl_private]],
[[clang::sycl_global]], [[clang::sycl_local]], [[clang::sycl_constant]]
and [[clang::sycl_generic]]. These correspond to the five address spaces
described by SYCL 2020 section 3.8.2, "SYCL device memory model" and
SYCL 2020 section 4.7.7, "Address space classes".
Assisted by Claude
---------
Co-authored-by: Tom Honermann <tom at honermann.net>
[CIR] Preserve padding bytes across a byval argument
Fill the byval slot at the call site, and the parameter's own slot in
the callee, with a copy from the object's address rather than a store
of a loaded record value. A store writes only the fields of the
record's type and leaves its padding unwritten, which for a union can
be another member's live data. A _BitInt keeps its load and store,
since those are its conversion to and from memory.
Assisted-by: Cursor / claude-opus-5
[flang] Mark visible Cray pointer associations as aliasing (#221350)
A visible Cray pointer association (ptr = loc(x) in the same procedure)
can alias x and the pointee. Flang treated them as no-alias and
miscompiled some codes at -O2.
-funsafe-cray-pointers is too broad. Instead, lowering now marks x as
TARGET for that procedure so later FIR passes (including TBAA) see the
aliasing. Default behavior: no-alias is unchanged.
[BoundsSafety][test] Add late-parsed counted_by type-attribute coverage
New tests exercising the late-parse fill-in mechanism:
- Sema/attr-counted-by-weird-type-positions{,-late-parsed}.c: counted_by
in assorted type positions, nested pointers, and rejection cases.
- Sema/attr-bounds-safety-function-ptr-param.c: attributes on
function-pointer-typed members.
- Modules/ and PCH/ bounds-safety-attributed-type-late-parsed: the
resolved type round-trips through serialization.
- Sema/attr-counted-by-late-parsed-regressions.c: guards against the
double-free on a nested-record decl-spec attribute and the null-count
escape on a free-function parameter.
[BoundsSafety] Create incomplete counted_by types and wire up the refill
Activate late parsing for the counted_by family (counted_by / sized_by and
their _or_null variants) in type-attribute position, under
-fexperimental-late-parse-attributes, on top of the type-attribute handling,
the validation helper and the refill machinery added in the previous commits.
When such an attribute is seen during type construction and its argument
can't be resolved yet, build the CountAttributedType immediately with
getIncompleteCountAttributedType and record it against the enclosing record;
its count expression is filled in at the closing brace via the refill logic.
Because enclosing types refer to the node by pointer, completing it in place
leaves the type chain untouched -- no rebuild, no TypeLoc re-emission.
- Sema::ActOnLateParsedTypeAttr builds the incomplete node; the parser
callback stores it on the LateParsedTypeAttribute and records the
attribute in the record currently being parsed.
Parser::CompleteLateParsedTypeAttributes drains that list at the closing
brace; a nested anonymous record hands its pending attributes up to the
[9 lines not shown]
[BoundsSafety] Handle the counted_by family as a type attribute
counted_by / sized_by (and their _or_null variants) were handled in only one
way: a declaration-position attribute went through handleCountedByAttrField,
which validated it and then patched the field afterwards with
FieldDecl::setType. There was no type-position handling at all.
Build the type during type construction instead, from a single handler that
serves both positions:
- Add HandleCountedByAttrOnType and dispatch the counted_by family to it
from processTypeAttrs, going through the shared
validateBoundsAttrTypeForTypePosition leaf.
- Remove handleCountedByAttrField. Its FieldDecl-based type-shape checks in
Sema::CheckCountedByAttrOnField are superseded by
Sema::ValidateBoundsAttrTypeShape, added in the previous commit and now
reached from the type path, and are deleted; no diagnostic is dropped. The
checks that genuinely need the FieldDecl (union member, non-flexible
array, cross-struct count) stay in CheckCountedByAttrOnField and run from
[11 lines not shown]
[BoundsSafety][NFC] Thread a late-parsed attribute list through declarators
A late-parsed type attribute is written in the middle of a declarator, so the
list it lands in has to travel with the declarator pieces until the enclosing
record can supply its argument. Add that storage and plumbing, with nothing
producing or consuming it yet:
- Move CachedTokens and LateParsedAttrList earlier in DeclSpec.h so DeclSpec,
Declarator and DeclaratorChunk can hold one.
- Give DeclSpec, Declarator and DeclaratorChunk a LateParsedAttrList, and let
Declarator::AddTypeInfo carry one onto the chunk it appends.
- Give ParseSpecifierQualifierList and ParseTypeQualifierListOpt an optional
LateParsedAttrList parameter, passed down to ParseDeclarationSpecifiers.
No functional change: the lists stay empty and no caller passes one. The next
commit populates them.
[BoundsSafety][NFC] Add the Sema/Parser bridge for late-parsed type attributes
A late-parsed bounds attribute has to build its type when the attribute is
seen, but its argument isn't parseable until the enclosing record is complete.
Building that type needs the Parser (which owns the cached tokens) and Sema
(which owns type construction) to meet:
- Sema::ActOnLateParsedTypeAttr validates a counted_by-family attribute for
the type position and, if valid, wraps the type in a CountAttributedType
whose count is not yet known, handing the node back for completion.
- Parser::ProcessLateParsedTypeAttrCallback is the Parser-side entry point,
registered on Sema so Sema can call back without including Parser.h (the
same pattern as LateTemplateParserCallback). It reuses an already-built
node so several declarators sharing one attribute share one type.
No functional change: nothing records late-parsed type attributes yet, so the
callback is never invoked. The next commit wires it up.
[BoundsSafety][NFC] Add counted_by type-shape validation helper
Introduce the single "is this type valid for a counted_by-family attribute in
type position" leaf that both the eager type-attribute path and the
late-parsed path will call:
- Sema::ValidateBoundsAttrTypeShape holds the type-shape checks -- pointer
or flexible array member, void and function pointee, pointee that is a
struct with a flexible array member -- and their diagnostics.
- validateBoundsAttrTypeForTypePosition wraps it for type position and adds
the nested-pointer rejection, reported with the new
err_counted_by_on_nested_pointer diagnostic.
Supporting pieces: Sema::BoundsAttrFlags and Sema::getBoundsAttrKind,
getCountAttrKind, getPointerNestLevel, the CountedByInvalidPointeeTypeKind
enum, and LangOptions::hasBoundsSafetyAttributes(), a stub returning false so
the shared leaf can gate its -fbounds-safety-only branches with the same
predicate used downstream.
[2 lines not shown]
[X86] Fix `FastISel` crash on `GEP` with a constant index wider than `64` bits (#223432)
Fixes #220954
When FastISel folds a GEP into an X86 addressing mode, it reads each
constant index with `getSExtValue()` and adds it to the displacement.
That call asserts if the constant has more than 64 significant bits, so
a `getelementptr` with an `i128` index of `2^64` feeding a legal-typed
load crashes at `-O0`. The LangRef says a GEP index is sign-extended or
truncated to the pointer width, and both generic FastISel and
SelectionDAGBuilder already do exactly that (added in 2015 for this same
assertion). The X86 address folder was the one GEP lowering that never
got the same treatment.
The index is now truncated to 64 bits before it is folded, mirroring
`FastISel::selectGetElementPtr`. For the reproducer the index becomes
zero and the load addresses the alloca directly, which is also what
SelectionDAG produces for the same IR. The other integer conversions in
`X86SelectAddress` are already safe: struct indices are
verifier-enforced `i32`, and the folded-add and `Add` paths only match
values whose type already equals the pointer width.
[CIR] Give up when we hit a global-view in dense-element-attr lowering (#224379)
A ptr-to-int conversion can't be converted to an APInt/APFloat, so this
ends up not being able to produce a valid dense element attr. This patch
makes us 'fall back' to the insert-value version of any potential
dense-elements lowering if there is a global view as one of the values.
[CIR] Correctly pass func self-comdat & alignment (#223773)
Classic codegen does these, and it is important for when these end up
being stored as function pointers, as we discovered on a benchmark.
This patch does 2 things:
1- Properly passes the 'self' 'comdat' feature (that is, when the symbol
reference is 'self', not when it is a different name, which isn't
implemented anywhere). This mirrors what was done for GlobalOp.
2- Properly calculate and pass the 'alignment'/'preferred alignment' for
a function. Only the 'alignment' is passed to LLVM-IR, as the dialect
doesn't support preferred alignment, so a 'missing feature' is left in
place. That functionality isn't important to this patch, but was 'next
to' the alignment work in CodeGenModule.cpp, so it seemed like something
we should handle if at all possible.
[x86][CostModel] A runtime stride should cost one ADD on AVX2+ (#219903)
Runtime stride should cost one ADD per iteration. Only when the loop has
no fixed step do we need the AVX2 cut-off.
Closes #217019.
[offload-arch] Report gfx1250-strict to match rocminfo (#224480)
## Motivation
offload-arch would print gfx1250, but rocminfo reports gfx1250-strict on
revision 0s. We want to print the gfx1250-strict too.
Note: This is based off a [similar PR in
rocm-systems](https://github.com/ROCm/rocm-systems/pull/11639).
## Required Changes
* llvm already can parse the gfx1250 -strict target, so no changes
necessary there.
* offload-arch already printed gfx1250, so just needed to get the ASIC
Revision, which is in bits 25:22 in the capability property.
* If ASIC Revision is 0 and gfx_target_version is gfx1250, then report
"gfx1250-strict"
[5 lines not shown]
[MLIR][Parser] Fix result numbers not being allowed in switch statements (#224581)
PR #87658 fixed this for the `case` branch for `cf.switch`, but not the
`default` case. Moreover, `llvm.switch` has the same problem. This PR
fixes them.