Skip to content

[LLVMCPU] Peel instead of masking for sub-byte operands - #25200

Draft
roberto-laudani wants to merge 1 commit into
mainfrom
users/roberto-laudani/llvmcpu-peel-sub-byte
Draft

roberto-laudani wants to merge 1 commit into
mainfrom
users/roberto-laudani/llvmcpu-peel-sub-byte

Conversation

@roberto-laudani

@roberto-laudani roberto-laudani commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25203

Narrow-type emulation cannot rewrite masked loads and stores of packed sub-byte elements once vector.create_mask is lowered. getVectorPreProcStrategy now selects peeling for linalg ops with packed sub-byte operands, so static shapes need no mask.

Assisted by: Claude

@egebeysel egebeysel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally in the good direction, though there is one correctness issue that this PR surfaces (for AArch64 NEON which already gets a peeling config, this issue was already there), see my inline comment for the e2e test.

Furthermore, #25203 says that loops with dynamic trip counts do not compile, and this would not necessarily fix that, right?:

  • tensor<?xi4>: the peeled remainder has a runtime size, so it's still masked and still hits the same error.
  • Static shapes split across workgroups: e.g. tensor with workgroup tile M with N % M != 0. Each wg has the extent affine.min(N - off, M), which isn't a constant. The remainder inside a workgroup is therefore masked again.
  • setTransposeLikeOpRootConfig does not set the peeling config so if it's realistic to get an i4 transpose, that wouldn't be handled.

Comment on lines +286 to +287
// sub-byte elements once their masks are lowered, so peel. Remainders of
// dynamic size are still masked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where exactly does this happen? can you also write a test to showcase/test that setting the peeling attr gets that pass to succeed (explicitly as a "unit" test instead of the e2e test)?

]> : tensor<34xi4>
%0 = tensor.empty() : tensor<34xf32>
%res = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]}
ins(%input : tensor<34xi4>) outs(%0 : tensor<34xf32>) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%res = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d1)>, affine_map<(d0, d1) -> (d0, d1)>], iterator_types = ["parallel", "parallel"]} ins(%3, %4 : tensor<128x70xi4>, tensor<70xf32>) outs(%5 : tensor<128x70xf32>) {
  ^bb0(%in: i4, %in_0: f32, %out: f32):
    %7 = arith.sitofp %in : i4 to f32
    %8 = arith.mulf %7, %in_0 : f32
    linalg.yield %8 : f32
  } -> tensor<128x70xf32>

This would pick tile sizes distribution = [128, 35], vector_parallel = [1, 4] and silently miscompile and produce wrong results on rows 35-66. We should also make sure to get byte-aligned tiles.

@roberto-laudani
roberto-laudani marked this pull request as draft November 12, 2026 08:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mlir][vector] Masked loads and stores of i4 only work with create_mask masks

4 participants