[Mlir-commits] [mlir] 71705f5 - [mlir][Arith] Disallow casting between scalable and fixed-length vectors
Javier Setoain
llvmlistbot at llvm.org
Tue Feb 15 09:35:35 PST 2022
Author: Javier Setoain
Date: 2022-02-15T17:34:42Z
New Revision: 71705f531f6e34a4fe4e0a178d0269c6f11b5672
URL: https://github.com/llvm/llvm-project/commit/71705f531f6e34a4fe4e0a178d0269c6f11b5672
DIFF: https://github.com/llvm/llvm-project/commit/71705f531f6e34a4fe4e0a178d0269c6f11b5672.diff
LOG: [mlir][Arith] Disallow casting between scalable and fixed-length vectors
Casting between scalable vectors and fixed-length vectors doesn't make
sense. If one of the operands is scalable, the other has to be scalable
to be able to guarantee they have the same shape at runtime.
Differential Revision: https://reviews.llvm.org/D119568
Added:
Modified:
mlir/lib/IR/TypeUtilities.cpp
mlir/test/Dialect/Arithmetic/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/IR/TypeUtilities.cpp b/mlir/lib/IR/TypeUtilities.cpp
index 7533a60a444b..e2cee18c418d 100644
--- a/mlir/lib/IR/TypeUtilities.cpp
+++ b/mlir/lib/IR/TypeUtilities.cpp
@@ -126,6 +126,19 @@ LogicalResult mlir::verifyCompatibleShapes(TypeRange types) {
if (!llvm::all_of(shapedTypes, [](auto t) { return t; }))
return failure();
+ // Return failure if some, but not all, are scalable vectors.
+ bool hasScalableVecTypes = false;
+ bool hasNonScalableVecTypes = false;
+ for (Type t : types) {
+ auto vType = t.dyn_cast<VectorType>();
+ if (vType && vType.isScalable())
+ hasScalableVecTypes = true;
+ else
+ hasNonScalableVecTypes = true;
+ if (hasScalableVecTypes && hasNonScalableVecTypes)
+ return failure();
+ }
+
// Remove all unranked shapes
auto shapes = llvm::to_vector<8>(llvm::make_filter_range(
shapedTypes, [](auto shapedType) { return shapedType.hasRank(); }));
diff --git a/mlir/test/Dialect/Arithmetic/invalid.mlir b/mlir/test/Dialect/Arithmetic/invalid.mlir
index 39031603f505..c0e6ebd1947e 100644
--- a/mlir/test/Dialect/Arithmetic/invalid.mlir
+++ b/mlir/test/Dialect/Arithmetic/invalid.mlir
@@ -553,3 +553,163 @@ func @trunci_cast_to_same_width(%arg0 : i16) {
%0 = arith.trunci %arg0 : i16 to i16
return
}
+
+// -----
+
+func @trunci_scalable_to_fl(%arg0 : vector<[4]xi32>) {
+ // expected-error at +1 {{'arith.trunci' op requires the same shape for all operands and results}}
+ %0 = arith.trunci %arg0 : vector<[4]xi32> to vector<4xi8>
+ return
+}
+
+// -----
+
+func @truncf_scalable_to_fl(%arg0 : vector<[4]xf64>) {
+ // expected-error at +1 {{'arith.truncf' op requires the same shape for all operands and results}}
+ %0 = arith.truncf %arg0 : vector<[4]xf64> to vector<4xf32>
+ return
+}
+
+// -----
+
+func @extui_scalable_to_fl(%arg0 : vector<[4]xi32>) {
+ // expected-error at +1 {{'arith.extui' op requires the same shape for all operands and results}}
+ %0 = arith.extui %arg0 : vector<[4]xi32> to vector<4xi64>
+ return
+}
+
+// -----
+
+func @extsi_scalable_to_fl(%arg0 : vector<[4]xi32>) {
+ // expected-error at +1 {{'arith.extsi' op requires the same shape for all operands and results}}
+ %0 = arith.extsi %arg0 : vector<[4]xi32> to vector<4xi64>
+ return
+}
+
+// -----
+
+func @extf_scalable_to_fl(%arg0 : vector<[4]xf32>) {
+ // expected-error at +1 {{'arith.extf' op requires the same shape for all operands and results}}
+ %0 = arith.extf %arg0 : vector<[4]xf32> to vector<4xf64>
+ return
+}
+
+// -----
+
+func @fptoui_scalable_to_fl(%arg0 : vector<[4]xf64>) {
+ // expected-error at +1 {{'arith.fptoui' op requires the same shape for all operands and results}}
+ %0 = arith.fptoui %arg0 : vector<[4]xf64> to vector<4xi32>
+ return
+}
+
+// -----
+
+func @fptosi_scalable_to_fl(%arg0 : vector<[4]xf32>) {
+ // expected-error at +1 {{'arith.fptosi' op requires the same shape for all operands and results}}
+ %0 = arith.fptosi %arg0 : vector<[4]xf32> to vector<4xi32>
+ return
+}
+
+// -----
+
+func @uitofp_scalable_to_fl(%arg0 : vector<[4]xi32>) {
+ // expected-error at +1 {{'arith.uitofp' op requires the same shape for all operands and results}}
+ %0 = arith.uitofp %arg0 : vector<[4]xi32> to vector<4xf32>
+ return
+}
+
+// -----
+
+func @sitofp_scalable_to_fl(%arg0 : vector<[4]xi32>) {
+ // expected-error at +1 {{'arith.sitofp' op requires the same shape for all operands and results}}
+ %0 = arith.sitofp %arg0 : vector<[4]xi32> to vector<4xf32>
+ return
+}
+
+// -----
+
+func @bitcast_scalable_to_fl(%arg0 : vector<[4]xf32>) {
+ // expected-error at +1 {{'arith.bitcast' op requires the same shape for all operands and results}}
+ %0 = arith.bitcast %arg0 : vector<[4]xf32> to vector<4xi32>
+ return
+}
+
+// -----
+
+func @trunci_fl_to_scalable(%arg0 : vector<4xi32>) {
+ // expected-error at +1 {{'arith.trunci' op requires the same shape for all operands and results}}
+ %0 = arith.trunci %arg0 : vector<4xi32> to vector<[4]xi8>
+ return
+}
+
+// -----
+
+func @truncf_fl_to_scalable(%arg0 : vector<4xf64>) {
+ // expected-error at +1 {{'arith.truncf' op requires the same shape for all operands and results}}
+ %0 = arith.truncf %arg0 : vector<4xf64> to vector<[4]xf32>
+ return
+}
+
+// -----
+
+func @extui_fl_to_scalable(%arg0 : vector<4xi32>) {
+ // expected-error at +1 {{'arith.extui' op requires the same shape for all operands and results}}
+ %0 = arith.extui %arg0 : vector<4xi32> to vector<[4]xi64>
+ return
+}
+
+// -----
+
+func @extsi_fl_to_scalable(%arg0 : vector<4xi32>) {
+ // expected-error at +1 {{'arith.extsi' op requires the same shape for all operands and results}}
+ %0 = arith.extsi %arg0 : vector<4xi32> to vector<[4]xi64>
+ return
+}
+
+// -----
+
+func @extf_fl_to_scalable(%arg0 : vector<4xf32>) {
+ // expected-error at +1 {{'arith.extf' op requires the same shape for all operands and results}}
+ %0 = arith.extf %arg0 : vector<4xf32> to vector<[4]xf64>
+ return
+}
+
+// -----
+
+func @fptoui_fl_to_scalable(%arg0 : vector<4xf64>) {
+ // expected-error at +1 {{'arith.fptoui' op requires the same shape for all operands and results}}
+ %0 = arith.fptoui %arg0 : vector<4xf64> to vector<[4]xi32>
+ return
+}
+
+// -----
+
+func @fptosi_fl_to_scalable(%arg0 : vector<4xf32>) {
+ // expected-error at +1 {{'arith.fptosi' op requires the same shape for all operands and results}}
+ %0 = arith.fptosi %arg0 : vector<4xf32> to vector<[4]xi32>
+ return
+}
+
+// -----
+
+func @uitofp_fl_to_scalable(%arg0 : vector<4xi32>) {
+ // expected-error at +1 {{'arith.uitofp' op requires the same shape for all operands and results}}
+ %0 = arith.uitofp %arg0 : vector<4xi32> to vector<[4]xf32>
+ return
+}
+
+// -----
+
+func @sitofp_fl_to_scalable(%arg0 : vector<4xi32>) {
+ // expected-error at +1 {{'arith.sitofp' op requires the same shape for all operands and results}}
+ %0 = arith.sitofp %arg0 : vector<4xi32> to vector<[4]xf32>
+ return
+}
+
+// -----
+
+func @bitcast_fl_to_scalable(%arg0 : vector<4xf32>) {
+ // expected-error at +1 {{'arith.bitcast' op requires the same shape for all operands and results}}
+ %0 = arith.bitcast %arg0 : vector<4xf32> to vector<[4]xi32>
+ return
+}
More information about the Mlir-commits
mailing list