[llvm] [AArch64][SPIRV][GlobalISel] Migrate target-specific wip_match_opcode combines to MIR-pattern (PR #222903)

Vikash Gupta via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 02:34:10 PDT 2026


vg0204 wrote:

> The updated AArch64 checks remove several `lsl; sub` sequences. Which matcher priority change causes this? Could we cover the intended rule ordering with a focused MIR case?

The removed `lsl; sub` sequences come from `mul_const`, not from the shuffle-rule reordering.

AArch64's `applyNonConstInsert` combine rule lowers a variable i8 lane to `idx * 1`. Now, AArch64's `mul_const` treats `1` as `2^1 - 1` and rewrites that as `(idx << 1) - idx`, which is the `lsl; sub` pair. That is the same offset as `idx.

The priority change is the `mul_const` root moving from `wip_match_opcode G_MUL` to `(G_MUL $dst, $src1, $src2)`. In the generated table the opcode-only rule was attempted before `right_identity_one_int` (`G_MUL $dst, $x, 1`). As a normal instruction pattern it shares that rule's priority class, and the constant-operand pattern is more specific, so `x * 1` is now deleted instead of being expanded, which is a great `WIN!`. `mul_const` still runs for every other constant it handles.

I shall add a focused MIR test that could cover both possiblilty explaining the elimination of `lsl; sub`. I'll add an `aarch64-postlegalizer-combiner` test with two functions:

- `G_MUL %x, 1` folds to `%x` (`right_identity_one_int`; no `G_SHL`/`G_SUB`)
- `G_MUL %x, 7` still becomes `G_SUB (G_SHL %x, 3), %x` (`mul_const`)



https://github.com/llvm/llvm-project/pull/222903


More information about the llvm-commits mailing list