Skip to content

[mlir][vector] Skip uniform vectorization for non scalar type #128294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025

Conversation

Lewuathe
Copy link
Member

The code to vectorize the uniform type effectively assume the scalar type such as integer, float and index type. We should not regard other types as vectorizable uniform type because the following vectorization cannot treat the type properlty for now.

Fixes #128277

@llvmbot
Copy link
Member

llvmbot commented Feb 22, 2025

@llvm/pr-subscribers-mlir-affine

@llvm/pr-subscribers-mlir

Author: Kai Sasaki (Lewuathe)

Changes

The code to vectorize the uniform type effectively assume the scalar type such as integer, float and index type. We should not regard other types as vectorizable uniform type because the following vectorization cannot treat the type properlty for now.

Fixes #128277


Full diff: https://github.com/llvm/llvm-project/pull/128294.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp (+4)
  • (modified) mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir (+16)
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 71e9648a5e00f..7e69bce34aea4 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1106,6 +1106,10 @@ static bool isUniformDefinition(Value value,
     if (!loop.isDefinedOutsideOfLoop(value))
       return false;
   }
+
+  if (!isa<IndexType, IntegerType, FloatType>(value.getType()))
+    return false;
+
   return true;
 }
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir b/mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir
index 9244604128cb7..388d9ff423626 100644
--- a/mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir
+++ b/mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir
@@ -682,5 +682,21 @@ func.func @vec_vecdim_reduction_rejected(%in: memref<256x512xf32>, %out: memref<
  return
 }
 
+// -----
+
+// Non scalar type is not regarded as the uniform in the vectorization
+
 // CHECK-LABEL: @vec_vecdim_reduction_rejected
 // CHECK-NOT: vector
+
+func.func @vec_non_scalar_type() {
+  %idx0 = index.constant 0
+  %alloc_82 = memref.alloc() : memref<1xi64>
+  affine.for %arg0 = 0 to 78 {
+    %dim_191 = memref.dim %alloc_82, %idx0 : memref<1xi64>
+  }
+  return
+}
+
+// CHECK-LABEL: @vec_non_scalar_type
+// CHECK-NOT: vector

The code to vectorize the uniform type effectively assume the scalar
type such as integer, float and index type. We should not regard other
types as vectorizable uniform type because the following vectorization
cannot treat the type properlty for now.

See: llvm#128277
@Lewuathe Lewuathe force-pushed the skip-vecortization-for-non-scalar-type branch from 05ceaf0 to f67d451 Compare February 22, 2025 08:07
Copy link
Contributor

@CoTinker CoTinker left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@Lewuathe Lewuathe merged commit 8d5c1e6 into llvm:main Feb 22, 2025
11 checks passed
@Lewuathe
Copy link
Member Author

@CoTinker Thank you for the review!

@Lewuathe Lewuathe deleted the skip-vecortization-for-non-scalar-type branch February 22, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mlir] Crash when using --affine-super-vectorize="virtual-vector-size=128"
3 participants