[InstCombine] Fold scmp/ucmp of extended operands (#218871)
Fixes #202467
`scmp`/`ucmp` compare their operands, and both `sext` and `zext` are
monotonic with respect to the unsigned order (`sext` additionally
preserves the signed order). So a common extension on both operands can
be dropped and the compare done in the narrower type:
scmp (sext X), (sext Y) --> scmp X, Y
scmp (zext X), (zext Y) --> ucmp X, Y
ucmp (ext X), (ext Y) --> ucmp X, Y
Zero-extended values are non-negative, which is why a signed compare of
them becomes an unsigned compare of the narrow operands.
Both operands must use the same extend opcode and source type. Since
these intrinsics are not commutative, the extend is looked for on either
side, and a constant operand is narrowed instead when truncating and
[4 lines not shown]
[VPlan] Reject Argmin/Argmax with intermediate ops. (#218944)
handleMultiUseReductions currently only supports a single min/max
reduction step, not multiple intermediate ops.
Bail out instead of crashing in that case.
PR: https://github.com/llvm/llvm-project/pull/218944
[lldb][NativePDB] Keep declaration order of struct fields (#218731)
Unlike in C/C++, struct fields in Rust may be reordered by the compiler
to reduce padding. When completing records, we only tracked the offset
of fields inside the struct. For Rust this could result in an order that
didn't match the declaration (#218613).
This PR tracks the declaration order and sorts fields after the record
is constructed. It's assumed that the members inside the `LF_FIELDLIST`
are present in declaration order.
Fixes #218613.
[mlir][LLVM] Use a disjoint scope domain when inlining noalias
This matches recent changes to the LLVM inliner.
AI disclosure: Claude wrote the code, I wrote the commit message and
have done initial review.
[mlir][LLVM] Add disjointScopes to AliasScopeDomainAttr
This also updates the MLIR-side inliner to clone disjoint domains
while cloning alias scopes, matching changes to LLVM.
AI disclosure: Claude wrote the code, I wrote the commit message and
looked at the code.
[AMDGPU] Use a disjoint scope domain for merged LDS structs
When lowering LDS values, all the values are mutually disjoint, so we
can use the newly-added disjoint scopes feature to simplify the IR.
AI disclosure: Claude wrote this and I reviewed it and wrote the
commit message
[AMDGPU] Use a disjoint scope domain for noalias kernel arguments
All noalias arguments of a kernel are disjoint with each other, so we
can use a disjoint scope to save on metadata construction.
AI disclosure: Claude wrote this, I looked at it and wrote this
message.
[Inliner] Use a disjoint scope domain for noalias arguments
InlineFunction creates alias.scope/noalias metadata to represent the
set of `noalias` arguments to a function. We don't need the `!noalias`
now that we have the ability to use disjoint scopes, saving us IR size
and metadata bloat.
TODO move these to a previous commit.
Also changes InstCombine to not drop the experimental.noalias.scope.decl
for disjoint scopes even if they're not mentioned in a `!noalias`, but
do still delete them if they're not used.
[IR] Add alias scope domains with disjoint scopes
See RFC at
https://discourse.llvm.org/t/rfc-disjoint-scope-alias-scope-noalias-domains/91537
This commit adds support for declaring an alias scope domain disjoint.
Disjoint domains are ones where each scope is implicitly `!noalias`
with each other scope in the domain. This is represented by adding an
`i1` into the scope's domain as the second argument, with `i1 true`
representing disjoint scopes and `i1 false` representing the old
non-disjoint behavior. AutoUpgrade mechanisms have been added to add
in the missing `i1 false` to existing metadata.
This commit updates alias analysis to know about disjoint scopes and
updates the function cloner to also clone the alias domain if it's
disjoint (since, as a herd of LLMs discovered, you don't want the old
IR to be noalias with a clone of itself).
Commits to migrate passes to use disjoint scopes where that's an
[4 lines not shown]
[utils] Don't rename %. inside quoted strings in test checkseg
Replacing `%.foo` with `%dotfoo` everywhere also caught any `%.foo`
inside metadata, which would then cause incorrect CHECK lines to be
generated (since the value in the metedata isn't going to be
modified).
This commit fixes the issue by matching quoted strings in a regex
before looking for %. to replace.
AI disclosure: Claude found and fixed this, I wrote the commit message
[flang][OpenMP] Track reachable metadirective replacements
Semantic checks currently consider each statically applicable metadirective
replacement independently. This can diagnose lower-ranked replacements that
selection can never reach, and nested construct selectors cannot observe a
directive selected by an enclosing metadirective.
Use shared candidate ranking to retain only reachable replacements. Track each
effective directive path separately and propagate reachability to nested APPLY
transformations. This lets nested selectors observe selected contexts without
combining mutually exclusive paths.
Assisted with codex.
[FoldingSet] Switch to linear probing and Algorithm R deletion (#218190)
FoldingSet uses an inefficient chaining hash table. Switch to
linear-probing open addressing: the bucket array holds node pointers,
with null marking an empty slot. Deletion uses Knuth TAOCP 6.4 Algorithm
R, as DenseMap/StringMap do, so erase invalidates iterators while
leaving pointers to nodes valid.
The next-in-bucket pointer becomes a cached 32-bit hash, halving
FoldingSetNode. A probe compares it before the profile compare, and
FindNodeOrInsertPos returns it instead of a bucket address, so an
InsertPos survives intervening insertions.
https://discourse.llvm.org/t/rfc-modernizing-llvms-foldingset-open-addressing-with-swiss-table-and-algorithm-r/91637
LLM-aided
Co-authored-by: Kazu Hirata <kazu at google.com>
[DebugInfo] Add DW_TAG_property support to LLVM DebugInfo (#215776)
DWARF v6 adds DW_TAG_property to represent an entity accessed like a
data member but implemented via an accessor, such as an Objective-C
@property backed by an ivar. This adds a DIProperty metadata node,
plumbs it through the IR (LLParser/AsmWriter, bitcode, DIBuilder,
Verifier), and emits DW_TAG_property/DW_AT_property_forward DIEs in
DwarfUnit, anchored on the accessor's own subprogram DIE.
This covers the LLVM IR and DWARF layers only; Clang emission and
LLDB consumption are left for follow-up patches.
Assisted-by: Claude
[flang][cuda][NFC] Walk fir.call instead of greedy rewrite in CUFFunctionRewrite (#218513)
The pass only replaces on_device() calls with a constant. The greedy
pattern driver was extra work on every fir.call and also folded the
surrounding convert chain. Walk with IRRewriter instead, and check for
the i1 constant in the tests.
This reduce the footprint of the pass especially if there are many
fir.call ops.
[SLP]Fix unscheduled-deps assertion for reassoc scalars covered by another entry's copyable data
The scheduler's reassociated-operand cleanup released the dependency
through copyable data of any entry's edge, so a dep registered for an
uncovered entry could go unreleased.
Fixes: #218850
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/219010
[Clang][CodeGen] Fix crash in EmitParmDecl for bodyless destructors with -fextend-variable-liveness (#218830)
The fake-use coroutine check in EmitParmDecl calls
FnDecl->getBody()->getStmtClass() without guarding against a null
getBody(). This crashes when processing implicit parameters (e.g.
should_call_delete) of MSVC deleting destructors whose base destructor
is only declared, not defined.
[clang][docs] Add documentation for the DanglingPtrDeref checker (#216688)
In order to move the `DanglingPtrDeref` checker out of alpha it needs a
documentation the user can get information from. This PR added the
documentation for the `DanglingPtrDeref` checker and follow up PR will
also do the same for the `UseAfterLifetimeEnd` checker. Currently the
documentation sits in the `alpha.core` category, but once we move the
checker out of alpha stage it should be changed as well.
AI-policy: After I have written the documentation I verified my
spellings, grammar with AI.
[libc][bazel] Allow building with -DLIBC_FULL_BUILD
This PR defines a flag `--@llvm-project//libc:build_mode` that configures LLVM-libc to build with full-build flags. This is only compatible with clang at the moment, since it relies on the `-nostdlibinc` flag.
[libc][bazel] Add a repo with linux kernel UAPI headers
This will be used to support libc's -DFULL_BUILD option, which uses `-nostdlibinc` and thus requires a copy of linux kernel headers.
[VectorCombine] Reject out-of-bounds extract indexes in scalarizeExtExtract (#218984)
Fixes #218724.
An out-of-bounds `extractelement` produces poison in LLVM IR.
`VectorCombine::scalarizeExtExtract` currently matches constant-index
extracts without checking that the index is within the vector bounds.
For a sufficiently large out-of-bounds index, `scalarizeExtExtract` uses
the index to compute a shift amount for the packed integer
representation. The resulting constant can exceed the bitwidth of the
packed type, causing an `APInt` assertion in `ConstantInt::get`.
This patch adds a bounds check in `scalarizeExtExtract` and bails out
when the extract index is out of range, avoiding the invalid shift
construction.
The regression test uses the reduced reproducer from #218724.