brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · 56a0d4d Raw
218 lines · plain
1// RUN: mlir-opt -split-input-file -convert-math-to-spirv -verify-diagnostics %s -o - | FileCheck %s2 3module attributes { spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Kernel], []>, #spirv.resource_limits<>> } {4 5// CHECK-LABEL: @float32_unary_scalar6func.func @float32_unary_scalar(%arg0: f32) {7  // CHECK: spirv.CL.atan %{{.*}}: f328  %0 = math.atan %arg0 : f329  // CHECK: spirv.CL.cos %{{.*}}: f3210  %1 = math.cos %arg0 : f3211  // CHECK: spirv.CL.exp %{{.*}}: f3212  %2 = math.exp %arg0 : f3213  // CHECK: %[[EXP:.+]] = spirv.CL.exp %arg014  // CHECK: %[[ONE:.+]] = spirv.Constant 1.000000e+00 : f3215  // CHECK: spirv.FSub %[[EXP]], %[[ONE]]16  %3 = math.expm1 %arg0 : f3217  // CHECK: spirv.CL.log %{{.*}}: f3218  %4 = math.log %arg0 : f3219  // CHECK: %[[ONE:.+]] = spirv.Constant 1.000000e+00 : f3220  // CHECK: %[[ADDONE:.+]] = spirv.FAdd %[[ONE]], %{{.+}}21  // CHECK: spirv.CL.log %[[ADDONE]]22  %5 = math.log1p %arg0 : f3223  // CHECK: %[[LOG2_RECIPROCAL:.+]] = spirv.Constant 1.44269502 : f3224  // CHECK: %[[LOG0:.+]] = spirv.CL.log {{.+}}25  // CHECK: spirv.FMul %[[LOG0]], %[[LOG2_RECIPROCAL]]26  %6 = math.log2 %arg0 : f3227  // CHECK: %[[LOG10_RECIPROCAL:.+]] = spirv.Constant 0.434294492 : f3228  // CHECK: %[[LOG1:.+]] = spirv.CL.log {{.+}}29  // CHECK: spirv.FMul %[[LOG1]], %[[LOG10_RECIPROCAL]]30  %7 = math.log10 %arg0 : f3231  // CHECK: spirv.CL.rint %{{.*}}: f3232  %8 = math.roundeven %arg0 : f3233  // CHECK: spirv.CL.rsqrt %{{.*}}: f3234  %9 = math.rsqrt %arg0 : f3235  // CHECK: spirv.CL.sqrt %{{.*}}: f3236  %10 = math.sqrt %arg0 : f3237  // CHECK: spirv.CL.tanh %{{.*}}: f3238  %11 = math.tanh %arg0 : f3239  // CHECK: spirv.CL.sin %{{.*}}: f3240  %12 = math.sin %arg0 : f3241  // CHECK: spirv.CL.fabs %{{.*}}: f3242  %13 = math.absf %arg0 : f3243  // CHECK: spirv.CL.ceil %{{.*}}: f3244  %14 = math.ceil %arg0 : f3245  // CHECK: spirv.CL.floor %{{.*}}: f3246  %15 = math.floor %arg0 : f3247  // CHECK: spirv.CL.erf %{{.*}}: f3248  %16 = math.erf %arg0 : f3249  // CHECK: spirv.CL.round %{{.*}}: f3250  %17 = math.round %arg0 : f3251  // CHECK: spirv.CL.tan %{{.*}}: f3252  %18 = math.tan %arg0 : f3253  // CHECK: spirv.CL.asin %{{.*}}: f3254  %19 = math.asin %arg0 : f3255  // CHECK: spirv.CL.acos %{{.*}}: f3256  %20 = math.acos %arg0 : f3257  // CHECK: spirv.CL.sinh %{{.*}}: f3258  %21 = math.sinh %arg0 : f3259  // CHECK: spirv.CL.cosh %{{.*}}: f3260  %22 = math.cosh %arg0 : f3261  // CHECK: spirv.CL.asinh %{{.*}}: f3262  %23 = math.asinh %arg0 : f3263  // CHECK: spirv.CL.acosh %{{.*}}: f3264  %24 = math.acosh %arg0 : f3265  // CHECK: spirv.CL.atanh %{{.*}}: f3266  %25 = math.atanh %arg0 : f3267  return68}69 70// CHECK-LABEL: @float32_unary_vector71func.func @float32_unary_vector(%arg0: vector<3xf32>) {72  // CHECK: spirv.CL.atan %{{.*}}: vector<3xf32>73  %0 = math.atan %arg0 : vector<3xf32>74  // CHECK: spirv.CL.cos %{{.*}}: vector<3xf32>75  %1 = math.cos %arg0 : vector<3xf32>76  // CHECK: spirv.CL.exp %{{.*}}: vector<3xf32>77  %2 = math.exp %arg0 : vector<3xf32>78  // CHECK: %[[EXP:.+]] = spirv.CL.exp %arg079  // CHECK: %[[ONE:.+]] = spirv.Constant dense<1.000000e+00> : vector<3xf32>80  // CHECK: spirv.FSub %[[EXP]], %[[ONE]]81  %3 = math.expm1 %arg0 : vector<3xf32>82  // CHECK: spirv.CL.log %{{.*}}: vector<3xf32>83  %4 = math.log %arg0 : vector<3xf32>84  // CHECK: %[[ONE:.+]] = spirv.Constant dense<1.000000e+00> : vector<3xf32>85  // CHECK: %[[ADDONE:.+]] = spirv.FAdd %[[ONE]], %{{.+}}86  // CHECK: spirv.CL.log %[[ADDONE]]87  %5 = math.log1p %arg0 : vector<3xf32>88  // CHECK: %[[LOG2_RECIPROCAL:.+]] = spirv.Constant dense<1.44269502> : vector<3xf32>89  // CHECK: %[[LOG0:.+]] = spirv.CL.log {{.+}}90  // CHECK: spirv.FMul %[[LOG0]], %[[LOG2_RECIPROCAL]]91  %6 = math.log2 %arg0 : vector<3xf32>92  // CHECK: %[[LOG10_RECIPROCAL:.+]] = spirv.Constant dense<0.434294492> : vector<3xf32>93  // CHECK: %[[LOG1:.+]] = spirv.CL.log {{.+}}94  // CHECK: spirv.FMul %[[LOG1]], %[[LOG10_RECIPROCAL]]95  %7 = math.log10 %arg0 : vector<3xf32>96  // CHECK: spirv.CL.rint %{{.*}}: vector<3xf32>97  %8 = math.roundeven %arg0 : vector<3xf32>98  // CHECK: spirv.CL.rsqrt %{{.*}}: vector<3xf32>99  %9 = math.rsqrt %arg0 : vector<3xf32>100  // CHECK: spirv.CL.sqrt %{{.*}}: vector<3xf32>101  %10 = math.sqrt %arg0 : vector<3xf32>102  // CHECK: spirv.CL.tanh %{{.*}}: vector<3xf32>103  %11 = math.tanh %arg0 : vector<3xf32>104  // CHECK: spirv.CL.sin %{{.*}}: vector<3xf32>105  %12 = math.sin %arg0 : vector<3xf32>106  // CHECK: spirv.CL.tan %{{.*}}: vector<3xf32>107  %13 = math.tan %arg0 : vector<3xf32>108  // CHECK: spirv.CL.asin %{{.*}}: vector<3xf32>109  %14 = math.asin %arg0 : vector<3xf32>110  // CHECK: spirv.CL.acos %{{.*}}: vector<3xf32>111  %15 = math.acos %arg0 : vector<3xf32>112  // CHECK: spirv.CL.sinh %{{.*}}: vector<3xf32>113  %16 = math.sinh %arg0 : vector<3xf32>114  // CHECK: spirv.CL.cosh %{{.*}}: vector<3xf32>115  %17 = math.cosh %arg0 : vector<3xf32>116  // CHECK: spirv.CL.asinh %{{.*}}: vector<3xf32>117  %18 = math.asinh %arg0 : vector<3xf32>118  // CHECK: spirv.CL.acosh %{{.*}}: vector<3xf32>119  %19 = math.acosh %arg0 : vector<3xf32>120  // CHECK: spirv.CL.atanh %{{.*}}: vector<3xf32>121  %20 = math.atanh %arg0 : vector<3xf32>122  return123}124 125// CHECK-LABEL: @float32_binary_scalar126func.func @float32_binary_scalar(%lhs: f32, %rhs: f32) {127  // CHECK: spirv.CL.atan2 %{{.*}}: f32128  %0 = math.atan2 %lhs, %rhs : f32129  // CHECK: spirv.CL.pow %{{.*}}: f32130  %1 = math.powf %lhs, %rhs : f32131  return132}133 134// CHECK-LABEL: @float32_binary_vector135func.func @float32_binary_vector(%lhs: vector<4xf32>, %rhs: vector<4xf32>) {136  // CHECK: spirv.CL.atan2 %{{.*}}: vector<4xf32>137  %0 = math.atan2 %lhs, %rhs : vector<4xf32>138  // CHECK: spirv.CL.pow %{{.*}}: vector<4xf32>139  %1 = math.powf %lhs, %rhs : vector<4xf32>140  return141}142 143// CHECK-LABEL: @float32_ternary_scalar144func.func @float32_ternary_scalar(%a: f32, %b: f32, %c: f32) {145  // CHECK: spirv.CL.fma %{{.*}}: f32146  %0 = math.fma %a, %b, %c : f32147  return148}149 150// CHECK-LABEL: @float32_ternary_vector151func.func @float32_ternary_vector(%a: vector<4xf32>, %b: vector<4xf32>,152                            %c: vector<4xf32>) {153  // CHECK: spirv.CL.fma %{{.*}}: vector<4xf32>154  %0 = math.fma %a, %b, %c : vector<4xf32>155  return156}157 158// CHECK-LABEL: @int_unary159func.func @int_unary(%arg0: i32) {160  // CHECK: spirv.CL.s_abs %{{.*}}161  %0 = math.absi %arg0 : i32162  return163}164 165} // end module166 167// -----168 169module attributes {170  spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader], []>, #spirv.resource_limits<>>171} {172 173// 2-D vectors are not supported.174 175// CHECK-LABEL: @vector_2d176func.func @vector_2d(%arg0: vector<2x2xf32>) {177  // CHECK-NEXT: math.atan {{.+}} : vector<2x2xf32>178  %0 = math.atan %arg0 : vector<2x2xf32>179  // CHECK-NEXT: math.cos {{.+}} : vector<2x2xf32>180  %1 = math.cos %arg0 : vector<2x2xf32>181  // CHECK-NEXT: math.exp {{.+}} : vector<2x2xf32>182  %2 = math.exp %arg0 : vector<2x2xf32>183  // CHECK-NEXT: math.absf {{.+}} : vector<2x2xf32>184  %3 = math.absf %arg0 : vector<2x2xf32>185  // CHECK-NEXT: math.ceil {{.+}} : vector<2x2xf32>186  %4 = math.ceil %arg0 : vector<2x2xf32>187  // CHECK-NEXT: math.floor {{.+}} : vector<2x2xf32>188  %5 = math.floor %arg0 : vector<2x2xf32>189  // CHECK-NEXT: math.powf {{.+}}, {{%.+}} : vector<2x2xf32>190  %6 = math.powf %arg0, %arg0 : vector<2x2xf32>191  // CHECK-NEXT: return192  return193}194 195// Tensors are not supported.196 197// CHECK-LABEL: @tensor_1d198func.func @tensor_1d(%arg0: tensor<2xf32>) {199  // CHECK-NEXT: math.atan {{.+}} : tensor<2xf32>200  %0 = math.atan %arg0 : tensor<2xf32>201  // CHECK-NEXT: math.cos {{.+}} : tensor<2xf32>202  %1 = math.cos %arg0 : tensor<2xf32>203  // CHECK-NEXT: math.exp {{.+}} : tensor<2xf32>204  %2 = math.exp %arg0 : tensor<2xf32>205  // CHECK-NEXT: math.absf {{.+}} : tensor<2xf32>206  %3 = math.absf %arg0 : tensor<2xf32>207  // CHECK-NEXT: math.ceil {{.+}} : tensor<2xf32>208  %4 = math.ceil %arg0 : tensor<2xf32>209  // CHECK-NEXT: math.floor {{.+}} : tensor<2xf32>210  %5 = math.floor %arg0 : tensor<2xf32>211  // CHECK-NEXT: math.powf {{.+}}, {{%.+}} : tensor<2xf32>212  %6 = math.powf %arg0, %arg0 : tensor<2xf32>213  // CHECK-NEXT: return214  return215}216 217} // end module218