[AggressiveInstCombine] Extend MulHigh fold for `or disjoint` (#228897)
`foldMulHigh` is excecuted after another fold, which folds `add` into
`or disjoint`. This can make `foldMulHigh` miss chances to fold.
Replacing `m_Add` into `m_AddLike` extends `foldMulHigh` so it can fold
more cases in `-O3` mode.
Notice that there are more cases in `foldMulHigh`. They may need to
replace `m_Add` too.
Fixes #221257.
RuntimeLibcalls: Add alignment to aligned memory helper arguments (#244724)
Add the alignment annotations to target specific memcpy-like functions.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[CIR] Give complex FP add/sub the fenv memory effects
cir.complex.fadd and cir.complex.fsub were Pure even with a constrained
fenv attribute, so they could be speculated or erased like unconstrained
ops. Derive them from CIR_FenvOp, as the other fenv ops are: constrained
ops read and write the FP environment and are only conditionally
speculatable, unconstrained ops stay effect-free.
Assisted-by: Claude Code (Opus 5.5).
[CIR] Handle integers wider than 64 bits in the vector constant folders
`cir::IntAttr::getUInt()` and `getSInt()` assert when the value needs
more than 64 bits. The folders of `cir.vec.cmp`, `cir.vec.ternary` and
`cir.vec.shuffle.dynamic` read constant elements through them, so they
asserted on a vector of `__int128` with such an element. C++ reaches
all three at -O0. The verifier of `cir.vec.shuffle` read its indices the
same way and asserted while parsing an index wider than 64 bits.
They now work on the `APInt` values:
- `cir.vec.cmp` compares the elements at their full width.
- `cir.vec.ternary` tests whether the condition element is zero.
- `cir.vec.shuffle.dynamic` masks the index before narrowing it.
- `cir.vec.shuffle` recognizes the -1 index by all of its bits being
set and range-checks the other indices without narrowing them.
Folds of integers up to 64 bits are unchanged.
Assisted-by: Claude Code (Fable 5.2).
[CIR] Lower constant vectors with undef, poison and zero elements
The `cir::ConstVectorAttr` verifier only checks the element types, so
`#cir.undef`, `#cir.poison` and `#cir.zero` are valid elements, and
`VecShuffleOp::fold` creates an undef element for a -1 index. The
lowering to the LLVM dialect handled int, float and bool elements and
hit an `llvm_unreachable` on anything else, so a
`__builtin_shufflevector` of two constant vectors with a -1 index
crashed `-fclangir -emit-llvm`.
A zero element is now a zero in the dense constant. An undef or poison
element also takes a zero there and is then replaced by an
`llvm.insertelement` of `llvm.mlir.undef` or `llvm.mlir.poison`.
`llvm.mlir.constant` cannot hold such an element itself: a dense
elements attribute holds only literals, and the translation to LLVM IR
accepts a per-element `LLVM::UndefAttr` or `LLVM::ZeroAttr` only in
struct and array constants and no `LLVM::PoisonAttr` at all. The
IRBuilder folds the insertions when the module is translated, in
function bodies and in global initializers, so the LLVM IR holds one
[4 lines not shown]
[CIR][NFC] Add a CIR_FenvOp base class (#245984)
Each operation with the fenv traits repeated them and the optional
`fenv` attribute in its own definition. This adds a `CIR_FenvOp` base
class that carries both, and the operations prepend their own arguments
to it. `CIR_FPBinaryOp` derives from `CIR_BinaryOp`, so it keeps the
traits and now appends its attributes to the `CIR_BinaryOp` arguments
instead of rebuilding the list. `cir.complex.fadd` and
`cir.complex.fsub` take the attribute without the traits and are not
changed here. The generated operation classes are unchanged.
Assisted-by: Claude Code (Fable 5.2).
[CIR] Mark LoweringPrepare init functions strictfp
Classic codegen's StartFunction makes a function that has no
FunctionDecl `strictfp` when the TU-wide default FP environment is
constrained: FP exceptions are not ignored or the rounding mode is
dynamic. That covers `_GLOBAL__sub_I_*`, `_GLOBAL__I_*`, the C++20
module initializer, `__cxx_global_var_init*`, `__cxx_global_array_dtor*`
and `__tls_init`. ClangIR marked only `__cxx_global_var_init*`, through
the `strictfp` attribute of its `cir.global`, so the other functions
and the calls in them were not `strictfp`.
LoweringPrepare creates these functions after CIRGen, so it reads the
TU-wide default from `#cir.lowering_options`. `no_trapping_math` already
records whether FP exceptions are ignored, and the new `rounding_math`
field mirrors `LangOptions::RoundingMath`. It is omitted when false, so
the module attribute prints as before without `-frounding-math`.
`buildRuntimeFunction` adds `strictfp` together with the other TU-wide
default function attributes. That needs no initializer to take the
attribute from, so it also covers a module initializer with nothing to
[3 lines not shown]
[CIR] Fix crashes in the complex constant folders
The folders of `cir.complex.real`, `cir.complex.imag` and
`cir.complex.create` asserted on constants that the `cir.const` verifier
accepts.
`cir.complex.real` and `cir.complex.imag` cast a constant operand to
`#cir.const_complex`. A complex constant can also be `#cir.zero`,
`#cir.undef` or `#cir.poison`. CIRGen emits `#cir.zero` for a
value-initialized complex, so clang crashed on `__real__ CI()`. A part
of `#cir.zero` now folds to the zero of the element type. The folders
leave an undef or poison operand alone.
`cir.complex.create` built a `#cir.const_complex` from any two constant
parts. The attribute holds int or float literals only, so its verifier
failed on a part that is undef, poison or a global view. The folder now
leaves such a create alone.
Assisted-by: Claude Code (Fable 5.2).
[lldb][Clike] Add ByteSizedType (#243814)
ByteSizedType is a mixin that adds a byte size to a Type. Type itself
only declares GetByteSize (returning "unknown" by default) because many
types derive their size from another type (arrays, typedefs, ...) or
from the target (pointers) and therefore don't need to store one. Types
with a size of their own, such as builtins, records and enums, will mix
this in.
An unknown size is stored as a UINT64_MAX sentinel instead of using
std::optional, which would need extra space for its flag.
assisted-by: claude
[lldb][Clike] Don't require TypeSystemClang for AppleObjCRuntimeV2 (#238961)
This makes this code compatible with TypeSystemClike. This is also code
that has no error handling aside from silently doing nothing, so I added
logging in case we fail to grab the TypeSystem.
[lldb][test] Add a new test for float types (Reland) (#238992)
This is a new modern test for float types that replaces the test logic
from `API/types` test that is about to be deleted.
This is #208451 but updated to also handle PDB.
See also #208402
assisted-by: claude
[lldb][Clike] Don't compare types using TSClang in ItaniumABIRuntime (#238958)
This won't work with TypeSystemClike. CompilerType has a generic API
that does the same without adding a dependency on TypeSystemClang.
[ConstantFolding] Add constant folding for strlen (#244183)
This patch adds constant folding of `strlen` on a string literal. These
are not uncommon, for example coming out of code like
```
std::string s = foo();
if (s == "bar") { ...
```
This patch (plus a follow-up one which exposes libfunc folding to inline
costs) helped resolve a 3% regression in a SPEC2026 benchmark coming out
of disable-pre-lto-vec changes.
[PowerPC] fix `ppc_fp128` `FABS` miscompile (#209286)
fixes https://github.com/llvm/llvm-project/issues/209034
On little-endian powerpc the bit position of the sign bit is bit 63, not
bit 127. However, `APFloat` reports that the sign bit is the MSB. As I
understand it, it is actually right about that because in the `APFloat`
internal representation the sign bit is in fact in the MSB, but using
this information for runtime values is incorrect for LE.
All three fix locations are required to get the correct output for this
reproducer.
I'm assuming there are more ways that this can fail, so a more
structural solution would be neat. I don't know how to do that though,
so in the meantime we can accumulate test cases and plug the gaps.
[libc++][pstl] Add a task scheduler based on std::thread (#237313)
This PR adds a simple task scheduler for PSTL.
With that, `std::execution::par` makes algorithms run in parallel on
non-Apple platforms (Apple platforms keep using `libdispatch`).
The implementation uses only the threading facilities provided by the
C++ Standard and contains no platform-specific code.
This code is intended to be a replaceable implementation detail of
libc++, which is not exported and can only be accessed via the
`std::__pstl::__statpart::__apply()` proxy.
The design prioritises correctness and simplicity over peak performance,
while still performing reasonably for typical usage (comparable to
`dispatch_apply_f()` from GCD).
[SPIRV][Offload] Implement `DynSharedMemory` for L0 (#231160)
This PR implements SLM for Level Zero backend. Every kernel in a module
lowered by the new SPIR-V pass receives a trailing `__local` argument,
including kernels that do not use SLM.
In order to support existing code that uses offload, the PR adds an
additional pass to SPIRV backend. The idea is that the pass is searching
for all extern unsized workgroup arrays and then it converts them to a
global variable that is initialized by an additional kernel argument to
every kernel in the module, including kernels that do not reference the
array.
The pass closes the gap between cuda/hsa and level_zero handling of the
dynamically sized workgroup memory, because level_zero (and openCL) only
support the local memory sized through kernel arguments compared to cuda
which configures it during kernel launch. It was inspired by existing
code in intel's fork of llvm.
[9 lines not shown]
[DAG] SimplifyDemandedVectorElts - add ISD::VECTOR_SHUFFLE_VAR handling (#244921)
Simplify the demanded elements of the mask operand using DemandedElts,
and use the mask's constant range to limit the demanded source elements.
The InstCombine part is in #245249.
Fixes #244310
AI Note: I've used Claude Code to help me understand `SelectionDAG`
concepts and the codebase. The implementation and tests are my own.
[X86] Fix miscompile of srl(xor(y, vecreduce_umax(x)), bw-1) (#244835)
In the signbit reduction fold added in #210281, `X` is initialized to
`N0` as the fallback for a failed `m_Not` match, but `sd_match`
overwrites `X` while trying the `xor` operands, even when the match
fails. If the last operand tried is `vecreduce_umax(x)`, the `xor` is
dropped and the shift is lowered to a `MOVMSK` test of `x`.
Set the fallback only after the match fails.
Fixes #244613
Fixes #244753
Assisted-by: Claude Opus 5.5
[DAGCombiner] Bail out in MatchLoadCombine when no bytes come from load (#244857)
Since #200247, calculateByteProvider returns ConstantZero for bytes
masked by AND with 0. This could make `Loads` empty in MatchLoadCombine
and triggers assertion.
Fix by early return when `Loads` is empty.
Fixes: https://github.com/llvm/llvm-project/issues/244804
Assisted-by: Claude Opus 5.5 <noreply at anthropic.com>
[NFC][ExecutionEngine] Fix calloc argument order in jitprofiling.c (#245189)
calloc takes (nmemb, size); the arguments were swapped. No functional
change, but it silences -Wcalloc-transposed-args on newer compilers.
---------
Co-authored-by: Claude <noreply at anthropic.com>
[CIR] Keep complex and bool casts constrained in strict FP functions
In a strictfp function ClangIR emitted plain `fpext`, `fptrunc`,
`fptosi`, `sitofp`, `uitofp` and `fcmp une` for casts between complex
types and for conversions between floating-point values and bool, where
classic codegen emits constrained intrinsics. CIRGen created the
complex casts and `float_to_bool` without the `fenv` attribute,
LoweringPrepare dropped the attribute when it expanded a complex cast,
and the LLVM lowering of `float_to_bool` and `bool_to_float` ignored
it.
`createCast` now takes an optional `fenv` attribute. CIRGen passes the
current floating-point environment for `float_to_bool` and for the
complex cast kinds that convert floating-point values. The kinds that
only select or pack a part get none. LoweringPrepare passes the
attribute of a complex cast to the scalar casts of its expansion. With
`fenv`, `float_to_bool` lowers to the quiet constrained `fcmp` and
`bool_to_float` to the constrained `uitofp`.
[4 lines not shown]
[MLIR][OpenACC] Keep private stores of array reductions on one lane (#245438)
Two fixes in the acc-cg-to-gpu lowering of privatized arrays:
- The walk that finds the acc.private_local behind a memref followed
every operand of the defining op. A memref.reinterpret_cast whose
dynamic sizes come from a different private descriptor was therefore
attributed to that descriptor. Scalar operands (sizes, strides, offsets,
indices) only shape an access, so the walk now follows only the view
source, the base entity of a partial access, or non-scalar operands.
- The per-thread partials of an array reduction are combined across the
accumulate's thread dimensions. Storing the reduction identity is safe
on every lane and initializes each partial. Any other store into a
partial is an update, and it is no longer made active on every thread:
it stays on one lane. Previously such an update ran on every lane, so
its contribution was combined once per lane.
[VPlan] Tighten usecase of findRecipe (NFC) (#236810)
Rename findRecipe to findUserRecursively for clarity, noticing that it
is only ever necessary in epilogue-based reasoning, which falls outside
VPlan modeling. Migrate one user to getSingleUser, and improve code
around remaining two users that do epilogue-based reasoning.
[LV] Increase test coverage of FOR-tail-folding (#238318)
Fix missing test coverage for the case when first-order-recurrences have
no in-loop users in the tail-folding case.
Assisted-by: llm