1// RUN: mlir-opt -split-input-file -convert-arith-to-spirv -verify-diagnostics %s 2 3///===----------------------------------------------------------------------===// 4// Cast ops 5//===----------------------------------------------------------------------===// 6 7module attributes { 8 spirv.target_env = #spirv.target_env< 9 #spirv.vce<v1.0, [Float16, Kernel], []>, #spirv.resource_limits<>> 10} { 11 12func.func @experimental_constrained_fptrunc(%arg0 : f32) { 13 // expected-error@+1 {{failed to legalize operation 'arith.truncf'}} 14 %3 = arith.truncf %arg0 to_nearest_away : f32 to f16 15 return 16} 17 18} // end module 19 20///===----------------------------------------------------------------------===// 21// Binary ops 22//===----------------------------------------------------------------------===// 23 24// ----- 25 26module attributes { 27 spirv.target_env = #spirv.target_env< 28 #spirv.vce<v1.0, [Int8, Int16, Int64, Float16, Float64, Shader], []>, #spirv.resource_limits<>> 29} { 30 31func.func @unsupported_5elem_vector(%arg0: vector<5xi32>) { 32 // expected-error@+1 {{failed to legalize operation 'arith.subi'}} 33 %1 = arith.subi %arg0, %arg0: vector<5xi32> 34 return 35} 36 37} // end module 38 39// ----- 40 41module attributes { 42 spirv.target_env = #spirv.target_env< 43 #spirv.vce<v1.0, [Int8, Int16, Int64, Float16, Float64, Shader], []>, #spirv.resource_limits<>> 44} { 45 46func.func @unsupported_2x2elem_vector(%arg0: vector<2x2xi32>) { 47 // expected-error@+1 {{failed to legalize operation 'arith.muli'}} 48 %2 = arith.muli %arg0, %arg0: vector<2x2xi32> 49 return 50} 51 52} // end module 53 54// ----- 55 56func.func @int_vector4_invalid(%arg0: vector<2xi16>) { 57 // expected-error @+2 {{failed to legalize operation 'arith.divui'}} 58 // expected-error @+1 {{bitwidth emulation is not implemented yet on unsigned op}} 59 %0 = arith.divui %arg0, %arg0: vector<2xi16> 60 return 61} 62 63// ----- 64 65func.func @int_vector_invalid_bitwidth(%arg0: vector<2xi12>) { 66 // expected-error @+1 {{failed to legalize operation 'arith.addi'}} 67 %0 = arith.addi %arg0, %arg0: vector<2xi12> 68 return 69} 70 71///===----------------------------------------------------------------------===// 72// Constant ops 73//===----------------------------------------------------------------------===// 74 75// ----- 76 77func.func @unsupported_constant_i64_0() { 78 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 79 %0 = arith.constant 0 : i64 80 return 81} 82 83// ----- 84 85func.func @unsupported_constant_i64_1() { 86 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 87 %0 = arith.constant 4294967296 : i64 // 2^32 88 return 89} 90 91// ----- 92 93func.func @unsupported_constant_vector_2xi64_0() { 94 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 95 %1 = arith.constant dense<0> : vector<2xi64> 96 return 97} 98 99// ----- 100 101func.func @unsupported_constant_f64_0() { 102 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 103 %1 = arith.constant 0.0 : f64 104 return 105} 106 107// ----- 108 109func.func @unsupported_constant_vector_2xf64_0() { 110 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 111 %1 = arith.constant dense<0.0> : vector<2xf64> 112 return 113} 114 115// ----- 116 117func.func @unsupported_constant_tensor_2xf64_0() { 118 // expected-error @+1 {{failed to legalize operation 'arith.constant'}} 119 %1 = arith.constant dense<0.0> : tensor<2xf64> 120 return 121} 122 123// ----- 124 125func.func @constant_dense_resource_non_existant() { 126 // expected-error @+2 {{failed to legalize operation 'arith.constant'}} 127 // expected-error @+1 {{could not find resource blob}} 128 %0 = arith.constant dense_resource<non_existant> : tensor<5xf32> 129 return 130} 131 132// ----- 133 134module { 135func.func @constant_dense_resource_invalid_buffer() { 136 // expected-error @+2 {{failed to legalize operation 'arith.constant'}} 137 // expected-error @+1 {{resource is not a valid buffer}} 138 %0 = arith.constant dense_resource<dense_resource_test_2xi32> : vector<2xi32> 139 return 140 } 141} 142// This is a buffer of wrong type and shape 143{-# 144 dialect_resources: { 145 builtin: { 146 dense_resource_test_2xi32: "0x0800000054A3B53ED6C0B33E55D1A2BDE5D2BB3E" 147 } 148 } 149#-} 150 151///===----------------------------------------------------------------------===// 152// Type emulation 153//===----------------------------------------------------------------------===// 154 155// ----- 156 157module attributes { 158 spirv.target_env = #spirv.target_env< 159 #spirv.vce<v1.0, [], []>, #spirv.resource_limits<>> 160} { 161 162// Check that we do not emualte i64 by truncating to i32. 163func.func @unsupported_i64(%arg0: i64) { 164 // expected-error@+1 {{failed to legalize operation 'arith.addi'}} 165 %2 = arith.addi %arg0, %arg0: i64 166 return 167} 168 169} // end module 170 171// ----- 172 173module attributes { 174 spirv.target_env = #spirv.target_env< 175 #spirv.vce<v1.0, [], []>, #spirv.resource_limits<>> 176} { 177 178// Check that we do not emualte f64 by truncating to i32. 179func.func @unsupported_f64(%arg0: f64) { 180 // expected-error@+1 {{failed to legalize operation 'arith.addf'}} 181 %2 = arith.addf %arg0, %arg0: f64 182 return 183} 184 185} // end module 186 187// ----- 188 189module attributes { 190 spirv.target_env = #spirv.target_env< 191 #spirv.vce<v1.0, [], []>, #spirv.resource_limits<>> 192} { 193 194// i64 is not a valid result type in this target env. 195func.func @type_conversion_failure(%arg0: i32) { 196 // expected-error@+1 {{failed to legalize operation 'arith.extsi'}} 197 %2 = arith.extsi %arg0 : i32 to i64 198 return 199} 200 201} // end module 202