Files
TheRock/compiler/amd-llvm/mlir/test/mlir-runner/expand-arith-ops.mlir
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

87 lines
3.4 KiB
MLIR

// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(arith-expand{include-bf16=true},convert-arith-to-llvm),convert-vector-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \
// RUN: | mlir-runner \
// RUN: -e main -entry-point-result=void -O0 \
// RUN: -shared-libs=%mlir_c_runner_utils \
// RUN: -shared-libs=%mlir_runner_utils \
// RUN: | FileCheck %s
// XFAIL: system-aix
func.func @trunc_bf16(%a : f32) {
%b = arith.truncf %a : f32 to bf16
%c = arith.extf %b : bf16 to f32
vector.print %c : f32
return
}
func.func @main() {
// Note: this is a tie (low 16 bits are 0x8000). We expect the rounding behavior
// to break ties "to nearest-even", which in this case means downwards,
// since bit 16 is not set.
// CHECK: 1
%value_1_00391_I = arith.constant 0x3f808000 : i32
%value_1_00391_F = arith.bitcast %value_1_00391_I : i32 to f32
call @trunc_bf16(%value_1_00391_F): (f32) -> ()
// Note: this is a tie (low 16 bits are 0x8000). We expect the rounding behavior
// to break ties "to nearest-even", which in this case means upwards,
// since bit 16 is set.
// CHECK-NEXT: 1.0156
%value_1_01172_I = arith.constant 0x3f818000 : i32
%value_1_01172_F = arith.bitcast %value_1_01172_I : i32 to f32
call @trunc_bf16(%value_1_01172_F): (f32) -> ()
// CHECK-NEXT: -1
%noRoundNegOneI = arith.constant 0xbf808000 : i32
%noRoundNegOneF = arith.bitcast %noRoundNegOneI : i32 to f32
call @trunc_bf16(%noRoundNegOneF): (f32) -> ()
// CHECK-NEXT: -1.00781
%roundNegOneI = arith.constant 0xbf808001 : i32
%roundNegOneF = arith.bitcast %roundNegOneI : i32 to f32
call @trunc_bf16(%roundNegOneF): (f32) -> ()
// CHECK-NEXT: inf
%infi = arith.constant 0x7f800000 : i32
%inff = arith.bitcast %infi : i32 to f32
call @trunc_bf16(%inff): (f32) -> ()
// CHECK-NEXT: -inf
%neginfi = arith.constant 0xff800000 : i32
%neginff = arith.bitcast %neginfi : i32 to f32
call @trunc_bf16(%neginff): (f32) -> ()
// Note: this rounds upwards. As the mantissa was already saturated, this rounding
// causes the exponent to be incremented. As the exponent was already the
// maximum exponent value for finite values, this increment of the exponent
// causes this to overflow to +inf.
// CHECK-NEXT: inf
%big_overflowing_i = arith.constant 0x7f7fffff : i32
%big_overflowing_f = arith.bitcast %big_overflowing_i : i32 to f32
call @trunc_bf16(%big_overflowing_f): (f32) -> ()
// Same as the previous testcase but negative.
// CHECK-NEXT: -inf
%negbig_overflowing_i = arith.constant 0xff7fffff : i32
%negbig_overflowing_f = arith.bitcast %negbig_overflowing_i : i32 to f32
call @trunc_bf16(%negbig_overflowing_f): (f32) -> ()
// In contrast to the previous two testcases, the upwards-rounding here
// does not cause overflow.
// CHECK-NEXT: 3.38953e+38
%big_nonoverflowing_i = arith.constant 0x7f7effff : i32
%big_nonoverflowing_f = arith.bitcast %big_nonoverflowing_i : i32 to f32
call @trunc_bf16(%big_nonoverflowing_f): (f32) -> ()
// CHECK-NEXT: 1.625
%exprolli = arith.constant 0x3fcfffff : i32
%exprollf = arith.bitcast %exprolli : i32 to f32
call @trunc_bf16(%exprollf): (f32) -> ()
// CHECK-NEXT: -1.625
%exprollnegi = arith.constant 0xbfcfffff : i32
%exprollnegf = arith.bitcast %exprollnegi : i32 to f32
call @trunc_bf16(%exprollnegf): (f32) -> ()
return
}