[InstCombine] Fold min/max of int-to-fp casts into integer min/max (#237190)
When both operands of a floating-point min/max intrinsic are the same
int-to-fp cast, the min/max can be done on the integers and converted
once:
m(uitofp X, uitofp Y) -> uitofp(umin/umax(X, Y))
m(sitofp X, sitofp Y) -> sitofp(smin/smax(X, Y))
Integer-to-float conversion is monotonic, so it preserves the order of
the operands. This covers all six min/max intrinsics.
Alive2: https://alive2.llvm.org/ce/z/PKQyse
[mlir][SPIR-V] Pass serialization options in --serialize-spirv (#237710)
serializeModule dropped its options, so --spirv-emit-debug-info had no
effect
---------
Co-authored-by: Igor Wodiany <dev at wodiany.com>
[clang][bytecode] Resolve FIXME comment in CheckArraySize (#237860)
Add `getActiveBits()` to primitive integral types so we don't have to go
through `APSInt`.
[MLIR][XeGPU] Fix memref-i4 offsets computation (#233474)
Introduces a new utility function `xegpu::addElemOffsetInBytes` for
byte-offset computation and use it in `xegpu-to-xevm` and
`peephole-optimizer`.
In comparison with the old logic, the new utility function handles
sub-byte (i4) types correctly by first multiplying the element-offset by
bit-width and dividing by 8 later:
```c++
// old logic
byteOffset = elemOffset * (bitWidth / 8);
basePtr += byteOffset;
// old logic breaks on sub-byte types:
byteOffset = 1024 * (4 / 8); // 1024 * 0 == 0
basePtr += 0; // reads from the start of the buffer
// new logic in 'addElemOffsetInBytes'
[6 lines not shown]
[OpenMP][clang] Correctly widen loop iteration calculation
For a loop like `for (uint32_t i = 0; i < (size_t)13; i += 2)`, widen
the `lower - step + 1` calculation to the size of the upper bound type,
aka size_t in this case. Otherwise, we would not caluclate 13 - (-1),
but instead 13 - (0xFFFFFFFF) and get the wrong result.
Fixes https://github.com/llvm/llvm-project/issues/70687.
Claude assisted with this patch.
[AArch64][LSR] Prefer LSR solutions with less pre/post-index (#234264)
In AArch64 CPUs a pre or post indexed load/store typically uses an extra
ALU resource compared to a load/store that uses offset addressing.
Therefore in Loop Strength Reduce we should favor solutions with fewer
of these instructions when the Insns and NumRegs costs are equal.
This currently has no effect, as the preferred addressing mode for
AArch64 is None so LSR assumes pre/post index instructions don't exist,
but I'm planning on changing the addressing mode in the future.
[clang][Lex] Fix assertion on unclosed paren in PP directive (#234992)
Clangd's preamble scan runs the preprocessor in single file parse mode.
If a directive contains an undefined identifier and ends inside a
subexpression (e.g. due to an unclosed parenthesis), PeekTok is already
eod when DiscardUntilEndOfDirective is called. That function lexes one
more token which is eof on the truncated buffer and triggers an
assertion.
Only discard if the current token is not eod, analogous to the other
callers of DiscardUntilEndOfDirective.
Fixes #226555
[lldb] Read Wasm globals through a frame of the stub's own thread (#237195)
This commit fixes an unconditional cast from Thread to ThreadWasm, which
ignores the possibility of an OS plugin, by using the real thread list.
Note that using the qWasmGlobal variant that expects a frame index is
unlikely to succeed in the presence of a custom unwinder that presents a
different view of frames. But at the very least we shouldn't crash by
doing an invalid cast, which this fixes.
[clang][Modules] Keep existing global definition on type mismatch in GetOrCreateLLVMGlobal (#223877)
When a global is requested for definition but a definition with the same
mangled name already exists, return it as is instead of creating a fresh
global and erasing the defined one, even if its type differs from the
requested type.
The type can legitimately differ when the initializer folded to a
different (e.g. anonymous) type, as happens with unions. Erasing the
defined global dangles pointers held by callers, e.g. the
`AssociatedData` of entries in `llvm.global_ctors`, leading to a
use-after-free crash during `EmitCtorList`. This also keeps the
deferred-decls "already emitted" check sound, since it queries with
`IsForDefinition`, which must be non-destructive.
Add a header-unit regression test: an inline variable with an
anonymous-union member, constant-initialized but requiring dynamic
destructor registration, must be emitted exactly once when imported from
header units. The folded initializer has an anonymous type that differs
[8 lines not shown]
[flang][OpenMP] Diagnose NOWAIT used with TASK REDUCTION modifier (#237326)
E.g. OpenMP 6.0 p254
> The task reduction-modifier must not appear in a reduction clause if
> the nowait clause is specified on the same construct.
Assisted-by: Codex
[mlir][SPIR-V] Require DotProductInput4x8Bit only for 4-element i8 vectors (#237711)
Other i8 vector sizes need DotProductInputAll per
SPV_KHR_integer_dot_product
[Inliner] Change CalleeTTI -> CallerTTI (#231905)
It makes more sense to use the caller's TTI, as this way we can query
whether the instruction can be inlined into the parent function, using
state described by the caller's TTI.
For example, for AArch64 SME where a function can be in a different mode
(streaming/non-streaming), the cost-model gives different answers based
on the TTI used.
For now, we don't expect to see any changes in behaviour as there are
currently no targets where it makes different cost/inlining-decisions
based on which TTI is used.
[FuncSpec] Relax restrictions on code size growth (#196570)
This patch is a preparation for
https://github.com/llvm/llvm-project/pull/195886 , which affects code
size and thus causes more functions to be rejected by the current code
size growth restriction in function specialisation.