59 lines · plain
1// RUN: mlir-opt --split-input-file %s \2// RUN: --pass-pipeline='builtin.module(func.func(convert-arith-to-amdgpu{chipset=gfx950 saturate-fp8-truncf=true}))' \3// RUN: | FileCheck %s4 5// RUN: mlir-opt --split-input-file %s \6// RUN: --pass-pipeline='builtin.module(func.func(convert-arith-to-amdgpu{chipset=gfx1200 saturate-fp8-truncf=true}))' \7// RUN: | FileCheck %s8 9// CHECK-LABEL: func.func @scalar_trunc10// CHECK-SAME: ([[V:%.+]]: f16)11// CHECK-DAG: [[CMin:%.+]] = arith.constant -5.734400e+04 : f1612// CHECK-DAG: [[CMax:%.+]] = arith.constant 5.734400e+04 : f1613// CHECK-DAG: [[CInf:%.+]] = arith.constant 0x7C00 : f1614// CHECK-DAG: [[CNegInf:%.+]] = arith.constant 0xFC00 : f1615// CHECK: [[ISINF:%.+]] = arith.cmpf oeq, [[V]], [[CInf]]16// CHECK: [[ISNEGINF:%.+]] = arith.cmpf oeq, [[V]], [[CNegInf]]17// CHECK: [[ISNAN:%.+]] = arith.cmpf uno, [[V]], [[V]]18// CHECK: [[ISNONFINITE_1:%.+]] = arith.ori [[ISINF]], [[ISNEGINF]]19// CHECK: [[ISNONFINITE:%.+]] = arith.ori [[ISNONFINITE_1]], [[ISNAN]]20// CHECK: [[CLAMPEDBELOW:%.+]] = arith.maximumf [[V]], [[CMin]]21// CHECK: [[CLAMPED:%.+]] = arith.minimumf [[CLAMPEDBELOW]], [[CMax]]22// CHECK: [[SATURATED:%.+]] = arith.select [[ISNONFINITE]], [[V]], [[CLAMPED]]23// CHECK: [[FLOAT:%.+]] = arith.extf [[SATURATED]] : f16 to f3224// CHECK: [[TRUNCV:%.+]] = amdgpu.packed_trunc_2xfp8 [[FLOAT]], undef into undef[word 0] : f32 to vector<4xf8E5M2>25// CHECK: [[W:%.+]] = vector.extract [[TRUNCV]][0] : f8E5M2 from vector<4xf8E5M2>26// CHECK: return [[W]] : f8E5M227func.func @scalar_trunc(%v: f16) -> f8E5M2 {28 %w = arith.truncf %v : f16 to f8E5M229 return %w : f8E5M230}31 32// No 0-D test because arith.truncf hasn't been extended to support it.33 34// -----35 36// CHECK-LABEL: func.func @vector_trunc37// CHECK-SAME: ([[V:%.+]]: vector<2xf32>) -> vector<2xf8E4M3FN> {38// CHECK-DAG: [[CMin:%.+]] = arith.constant dense<-4.480000e+02> : vector<2xf32>39// CHECK-DAG: [[CMax:%.+]] = arith.constant dense<4.480000e+02> : vector<2xf32>40// CHECK-DAG: [[CInf:%.+]] = arith.constant dense<0x7F800000> : vector<2xf32>41// CHECK-DAG: [[CNegInf:%.+]] = arith.constant dense<0xFF800000> : vector<2xf32>42// CHECK: [[ISINF:%.+]] = arith.cmpf oeq, [[V]], [[CInf]]43// CHECK: [[ISNEGINF:%.+]] = arith.cmpf oeq, [[V]], [[CNegInf]]44// CHECK: [[ISNAN:%.+]] = arith.cmpf uno, [[V]], [[V]]45// CHECK: [[ISNONFINITE_1:%.+]] = arith.ori [[ISINF]], [[ISNEGINF]]46// CHECK: [[ISNONFINITE:%.+]] = arith.ori [[ISNONFINITE_1]], [[ISNAN]]47// CHECK: [[CLAMPEDBELOW:%.+]] = arith.maximumf [[V]], [[CMin]]48// CHECK: [[CLAMPED:%.+]] = arith.minimumf [[CLAMPEDBELOW]], [[CMax]]49// CHECK: [[SATURATED:%.+]] = arith.select [[ISNONFINITE]], [[V]], [[CLAMPED]]50// CHECK: [[F0:%.+]] = vector.extract [[SATURATED]][0]51// CHECK: [[F1:%.+]] = vector.extract [[SATURATED]][1]52// CHECK: [[W0:%.+]] = amdgpu.packed_trunc_2xfp8 [[F0]], [[F1]] into undef[word 0] : f32 to vector<4xf8E4M3FN>53// CHECK: [[W:%.+]] = vector.extract_strided_slice [[W0]] {offsets = [0], sizes = [2], strides = [1]} : vector<4xf8E4M3FN> to vector<2xf8E4M3FN>54// CHECK: return [[W]] : vector<2xf8E4M3FN>55func.func @vector_trunc_short(%v: vector<2xf32>) -> vector<2xf8E4M3FN> {56 %w = arith.truncf %v : vector<2xf32> to vector<2xf8E4M3FN>57 return %w : vector<2xf8E4M3FN>58}59