|
3 | 3 | // RUN: mlir-opt %s -convert-math-to-xevm='convert-arith=false' \ |
4 | 4 | // RUN: | FileCheck %s -check-prefixes='CHECK,CHECK-NO-ARITH' |
5 | 5 |
|
| 6 | +// RUN: mlir-opt --pass-pipeline="builtin.module(convert-math-to-xevm)" %s \ |
| 7 | +// RUN: | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ENTIRE-MODULE' |
| 8 | +// RUN: mlir-opt --pass-pipeline="builtin.module(gpu.module(convert-math-to-xevm))" %s \ |
| 9 | +// RUN: | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ONLY-GPU' |
| 10 | + |
| 11 | +// This test: |
| 12 | +// - check that MathToXeVM converts fastmath math/arith ops properly; |
| 13 | +// - check that MathToXeVM handles nested modules while respecting pass manager. |
| 14 | + |
6 | 15 | module @test_module { |
7 | 16 | // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDh(f16) -> f16 |
8 | 17 | // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32 |
@@ -152,4 +161,39 @@ module @test_module { |
152 | 161 |
|
153 | 162 | return |
154 | 163 | } |
| 164 | + |
| 165 | + // Check that MathToXeVM handles nested modules while respecting pass manager: |
| 166 | + |
| 167 | + // CHECK-ENTIRE-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32 |
| 168 | + // CHECK-ONLY-GPU-NOT: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32 |
| 169 | + |
| 170 | + // CHECK-MODULE-LABEL: @test_gpu |
| 171 | + gpu.module @test_gpu { |
| 172 | + // CHECK-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32 |
| 173 | + gpu.func @exp_gpu() { |
| 174 | + %c1_f32 = arith.constant 1. : f32 |
| 175 | + |
| 176 | + // CHECK-MODULE: math.exp |
| 177 | + %exp_normal_f32 = math.exp %c1_f32 : f32 |
| 178 | + |
| 179 | + // CHECK-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32 |
| 180 | + %exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32 |
| 181 | + |
| 182 | + gpu.return |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + // CHECK-MODULE-LABEL: @exp_func |
| 187 | + func.func @exp_func() { |
| 188 | + %c1_f32 = arith.constant 1. : f32 |
| 189 | + |
| 190 | + // CHECK-MODULE: math.exp |
| 191 | + %exp_normal_f32 = math.exp %c1_f32 : f32 |
| 192 | + |
| 193 | + // CHECK-ENTIRE-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32 |
| 194 | + // CHECK-ONLY-GPU: math.exp |
| 195 | + %exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32 |
| 196 | + |
| 197 | + return |
| 198 | + } |
155 | 199 | } |
0 commit comments