[LoopPredication] Register inserted assumptions with the AssumptionCache (#247964)
When widening a guard, LoopPredication inserts an llvm.assume of the
guard's old condition (on by default), but did not register it with the
AssumptionCache. The cache is never invalidated, so it was missing these
assumptions for the rest of the pipeline. This registers them in both
places that insert one.
Another follow-up to #245493.
[BOLT] Prefer global symbols at the same address (#244233)
Currently, BOLT's address-to-symbol resolution prioritizes function
symbols over other symbols and debug symbols, without making a
fine-grained distinction for local symbols. When multiple symbols share
the same address, BOLT may pick a local function symbol as the primary
name and emit it into the output binary and profile (this is especially
common on RISC-V due to the heavy use of label symbols). This can cause
confusion and potential profile mismatch issues (lots of `PG.` symbols
emitted, as described in #243760).
This patch standardizes the behavior of `discoverFileObjects()` and
refines the handling of local vs. global symbols, selecting the primary
symbol name according to the following priority order:
0: Global function
1: Non-global function
2: Other global symbol
3: Other non-global symbol
4: Global debug symbol
5: Non-global debug symbol
[InstSimplify] Fold comparisons of ctpop with its operand (#221104)
Fold llvm.ctpop(x) <= x by registering x as an unsigned upper bound of
ctpop(x). Automatically handles other canonicalized variants.
Partially addresses #220800.
Alive2 proof https://alive2.llvm.org/ce/z/MTkIxk
Fix edge case defects and add test coverage
Disallow promotion to no-loop for kernels with non-contant or false
conditional clause that affects teams or thread number.
Add guard for 0 trip count for empty loops on host-compile and accept
oversubscription flags there so it applies, so that no-loop kernels are
correctly sized from the count and no longer result in large grid sizing
for zero extended negative iteration counts.
Add guard to write keep-alive list only on per module finalize, matching
offload entry per-module write, to avoid multiple lists with different
names, of which only the first protects its entries, leaving clang's own
list unprotected.
Share one no-loop eligibility check between exec mode and body
The kernel is tagged SPMD_NO_LOOP by a single check, and the body is
emitted loop-free exactly when the kernel carries that tag. Add tests
for the clauses that block promotion.
[clang][OpenMP] Add no-loop SPMD kernel promotion
A target teams distribute parallel for that is guaranteed a thread for
every iteration does not need the loop around its body. Flang already
drops it and runs the region as a no-loop kernel.
Enable the same optimization for Clang through mirroring Flang's MLIR
promotion using OpenMPIRBuilder. The kernel is tagged SPMD_NO_LOOP, so
the runtime sizes the grid to the iteration space, and the body is
emitted without a loop around it. The canonical loop it consumes is
reconstructed in the no-loop branch rather than taken from an
OMPCanonicalLoop node, so the promotion does not require
-fopenmp-enable-irbuilder.
Restrict offload entry creation to module level finalize, preventing
asserts on missing offload entries from nested CodeGenFunction
finalizing before module completion.
[PowerPC] Fix stack protector + indirect tail call on power10 (#246638)
The issue here is that findSplitPointForStackProtector() does not
recognize the mtctr instruction as being part of the terminator sequence
(as it's not just a physreg COPY). This results in the block being split
between the physreg copies for the arguments and the call. This will
fail machine verification, and in release builds will end up removing
those copies, resulting in a miscompile.
Fix this by using a pseudo that takes a GPR and expands to mtctr plus
the usual tail-call sequence. This is implemented as a custom inserter
pseudo so we don't need to deal with register class constraints. This is
sufficient, as the stack protector split happens before finalize-isel,
so we don't need this to be an emit-time pseudo.
Fixes https://github.com/llvm/llvm-project/issues/195561.
Assisted-by: Claude
[llvm-strings] Add --unicode option (#242890)
This commit adds the --unicode option from GNU strings to llvm-strings.
The options from GNU strings are supported, plus an additional option
value --unicode=utf8 to explicitly request UTF-8 output, similar to how
we also add an --encoding=utf8 option value to explicitly specify the
input is UTF-8.
This makes a slight change from what was previously proposed: it adds
`--unicode=utf8` as an option value, and rather than `--unicode=default`
specifying UTF-8 output, it is equivalent to leaving out the option.
This makes a difference only in one corner case: this makes
`--encoding=S` and `--encoding=S --unicode=default` behave the same, as
the option implies.
[VPlan] Pull header mask out of (HM && Y) | (HM && Z)
The current (X && Y) | (X && Z) -> X && (Y | Z) combine requires one of the operands to have a single user. But if X is the header mask we usually want to do this regardless, similar to the reasoning behind reassociateHeaderMask.
This removes header masks in a good few places on RISC-V across llvm-test-suite and SPEC CPU 2017.
[VPlan] Erase dead masks in removeCommonBlendMask
removeCommonBlendMask was leaving behind the old masks, which can cause other masks to still have dead recipes as users. This in turn prevents simplifyBlends from picking a start value for a blend that would have been dead-coded.
Erasing them improves codegen in various benchmarks, for example on sqlite with clang -march=rva23u64 -O3:
void sqlite3HexToBlob(int *restrict dst, int *restrict src, int n) {
for (int i = 0; i < n; i++) {
int h = src[i], x;
if (h >= '0' && h <= '9')
x = h - '0';
else if (h >= 'a' && h <= 'f')
x = h - 'a' + 10;
else
x = h - 'A' + 10;
dst[i] = x;
}
}
[39 lines not shown]
[RISCV][GISel] Select scalable integer G_SPLAT_VECTOR (#247751)
Lower G_SPLAT_VECTOR with a scalar on the GPR bank to G_VMV_V_X_VL in
the instruction selector, with an undef passthru and VL set to VLMAX.
This matches what RISCVDAGToDAGISel::PreprocessISelDAG does for
SPLAT_VECTOR,
so the existing vmv.v.x patterns are reused.
Add a G_VMV_V_X_VL generic instruction equivalent to riscv_vmv_v_x_vl.
Also specify the legal G_SPLAT_VECTOR legalizer actions before the
custom one.
Part of #246831
[Hexagon] Disable global scheduler V2 by default (#247953)
Make -enable-global-sched default to false, until reported issues in the
pass are addressed. Hand-written tests that exercise it set
-enable-global-sched=true explicitly, and the autogenerated CHECK lines
are regenerated with the pass disabled.
Assisted by AI
[X86][APX] Don't fold an NDD reload that needs a COPY into a split register (#246808)
This is an alternative solution to #237148 and #243055. If the
destination was created by splitting or spilling, just refuse the fold
rather than post handling the inserted COPY. It avoids unnecessary
spill/reload due to the COPY handling.
Assisted-by: Claude Opus 5.5
[AVR] Remove incorrect selection patterns of two pseudo instructions (#247453)
Remove the selection patterns of STDWSPQRr/STDSPQRr, which cannot guarantee the base pointer is the SP register..
Fixes https://github.com/llvm/llvm-project/issues/246837.
[DirectX] Wire up CodeGenPassBuilder
Introduce DirectXCodeGenPassBuilder and wire up the pass pipeline to be
the same as the existing DirectXPassConfig/addPassesToEmitFile.
Assisted-By: LLM
Reviewers: hekota, bogner
Pull Request: https://github.com/llvm/llvm-project/pull/244834
[NFC][CodeGen][NewPM] Allow overriding buildPipeline
Also some refactoring around registerAsmPrinter to make targets that
want to override the entire pipeline (e.g., DirectX) easier. We can't
just do everything in buildCodeGenPipeline or otherwise we need to
reinvent all the start/stop machinery.
Assisted-By: LLM
Reviewers: arsenm, aeubanks
Pull Request: https://github.com/llvm/llvm-project/pull/244833
[Hexagon] Don't packetize a slot-0-only store with a later aliasing store (#246713)
When two stores in a packet write to the same location, the one in slot
0 takes effect last. The shuffler keeps program order by putting the
first store in slot 1, but it cannot when the first store can only go in
slot 0, such as an HVX vmem. The packetizer allowed any store followed
by a store, so the HVX store then overwrote the later store.
This miscompiles a variable-index insert element into a vector on the
stack: the vector spill and the element store land in one packet, and
the inserted element is lost.
Fixes #246036.
_AI Usage: Claude Code_
---------
Co-authored-by: soumikiith <cs21resch11004 at iith.ac.in>
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[Hexagon] Handle partially redefined QFP pair refills (#244193)
Add the conversion instruction for a subregister selectively if the
subregister has not been redefined.
Fixes #237218
Assisted by AI.
---------
Co-authored-by: quic-santdas <quic_santdas at qti.qualcomm.com>