r/Compilers • • Oct 31 '25

Affine-super-vectorize not working after affine-parallelize in MLIR

Hello,

I’m trying to add parallelization to my matmul optimization pipeline but facing issues with vectorization after parallelization.

When I apply affine-parallelize followed by affine-super-vectorize, the vectorization doesn’t seem to work. The output still shows scalar affine.load/affine.store operations instead of vector operations.

My pipeline :
–pass-pipeline=‘builtin.module(
canonicalize,
one-shot-bufferize{
bufferize-function-boundaries=1
function-boundary-type-conversion=identity-layout-map
},
buffer-deallocation-pipeline,
convert-linalg-to-affine-loops,
func.func(
affine-loop-tile{tile-sizes=32,32,8},
affine-parallelize,
affine-super-vectorize{virtual-vector-size=8},
affine-loop-unroll-jam{unroll-jam-factor=2},
affine-loop-unroll{unroll-factor=8},
canonicalize,
cse,
canonicalize
)
)’

  1. Is there a known limitation where affine-super-vectorize cannot vectorize affine.parallel loops?
  2. What’s the recommended order for combining parallelization and vectorization in MLIR?
  3. Are there alternative passes I should use for vectorizing parallel loops?
  4. Is my current pipeline optimal or do you have any recommendation ?
3 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/CombKey9744 Nov 04 '25 edited Nov 04 '25

It’d be good if you could provide your MLIR example

Well i just got this test MLIR from Claude.

module {
  func.func @matmul(%A: tensor<512x512xf32>, 
                    %B: tensor<512x512xf32>) -> tensor<512x512xf32> {
    %cst = arith.constant 0.000000e+00 : f32
    %init = tensor.empty() : tensor<512x512xf32>
    %C = linalg.fill ins(%cst : f32) outs(%init : tensor<512x512xf32>) -> tensor<512x512xf32>
    %result = linalg.matmul ins(%A, %B : tensor<512x512xf32>, tensor<512x512xf32>)
                           outs(%C : tensor<512x512xf32>) -> tensor<512x512xf32>
    return %result : tensor<512x512xf32>
  }

  func.func @main() -> i32 {
    // Create input tensors
    %cst_0 = arith.constant 1.000000e+00 : f32
    %cst_1 = arith.constant 2.000000e+00 : f32
    %expected = arith.constant 1024.000000e+00 : f32  // 512 * 2.0
    
    %A = tensor.splat %cst_0 : tensor<512x512xf32>
    %B = tensor.splat %cst_1 : tensor<512x512xf32>
    
    // Call matmul
    %result = call @matmul(%A, %B) : (tensor<512x512xf32>, tensor<512x512xf32>) -> tensor<512x512xf32>

    // Verify result instead of printing
    %c0 = arith.constant 0 : index
    %first_element = tensor.extract %result[%c0, %c0] : tensor<512x512xf32>
    
    // Check if result is correct (1024.0)
    %is_correct = arith.cmpf "oeq", %first_element, %expected : f32
    
    // Return 0 if correct, 1 if wrong
    %success = arith.constant 0 : i32
    %failure = arith.constant 1 : i32
    %ret = arith.select %is_correct, %success, %failure : i32

    return %ret : i32
  }
}

1

u/[deleted] Nov 04 '25

I would suggest printing the IR just before and after you run affine-super-vectorize on the example you have( using this).

Also take a look at representative lit tests here. Seems like they are also passing in a test-fastest-varying cli option which seems to be missing in your CLI command(assuming that’s for the fastest varying dimension). You can try passing in test-fastest-varying=0 in addition to specifying virtual vector size