[LV] Fix crash when forced UserVF and EpilogueVF are ignored (#218282)
`computeBestVF()` assumes/asserts that there should be only 2 vplans as
long as there is a vplan for `UserVF` and when `EpilogueVF` is forced.
It doesn't consider the case when those VFs are ignored because of
invalid costs.
This patch removes the assert and add a check for the vplan size.
[flang][debug] Don't ask for a name table with -gline-directives-only (#218402)
On current main (since #217132), a unit built with
`-gline-directives-only` crashes the backend when DWARF 5 is requested:
```console
$ echo 'end program' > test.f90
$ flang -gdwarf-5 -gline-directives-only -S -o /dev/null test.f90
flang: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h:107:
llvm::MCSymbol *llvm::DwarfUnit::getLabelBegin() const:
Assertion `LabelBegin && "LabelBegin is not initialized"' failed.
```
The version has to be spelled out because flang does not yet default to
DWARF 5. Everything else about the command line is ordinary.
Such a unit emits line directives and no `.debug_info`, so the header of
its compile unit is never written and neither is the label that header
defines. Under DWARF 5 the accelerator table indexes every compile unit
[11 lines not shown]
[KnownFPClass] Move float-to-integer bitcast handling into KnownFPClass [NFC] (#218090)
I moved the float-to-integer bitcast code into a new `KnownBits
bitcastToKnownBits(const fltSemantics &FltSemantics) const;` function.
This allows the code to be unit testable, and allows the code to be
reused elsewhere.
I also have future plans to work on the `KnownBits` deductions for the
float-to-integer bitcast.
AI Disclosure:
I used ChatGPT Codex (sol-5.6) to help move the code which I reviewed.
[Debug Info] Fix a Verifier failure with redeclared nodebug functions (#218070)
When a forward-declard function is used before its definition, and the
definition has a nodebug attribute on it, the existing heuristic in
EmitFuncDeclForCallSite would fail, because it only saw the non-nodebug
forward declaration, thus emitting a conflicting DISubprogram for the
call site.
rdar://184780682
Assisted-by: claude
[AMDGPU] Combine redundant ballot intrinsic calls
Suppose there is a loop where there is a call to @llvm.amdgcn.ballot,
which maps to an instruction involving the exec mask as an operand. This
instruction duplicates if the loop is unrolled. With a higher number of
unrolled iterations, the code bloats with such redundant instructions
with $exec as there is no middle-end/backend pass which could combine
such instructions in a uniform CFG.
This patch introduces a transform in AMDGPUUniformIntrinsicCombine to
combine redundant calls to @llvm.amdgcn.ballot, to mitigate this issue.
The approach is to walk over the dominator tree and collect all calls to
@llvm.amdgcn.ballot. Map the result type and condition to the calls, to
avoid combining calls of different kinds. Calls A and B can be combined
into A iff:
- A and B are identical
- A dominates B
- all paths from A to B are uniform and exec-invariant.
[2 lines not shown]
[KnownFPClass] Improve sign-preservation for `asin` (#216119)
`asin(x)` is negative iff `x` is negative. However, this can be loosened
to `asin(x)` is negative iff `x` is negative-finite since `asin(-inf)`
is `NaN`.
[Remarks] Fix linker warnings from mold
This PR is trying to fix the linker warnings emitted from mold.
```
mold: warning: tools/remarks-shlib/Remarks.exports: cannot assign version `LLVM_24.0` to symbol `LLVMRemarkStringGetData`: symbol not found
```
Fixes #93028.
[OpenMP][Flang] Add integer-kind wrappers to omp_lib (#213505)
Many OpenMP routines in omp_lib currently accept only
integer(kind=omp_integer_kind) arguments, where omp_integer_kind maps to
c_int. As a result, Flang's type checking rejects calls that pass
integer(1), integer(2), or integer(8) arguments. To improve
compatibility, wrapper procedures have been added in the omp_lib module
for applicable routines, enabling support for integer(1), integer(2),
integer(4), and integer(8) argument types. The interfaces are added in
omp_lib module and the implementations are part of omp_lib_impl sub
module.
Similar changes are required in omp_lib.h and will be addressed in a
separate pull request.
Fixes #123948.
Assisted-by: Cursor
Co-authored-by: Cursor <cursoragent at cursor.com>
[OpenMP][flang] Use auto-generated data for modifier verification (#215648)
Introduce descriptors of OpenMP clauses and modifiers, auto-generated
from OpenMP specification data[*].
This replaces the preexisting modifier descriptors used in flang, the
code using it is adjusted to use the new definitions.
[*] This does not contain any actual auto-generation infrastructure. The
descriptors were generated by a custom script from the exported OpenMP
definitions.
[DAGCombiner] Fix divide-by-zero in visitSUBSAT when LHS is known-zero (#218284)
Fixes a crash introduced by #206592.
When the LHS of `usub.sat` is a known-zero value, `ActiveBits` is 0 and
`NarrowBits` starts at 0, causing a divide-by-zero via `ActiveBits %
NarrowBits` in `visitSUBSAT`.
Guard the loop with `NarrowBits != 0` to skip the narrowing optimization
in this case. Other folds handle the known-zero
case correctly.
A regression test has been added to `usubsat-narrow.ll` using a
known-zero LHS (`xor v, v`) to prevent future regressions.
Fixes #217964
[mlir][bufferization] Fix alloc_tensor copy operand assert with size_hint (#217734)
`AllocTensorOpInterface::bufferizesToMemoryRead` and
`bufferizesToMemoryWrite` assert that the `copy` operand is the last
operand. The ODS argument order is `dynamic_sizes`, `copy`, `size_hint`,
`memory_space`.
`copy` and `size_hint` can be used together, so the input is legal and
thus OSB asserts on legal code. Compare the operand against `getCopy()`
instead.
---
Code authored by Claude Code.
Signed-off-by: Víctor Pérez Carrasco <victor.pc.upm at gmail.com>
[mlir][tensor] Fix assertion on bufferizing expand_shape with a non-strided layout (#217714)
`ExpandShapeOpInterface::bufferize` creates a `memref.expand_shape`
directly without consulting `getBufferType`. The `memref::ExpandShapeOp`
builder computes the result layout with `computeExpandedType` and
asserts when that fails. `computeExpandedType` fails when the source
layout is not identity and `getStridesAndOffset` cannot decompose it, so
a non-strided affine layout aborts the compiler instead of reporting a
failed bufferization.
Query `getBufferType` first and return failure when it fails. The
model's own `getBufferType` already propagates the `computeExpandedType`
failure.
Rest of the behaviour is unchanged: we just fail gracefully now instead
of crashing.
---
Code authored by Claude Code.
[NFC][analyzer] Remove class 'NodeBuilder' (#217319)
This change concludes the removal of the class `NodeBuilder` which
previously added lots of unnecessary complications to the logic of the
analyzer engine.
The main feature of a `NodeBuilder` was that it tracked a "frontier"
set of exploded nodes, which were freshly created and not yet superseded
by the creation of another node. This was counterproductive in almost all
code that used `NodeBuilder`s -- with the exception of `CheckerContext`
where this was useful to support arbitrary chains of `addTransition`
calls in checkers.
As earlier commits removed the counterproductive use of `NodeBuilder`s,
there was only one surviving `NodeBuilder`, a data member of
`CheckerContext`, and its `generateNode` method was called only once, so
this commit inlines still relevant fragments of `NodeBuilder` into
`CheckerContext` and removes `NodeBuilder` as a separate class.
[4 lines not shown]
[clang][bytecode] Avoid copying function call arguments (#218399)
In most cases, we dony' need the SmallVector (we only use it to reverse
the arguments in the assignment operator case).
[clang-tidy] Fix modernize-use-noexcept crash on unparsed exception specs (#218256)
A failed template instantiation can leave a function type with an
`EST_Unparsed` exception specification.
`modernize-use-noexcept` currently calls
`FunctionProtoType::isNothrow()` for that type, which reaches an
unreachable path in `FunctionProtoType::canThrow()`.
This fixes the crash by skipping unparsed exception specifications
before querying whether the function is non-throwing.
Fixes #214291
[clang][bytecode] Optimize `PtrView::isOnePastEnd()` (#218375)
We call this a lot. Optimize this by inlining and then simplifying the
callers, i.e. don't call getFieldDesc() as much.
Also remove some code duplication from the similar
`Pointer::isOnePastEnd()`.
[mlir][linalg] Fix splat fold crash on non-TypedAttr element types (#218012)
`getScalarConstantAttrFromDenseSplat` returns
`getSplatValue<TypedAttr>()`, which for a derived attribute type is an
unchecked `llvm::cast`. Complex element types store their splat as an
`ArrayAttr` of two values, and `ArrayAttr` does not implement
`TypedAttr`, so the cast asserts on
%cst = arith.constant dense<(1.0,2.0)> : tensor<3xcomplex<f32>>
%0 = linalg.broadcast ins(%cst : tensor<3xcomplex<f32>>)
outs(%init : tensor<2x3xcomplex<f32>>) dimensions = [0]
under `mlir-opt --canonicalize`. Integer and float splats yield
`IntegerAttr`/`FloatAttr`, which are `TypedAttr`, so only non-scalar
element types are affected.
Guard with a `dyn_cast` and decline the fold when the splat value has no
`TypedAttr` representation. The helper is shared by the broadcast
pattern added in PR 195980 and the transpose patterns added in PR
195991, so both call sites are fixed; a test is added for each, as the
transpose case was not previously covered.