[MISched] Enable store sequencing by default (#235948)
Enables the store-sequencing DAG construction algorithm by default on
all targets and updates tests accordingly. The following is a list of
tests which I updated by hand, alongside the resolution I made in each
case:
- `AArch64/aarch64-stp-cluster.ll`, added an extra `store` to act as
sequencing store;
- `AArch64/arm64-misched-memdep-bug.ll`, updated `CHECK` lines;
- `AArch64/dag-maps-huge-region.ll`, disabled store-sequencing (this
test will be dropped);
- `AArch64/misched-bundle.mir`, updated `CHECK` lines;
- `AArch64/tailcall_misched_graph.ll`, updated `CHECK` lines;
- `AMDGPU/ds-combine-with-dependence.ll`, swapped reordered `CHECK`
lines;
- `AMDGPU/schedule-relaxed-occupancy.ll`, updated `CHECK` lines;
- `AMDGPU/swp-amdgpu-pipeline-loop-carried-mem.mir`, disabled store
sequencing (the test is correct with store sequencing enabled, but a
loop carried edge is subsumed by a new intra-iteration barrier edge, so
[16 lines not shown]
[RelLookupTableConverter] Add support for phi/select uses (#245614)
This adds support for converting lookup tables that are used through phi
or select nodes, which can for example be introduced though SimplifyCFG
common code sinking.
The use walk now looks through phi and select instructions. For these it
requires that all phi/select operands can be converted to relative
tables, and converts all of them at once.
To support this, the replacement logic now rewrites the uses while still
referring to the original table, and then replaces the tables with RAUW.
This avoids the need to track or recreate the phi/select nodes.
There's still a small limitation here in that the "all operands must be
convertible" check effectively precludes nested phis/selects, as it's
not recursive.
clang size-data drops by 1.73%.
Fixes https://github.com/llvm/llvm-project/issues/243901.
[mlir][affine] Implement PromotableRegionOpInterface for AffineIfOp (#225388)
Follow-up to #221123 to use the structured mem2reg pass on affine if
operations.
[Inliner] Remove unused functions with trivial comdat eagerly (#245935)
Inlining was dropping functions that become unused as a result of
inlining eagerly, as this impacts the single-call bonus. However, this
is not done for functions in comdats, as this requires all functions in
the comdat to be dead.
This adds a special case for trivial comdats, where the function is the
only member. This has become more relevant after the introduction of
module-local hints in https://github.com/llvm/llvm-project/pull/228074,
as linkonce_odr functions (which will typically have a comdat) can now
be subject to the single-call bonus.
This gives a 1.2% compile-time improvement on tramp3d-v4. This is
because we end up inlining a call earlier and do less redundant
simplification. In other cases, it could probably also regress
compile-time by enabling more inlining overall.
[SystemZ] Fix aliasing bug with vec_scatter/gather_element (#245724)
The implementation of vec_scatter_element and vec_gather_element in
vecintrin.h could in some cases violate aliasing rules.
Fix by using __builtin_memcpy rather than pointer cast.
Fixes: https://github.com/llvm/llvm-project/issues/244085
[clang] Allow fixed-point to bool enumeration conversions (#245853)
Fixes #245850.
Since #244494, `Type::getScalarTypeKind()` returns `STK_Bool` for an
enumeration
with a fixed bool underlying type, so converting a fixed-point value to
such an
enumeration selects `CK_FixedPointToBoolean`. `VisitCastExpr()` still
asserts
that the destination of that cast kind is `bool`, which crashes an
assertions
build:
```c
enum E : bool { F, T };
enum E to_enum(_Accum x) { return (enum E)x; } /* clang -std=c23 -ffixed-point */
```
[4 lines not shown]
AArch64: Fold SVE deinterleaving zero extensions into transposes (#241199)
Transform deinterleave-and-zero-extend patterns into TRN1/2 operations
using a zero vector, and add code-gen tests.
[AI disclosure] I used AI to explore and understand the codebase,
understand the problem scope, find existing relevant functions and
examples, but the implementation is written entirely by myself.
[LICM] Use EarliestEscapeAnalysis when checking for in-loop clobbers (#236520)
LICM's clobber check treated an object captured anywhere in the function
as possibly aliased by pointers loaded or returned in the loop. With
EarliestEscapeAnalysis only captures before the pointer is obtained
count.
Objects captured only after the loop or on an unwind path no longer
block hoisting.
EarliestEscapeAnalysis is already used by MemDep, MemCpyOpt and DSE.
[AArch64][NFC] Add [de]interleave6 tests (#245247)
interleave6 and deinterleave6 already have support for custom lowering
using st3/ld3 and uzp/zip, but was missing test coverage for a sequence
where values are interleaved and stored, or loaded and deinterleaved.
Assisted-by: Codex
[mlir][linalg] Don't use `in_bounds` in `vectorizeAsInsertSliceOp` (#245042)
Updates `vectorizeAsInsertSliceOp` (Linalg vectorization) so that masks are
used instead of the `in_bounds` attribute when generating
`vector.transfer_read` and `vector.transfer_write` Ops.
One test in `mlir/test/Dialect/Vector/transform-vector.mlir` is removed. While
the change in the generated IR is insignificant (due to the appearance of
masks), it's an example of mixing many transformations in one test, i.e. going
against our testing guidelines (https://mlir.llvm.org/getting_started/TestingGuide/):
> Tests should be minimal, and only check what is absolutely necessary.
In addition, it's a relatively old test that predates many other more focused
tests (in e.g. mlir/Dialect/Vector or mlir/Dialect/Linalg) - I doubt this
erasure affects test coverage. Finally, it tests the lowering (tiling,
vectorization, bufferization, etc.) of a `linalg.matmul` operation. Such tests
do not belong under `mlir/test/Dialect/Vector`.
Part of https://github.com/llvm/llvm-project/issues/227821
[Evaluator] Create TargetLibraryInfo in the context of the evaluated function (#245269)
The Evaluator uses a single TargetLibraryInfo instance for each
evaluated function. That TLI is created in the context of
the top-level function being evaluated and is not necessarily
valid for other functions.
In particular, this caused the Evaluator to fold calls to standard
library functions despite the presence of "no-builtins" attribute.
This patch makes the Evaluator create a new
TargetLibraryInfo instance for each evaluated function.
Fixes https://github.com/llvm/llvm-project/issues/244323
[mlir] Declare reshapeLikeShapesAreCompatible before verifyReshapeLikeTypes (#245432)
`verifyReshapeLikeTypes` is a function template that calls
`reshapeLikeShapesAreCompatible`, which is only declared further down
the header. The call is dependent, so it resolves at instantiation
through ADL on the lambda's enclosing namespace, which newer compilers
accept. Clang 7 does not (it predates the DR1690 lookup rules for local
classes) and fails with "call to function
'reshapeLikeShapesAreCompatible' that is neither visible in the template
definition nor found by argument-dependent lookup" while building
TensorOps.cpp. Move the declaration above the template so ordinary
lookup finds it.
[mlir] Use the default op registration in upstream dialects
Opts all upstream dialects that define operations in ODS into `useDefaultOperationRegistration`, which removes a decent bit of code. DLTI, which has no operations, and Transform, whose operations are also generated by its extensions, are left as is. Doing so required minor changes:
* ArmSME and Linalg did an ad-hoc partitioning before and now utilize the partitioning feature instead
* Flang's codegen dialect is now ODS generated
Dialects whose `initialize` became empty set `hasInitializer` to 0.
Co-authored-by: Claude <noreply at anthropic.com>
[mlir][ODS] Register the operations of a dialect by default (#245266)
Dialects registered their ODS operations by expanding `GET_OP_LIST` into
`addOperations` in `initialize`, while sharded and partitioned dialects
had to call the generated `register<Dialect>Operations` themselves. This
was not only an inconsistent interface but also boilerplate for every
dialect definition.
Like attributes and types do since
https://github.com/llvm/llvm-project/pull/243481, operations are now
only registered by a generated `register<Dialect>Operations` hook that
the generated dialect constructor calls, for all generated files whether
sharded, partitioned or neither (i.e., we are consistent again!).
To avoid breaking downstreams `useDefaultOperationRegistration` is
currently set to 0 for compatibility but will be switched in a future
PR.
Dialects without operations, or that register them manually, should set
`useDefaultOperationRegistration` to 0. `-op-registration-name` names
[11 lines not shown]
[Mips] Use a 0/1 result for constrained FP compares on R6 (#245918)
#245469 made R6 FP compares produce 0/1 booleans, so lowerSETCC takes
the low bit of the cmp.cond.fmt mask. lowerFSETCC, from #245178, still
returned the whole mask for STRICT_FSETCC and STRICT_FSETCCS, which was
correct while FP compares used 0/-1 booleans. With both changes on main,
a constrained compare used as a value gives -1 for true.
Take the low bit of the mask, as lowerSETCC does. This fixes the
CodeGen/Mips/fp-strict-fcmp.ll failure on main, seen on the buildbots
since both changes landed.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[MIR2Vec] Build the vocabulary once per module (#245773)
The legacy printer rebuilt it for every machine function
On a 112-function AMDGPU MIR file, `llc -run-pass=none -print-mir2vec`
drops from 14.4s to 6.8s
[mlir] Use the default op registration in upstream dialects
Opts all upstream dialects that define operations in ODS into `useDefaultOperationRegistration`, which removes a decent bit of code. DLTI, which has no operations, and Transform, whose operations are also generated by its extensions, are left as is. Doing so required minor changes:
* ArmSME and Linalg did an ad-hoc partitioning before and now utilize the partitioning feature instead
* Flang's codegen dialect is now ODS generated
Dialects whose `initialize` became empty set `hasInitializer` to 0.
Co-authored-by: Claude <noreply at anthropic.com>
[AMDGPU] Fold fmul with zero checks to fmul.legacy (#229357)
Recognize f32 multiplication with zero checks in AMDGPUCodeGenPrepare,
including fabs/fneg wrappers.
Example:
```
(x == 0 || y == 0) ? +0.0 : x * y
==>
llvm.amdgcn.fmul.legacy(x, y)
```
AMDGPU example: https://godbolt.org/z/5f56T46fT
Assisted-by: Claude Opus 5.5
[LoongArch][NFC] Pre-commit tests for sign-extended vector element extraction (#241718)
Add tests where a constant-index i8/i16 vector element extraction is
followed by a sign extension.
Assisted-By: LLM
[LoongArch] Use signed vector extract for sign extension (#241719)
`[x]vpickve2gr.{b/h}` already sign-extends the extracted element to
GRLen, so a following `ext.w.{b/h}` is redundant:
```llvm
%e = extractelement <16 x i8> %v, i64 7
%r = sext i8 %e to i32
```
```asm
vpickve2gr.b $a0, $vr0, 7
ext.w.b $a0, $a0
```
Add patterns that fold sext_inreg of a constant-index i8/i16 vector
extraction into VPICKVE2GR_B/H, mirroring the existing zero-extension
patterns for VPICKVE2GR_BU/HU. The i32 case already needs no extra
instruction.
Assisted-By: LLM
[mlir][SPIR-V] Pack only CPacked structs in SPIRVToLLVM (#245771)
Other structs without Offset have natural alignment, so packing them
misplaced members
[mlir][SPIR-V] Order -0.0 before +0.0 in arith.maximumf/minimumf (#245530)
FMax and FMin return the first operand on ties, so max(-0.0, +0.0) gave
-0.0
In #225667 the same bug was fixed for llvm.maximum/minimum in the SPIR-V
backend
[AMDGPU] Remove R600 usage from llvm tests. NFC
Second step of removing the R600 (TeraScale) tests:
* [x] clang, flang, lld tests (#245524)
* [x] llvm tests (this patch)
Tests that only cover R600 are deleted, including the tests of the
`llvm.r600.*` intrinsics. In tests shared with GCN, the r600 RUN lines
and their now unused EG, CM and R600 checks and comments are removed,
and autogenerated checks are regenerated. The R600 cases in the yaml,
TableGen, TargetParser, Triple and DataLayout upgrade tests are removed
too:
```
; RUN: llc -mtriple=amdgcn -mcpu=tahiti < %s | FileCheck -check-prefixes=SI,FUNC %s
; RUN: llc -mtriple=r600 -mcpu=redwood < %s | FileCheck -check-prefixes=EG,FUNC %s
; EG: LDS_READ_RET
-->
[8 lines not shown]
[SLP][AArch64] Don't count splats folded into indexed FMLA in inst count (#230105)
The VF=2 instruction-count check (#190414) counts each splat gather as
one instruction per lane, including repeated gathers of the same splat.
In two Horner chains in x^2, the splat of x^2 feeds each level's fused
fmul/fadd pair, so the check sees 15 vector instructions against 8
scalar fmas and rejects a tree the cost model finds profitable. AArch64
emits no splat here: each pair becomes an indexed `fmla.2d` that reads
lane 0.
This uses the build-vector context hint (#224766). AArch64 reports
`SplatOpFolded` for an FP splat whose fmul users each fuse with a
contractable fadd or fsub of the same opcode in their block, decided
from the IR, and costs its broadcast as free. The count skips a splat
gather when the new `TTI::isSplatFolded()` says so: it checks for a
splat of a non-constant value and queries the hint, with SLP only
supplying the users. Unfused fmuls are not reported, since the scalar
count only credits fused pairs as fmas. Splats with undef lanes may need
a freeze and are never treated as folded.
[29 lines not shown]
[lldb][NFC] Remove GetChildCompilerTypeAtIndex
All type systems and callers use GetChildAtIndex now, so this patch removes
TypeSystem::GetChildCompilerTypeAtIndex and its CompilerType wrapper, and
makes TypeSystem::GetChildAtIndex pure virtual.
assisted by claude
[lldb][NFC] Remove redundant zero assignments in TypeSystemClang
TypeSystemClang::GetChildAtIndex starts from a value-initialized
ChildTypeInfo, so it doesn't need to set byte_offset to 0.
assisted by claude