[CIR] Make cir-canonicalize a full canonicalizer
cir-canonicalize applied the CIR canonicalization patterns and folders
only to a hand-written list of operations. It now builds the pattern set
once in initialize() and runs the greedy driver over every operation, so
every pattern and folder applies everywhere. Only operations that
rewriting left dead are erased, such as the inputs of a folded
operation: CIR stays close to the source, so unused locals and ignored
expressions are kept as in classic codegen. Empty scopes and switches
were removed only because they were dead, so they get explicit
canonicalization patterns.
The pass uses the multi-op driver because the region driver always
erases blocks without a CFG predecessor, and a block that starts with
cir.label is reached only through cir.goto until the goto solver runs.
Region simplification stays off for the same reason. The new
test-convergence option fails the pass when the driver does not reach a
fixpoint, as in the upstream canonicalizer.
Assisted-by: Claude Code (claude-opus-5-5).
[mlir] Add a dead code elimination mode to the greedy rewriter
The greedy pattern rewrite driver always erases trivially dead
operations, so a client that wants canonicalization patterns and
folders without dead code elimination has no way to get it. Add
GreedyRewriteConfig::setDeadCodeElimination and the matching
dead-code-elimination option of the canonicalizer pass, with three
modes:
- all, the default, erases every trivially dead operation as before.
- newly-dead keeps the operations whose results are unused when
rewriting starts and erases any other operation once it is dead, so
what a fold or pattern leaves unused goes away.
- disabled erases an operation only by a pattern or by folding.
Region simplification is separate and still removes dead values unless
it is disabled too. The deadness cache skips invalidation while it is
empty, so a run that never queries it pays nothing for its tracking.
Assisted-by: Claude Code (claude-opus-5-5).
[DAGCombiner] Mark uint_to_fp widened through trunc nuw as nneg
The source of a trunc nuw fits in a strictly narrower type, so it is
non-negative. Without nneg x86 lowers the widened conversion through the
unsigned i64 expansion.
Assisted-by: Claude Code Opus 5.5
[X86] Mark vXi64 int to fp undesirable without AVX512DQ
Without avx512dq there is no vector conversion from i64 elements to f32
or f64, so widening the conversion of a source truncated with nsw or nuw
back to i64 makes it slower.
avx512fp16 converts i64 elements to f16 directly, so the widening folds
now pass the node and the check sees the result type.
Assisted-by: Claude Code Opus 5.5
Fix check for loop promotion to parallel for
A teams loop with calls to non API routines cannot be promoted to
parallel for. The visitor overrode such a case when there was a later
call to an API routine.
[lldb][gdb-remote] Preserve the initial vRun stop reply (#239671)
Return the server's launch response from the gdb-remote client and preserve the initial vRun stop, exit, or termination reply. Legacy A launches continue to query the stop reason after qLaunchSuccess.
Preserve exit status and descriptions when the process exits during launch, and deliver the exit event after restoring the outer launch listener.
Add packet classification and regression coverage for initial signal replies, immediate exits, and the legacy launch fallback.
Add entry to local declarations for split target / teams loop
Add missing entry to declaration map for split spelling target teamsloop
missing after #233539
[clang][OpenMP] Extend no-loop promotion to the split teams loop
Widen the no-loop promotion to apply not only to the fused target teams
distribute parallel for but include the same region written as separate
directives, other directives promotable to parallel for, and regions
carrying a schedule clause that asks for a mapping a no-loop kernel
already provides.
Use the SPMD_NO_LOOP kernel tag to carry the promotion decision, based
on whether the kernel can get fully promoted to a no-loop kernel. This
eliminates the previous discrepancy where a clause got the tag but not
the promotion.
[AArch64] Add feature guards to SVE and SME intrinsics
This PR adds streaming/non-streaming feature guards to the SVE and SME
intrinsics. A new verifier pass is added to rejects calls to intrinsics
whose type signature is unavailable for the function's mode and feature
flags.
Some codegen tests needed updating to avoid using types that don't
map to any legal ACLE types.
More as an optional feature; this PR adds a check to Clang's SveEmitter
to ensure that a builtin's type/target maps to a compatible LLVM intrinsic
variant, under the compatible feature flags so that incorrect mappings
are caught during TableGen generation.
I'm happy to split this PR up, but I wasn't sure that was necessarily
going to be more helpful.
SimplifyLibCalls: preserve allocation attributes in optimizeNew
When `LibCallSimplifier::optimizeNew` rewrites an `operator new` call into a
`__hot_cold_t` allocation call, forward the allocation attributes
(`allockind`, `allocsize`, `"alloc-family"`, and parameter `allocalign`) from
the original call onto the synthesized call instruction alongside its metadata.
This is a new patch since 2023 (unlike most of the rest of the stack)
and allows the next patch to remove more specialized C++ knowledge
from the LLVM layer, instead leaving it in clang where it seems more
sensible.
This patch was authored with the assistance of an LLM and was reviewed
by me before posting.
CGExprCXX: emit family and allockind attributes
This allows us to remove the special knowledge about C++ allocation from
LLVM's MemoryBuiltins.cpp, instead trusting attributes to communicate
the important properties.
Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.
Happily, clang now emits allocator family attributes for custom
allocators like the `__hot_cold_t` overloads in `new_hot_cold.cpp`
(which `isReplaceableGlobalAllocationFunction` in clang recognizes),
allowing us to remove that special knowledge from LLVM.
[7 lines not shown]
[CIR] Introduce cir.vtable.get_offset to handle offset mechanism (#242032)
In anticipation of the relative-vtable implementation, this patch
replaces the vtable pointer offset math with its own operation that
replaces all of the offset calculations, and re-introduces them during
LowerToLLVM.
Eventually, this will unify the two 'types' (pointer vs diff) that comes
out when using relative vtable lowering.
Additionally, this patch converts the dyn-cast operation to remove its
relative-flag and just use this get_offset functionality instead.
[Mips] Fix MipsJmpLink and MipsTailCall to use compact branch instructions on MIPS32/64 R6 (#241162)
MIPS32/64 R6 should emit the BALC instruction for MipsJmpLink instead of
JAL. Currently LLVM emits JAL regardless of the option, while GCC
correctly emits BALC.
This patch adds R6-specific pseudo instructions JAL_R6 and TAILCALL_R6
that expand to BALC and BC. The JAL and TAILCALL patterns are restricted
to pre-R6 targets.
PR #232578 restricted JAL instruction predicates to pre-R6, which broke
Linux kernel builds for mips32r6 when inline assembly contains `jal`:
error: instruction requires a CPU feature not currently enabled. Fix
this by restoring JAL to ISA_MIPS1, adding mipspat for MipsJmpLink
tglobaladdr and removing the embedded MipsJmpLink pattern from the
JumpLink base class.
Fix #165634.
[CIR][OpenMP] Add initial support for distribute
This patch adds initial support for the OpenMP 'distribute' directive. Basic
code generation for the standalone and combined cases is introduced. Support
for clauses will be added in the future. The composite 'teams distribute
parallel for' form will be added in a subsequent patch.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for 'distribute parallel for' with 'target teams'
Adds support for handling the full '[target] teams distribute parallel for'.
Introduces setting the omp.composite attibute for the 'distribute parallel for'
composite construct.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for omp teams
This patch adds support for the OpenMP 'teams' directive, both standalone
and as the combined `target teams` construct. isCombinableLeaf now also
recognizes teams, so an explicitly-nested `target` + `teams` pair gets
the same omp.combined marking as the combined case.
Assisted-by: Cursor / Claude Sonnet 5 High
[CIR][OpenMP] Add support for host_eval so that SPMD kernels can be used
This patch adds support for host_eval so that SPMD kernels and in the future
num_threads and other clauses can be implemented correctly.
Assisted-by: Cursor / Claude Sonnet 5 High
[scudo] Ensure unique backtrace in Fuchsia's die() (#243216)
Materialize the address of a unique static variable in a register so
compiler/linker optimizations (LTO, ICF) cannot fold die() together with
unrelated __builtin_trap() functions.
Assisted-by: Gemini
CGExprCXX: emit family and allockind attributes
This allows us to remove the special knowledge about C++ allocation from
LLVM's MemoryBuiltins.cpp, instead trusting attributes to communicate
the important properties.
Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.
Happily, clang now emits allocator family attributes for custom
allocators like the `__hot_cold_t` overloads in `new_hot_cold.cpp`
(which `isReplaceableGlobalAllocationFunction` in clang recognizes),
allowing us to remove that special knowledge from LLVM.
[7 lines not shown]
SimplifyLibCalls: preserve allocation attributes in optimizeNew
When `LibCallSimplifier::optimizeNew` rewrites an `operator new` call into a
`__hot_cold_t` allocation call, forward the allocation attributes
(`allockind`, `allocsize`, `"alloc-family"`, and parameter `allocalign`) from
the original call onto the synthesized call instruction alongside its metadata.
This is a new patch since 2023 (unlike most of the rest of the stack)
and allows the next patch to remove more specialized C++ knowledge
from the LLVM layer, instead leaving it in clang where it seems more
sensible.
This patch was authored with the assistance of an LLM and was reviewed
by me before posting.
[SLP]Support i1 constant lanes in copyable compare nodes
Model i1 constant lanes of an icmp node as compares of constants, or as
a compare of a non-undef/poison splat operand with itself. Lanes share
the predicate via CmpSamePredicateHelper. Drop samesign if a copyable
lane compares different i1 constants, where 0 and 1 differ in sign.
Assisted-by: Cursor
Pull-request: https://github.com/llvm/llvm-project/pull/234367
Reviewers: RKSimon, bababuck, madhur13490
Reviewed-by: bababuck
[ProfCheck] Remove ablation flag up to 2026-03-09 (#243301)
I used the wrong cutoff date (about a month too early) for removing
ProfCheckDisableMetadataFixes checks. Remove any that I forgot to remove
previously up to the new date where we have not ablated any of the
flags.
[CIR] Make cir-canonicalize a full canonicalizer
cir-canonicalize applied the CIR canonicalization patterns and folders
only to a hand-written list of operations. It now builds the pattern set
once in initialize() and runs CIR's greedy driver over every operation,
top-down like MLIR's canonicalizer, so every pattern and folder applies
everywhere. Only operations that rewriting left dead are erased, such as
the inputs of a folded operation: CIR stays close to the source, so
unused locals and ignored expressions are kept as in classic codegen.
Empty scopes and switches were removed only because they were dead, so
they get explicit canonicalization patterns.
For this, cir::applyOpPatternsGreedily takes an eraseOnlyNewlyDead flag.
With it, the driver records which of the given operations are unused
when rewriting starts and never erases those for being dead; a pattern
or a fold still can. The default still erases every trivially dead
operation.
The label tests used unused constants to show which code the driver
[7 lines not shown]
Reapply "[libc] Add network byte-order helpers to __support/net" (#243396)
Reverts llvm/llvm-project#243187, re-applying #243122.
Dropping libc.src.arpa.inet.htons from udp_test removed the entrypoint
gating that had been keeping it disabled on non-Linux targets. Move
udp_test into test/src/netinet/linux/ so it only builds on Linux.
The original commit message was:
In overlay mode, system headers (<netinet/in.h>, <arpa/inet.h>) may
define htons/htonl/ntohs/ntohl as macros. Including our entrypoint
headers after those system headers or calling LIBC_NAMESPACE::htons(...)
without extra parentheses runs into macro expansion issues.
Add templated net::hton<T> and net::ntoh<T> helpers in
__support/net/byte_order.h (along with making Endian conversions
constexpr), and use them across internal networking code, the
hton*/ntoh* entrypoints, and unit tests instead of the htons-family
[2 lines not shown]
[lldb] Let the process compare call frame addresses
StackID::IsYoungerThan asks Process::CompareCFAs before it assumes a stack that
grows down; the default has no opinion.