brintos

brintos / llvm-project-archived public Read only

0
0
Text · 26.0 KiB · 8f9b0fe Raw
636 lines · plain
1// RUN: mlir-opt %s -arith-expand="include-bf16=true include-f8e8m0=true include-f4e2m1=true" -verify-diagnostics -split-input-file | FileCheck %s2// RUN: mlir-opt %s -arith-expand -split-input-file -verify-diagnostics | FileCheck %s --check-prefix=SCHECK3 4// Test ceil divide with signed integer5// CHECK-LABEL:       func @ceildivi6// CHECK-SAME:     ([[ARG0:%.+]]: i32, [[ARG1:%.+]]: i32) -> i32 {7func.func @ceildivi(%arg0: i32, %arg1: i32) -> (i32) {8  %res = arith.ceildivsi %arg0, %arg1 : i329  return %res : i3210 11// CHECK:           [[ZERO:%.+]] = arith.constant 0 : i3212// CHECK:           [[ONE:%.+]] = arith.constant 1 : i3213// CHECK:           [[DIV:%.+]] = arith.divsi %arg0, %arg1 : i3214// CHECK:           [[MUL:%.+]] = arith.muli [[DIV]], %arg1 : i3215// CHECK:           [[NEXACT:%.+]] = arith.cmpi ne, %arg0, [[MUL]] : i3216// CHECK:           [[NNEG:%.+]] = arith.cmpi slt, %arg0, [[ZERO]] : i3217// CHECK:           [[MNEG:%.+]] = arith.cmpi slt, %arg1, [[ZERO]] : i3218// CHECK:           [[SAMESIGN:%.+]] = arith.cmpi eq, [[NNEG]], [[MNEG]] : i119// CHECK:           [[SHOULDROUND:%.+]] = arith.andi [[NEXACT]], [[SAMESIGN]] : i120// CHECK:           [[CEIL:%.+]] = arith.addi [[DIV]], [[ONE]] : i3221// CHECK:           [[RES:%.+]] = arith.select [[SHOULDROUND]], [[CEIL]], [[DIV]] : i3222}23 24// -----25 26// Test ceil divide with index type27// CHECK-LABEL:       func @ceildivi_index28// CHECK-SAME:     ([[ARG0:%.+]]: index, [[ARG1:%.+]]: index) -> index {29func.func @ceildivi_index(%arg0: index, %arg1: index) -> (index) {30  %res = arith.ceildivsi %arg0, %arg1 : index31  return %res : index32 33// CHECK:           [[ZERO:%.+]] = arith.constant 0 : index34// CHECK:           [[ONE:%.+]] = arith.constant 1 : index35// CHECK:           [[DIV:%.+]] = arith.divsi %arg0, %arg1 : index36// CHECK:           [[MUL:%.+]] = arith.muli [[DIV]], %arg1 : index37// CHECK:           [[NEXACT:%.+]] = arith.cmpi ne, %arg0, [[MUL]] : index38// CHECK:           [[NNEG:%.+]] = arith.cmpi slt, %arg0, [[ZERO]] : index39// CHECK:           [[MNEG:%.+]] = arith.cmpi slt, %arg1, [[ZERO]] : index40// CHECK:           [[SAMESIGN:%.+]] = arith.cmpi eq, [[NNEG]], [[MNEG]] : i141// CHECK:           [[SHOULDROUND:%.+]] = arith.andi [[NEXACT]], [[SAMESIGN]] : i142// CHECK:           [[CEIL:%.+]] = arith.addi [[DIV]], [[ONE]] : index43// CHECK:           [[RES:%.+]] = arith.select [[SHOULDROUND]], [[CEIL]], [[DIV]] : index44 45}46 47// -----48 49// Test floor divide with signed integer50// CHECK-LABEL:       func @floordivi51// CHECK-SAME:     ([[ARG0:%.+]]: i32, [[ARG1:%.+]]: i32) -> i32 {52func.func @floordivi(%arg0: i32, %arg1: i32) -> (i32) {53  %res = arith.floordivsi %arg0, %arg1 : i3254  return %res : i3255// CHECK:   %[[QUOTIENT:.*]] = arith.divsi %arg0, %arg1 : i3256// CHECK:   %[[PRODUCT:.*]] = arith.muli %[[QUOTIENT]], %arg1 : i3257// CHECK:   %[[NOT_EQ_PRODUCT:.*]] = arith.cmpi ne, %arg0, %[[PRODUCT]] : i3258// CHECK-DAG:   %[[ZERO:.*]] = arith.constant 0 : i3259// CHECK:   %[[NEG_DIVISOR:.*]] = arith.cmpi slt, %arg0, %[[ZERO]] : i3260// CHECK:   %[[NEG_DIVIDEND:.*]] = arith.cmpi slt, %arg1, %[[ZERO]] : i3261// CHECK:   %[[OPPOSITE_SIGN:.*]] = arith.cmpi ne, %[[NEG_DIVISOR]], %[[NEG_DIVIDEND]] : i162// CHECK:   %[[CONDITION:.*]] = arith.andi %[[NOT_EQ_PRODUCT]], %[[OPPOSITE_SIGN]] : i163// CHECK-DAG:   %[[NEG_ONE:.*]] = arith.constant -1 : i3264// CHECK:   %[[MINUS_ONE:.*]] = arith.addi %[[QUOTIENT]], %[[NEG_ONE]] : i3265// CHECK:   %[[RES:.*]] = arith.select %[[CONDITION]], %[[MINUS_ONE]], %[[QUOTIENT]] : i3266}67 68// -----69 70// Test floor divide with index type71// CHECK-LABEL:       func @floordivi_index72// CHECK-SAME:     ([[ARG0:%.+]]: index, [[ARG1:%.+]]: index) -> index {73func.func @floordivi_index(%arg0: index, %arg1: index) -> (index) {74  %res = arith.floordivsi %arg0, %arg1 : index75  return %res : index76// CHECK:   %[[QUOTIENT:.*]] = arith.divsi %arg0, %arg1 : index77// CHECK:   %[[PRODUCT:.*]] = arith.muli %[[QUOTIENT]], %arg1 : index78// CHECK:   %[[NOT_EQ_PRODUCT:.*]] = arith.cmpi ne, %arg0, %[[PRODUCT]] : index79// CHECK-DAG:   %[[ZERO:.*]] = arith.constant 0 : index80// CHECK:   %[[NEG_DIVISOR:.*]] = arith.cmpi slt, %arg0, %[[ZERO]] : index81// CHECK:   %[[NEG_DIVIDEND:.*]] = arith.cmpi slt, %arg1, %[[ZERO]] : index82// CHECK:   %[[OPPOSITE_SIGN:.*]] = arith.cmpi ne, %[[NEG_DIVISOR]], %[[NEG_DIVIDEND]] : i183// CHECK:   %[[CONDITION:.*]] = arith.andi %[[NOT_EQ_PRODUCT]], %[[OPPOSITE_SIGN]] : i184// CHECK:   %[[NEG_ONE:.*]] = arith.constant -1 : index85// CHECK-DAG:   %[[MINUS_ONE:.*]] = arith.addi %[[QUOTIENT]], %[[NEG_ONE]] : index86// CHECK:   %[[RES:.*]] = arith.select %[[CONDITION]], %[[MINUS_ONE]], %[[QUOTIENT]] : index87}88 89// -----90 91// Test floor divide with vector92// CHECK-LABEL:   func.func @floordivi_vec(93// CHECK-SAME:                             %[[VAL_0:.*]]: vector<4xi32>,94// CHECK-SAME:                             %[[VAL_1:.*]]: vector<4xi32>) -> vector<4xi32> {95func.func @floordivi_vec(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> (vector<4xi32>) {96  %res = arith.floordivsi %arg0, %arg1 : vector<4xi32>97  return %res : vector<4xi32>98// CHECK:   %[[QUOTIENT:.*]] = arith.divsi %arg0, %arg1 : vector<4xi32>99// CHECK:   %[[PRODUCT:.*]] = arith.muli %[[QUOTIENT]], %arg1 : vector<4xi32>100// CHECK:   %[[NOT_EQ_PRODUCT:.*]] = arith.cmpi ne, %arg0, %[[PRODUCT]] : vector<4xi32>101// CHECK-DAG:   %[[ZERO:.*]] = arith.constant dense<0> : vector<4xi32>102// CHECK:   %[[NEG_DIVISOR:.*]] = arith.cmpi slt, %arg0, %[[ZERO]] : vector<4xi32>103// CHECK:   %[[NEG_DIVIDEND:.*]] = arith.cmpi slt, %arg1, %[[ZERO]] : vector<4xi32>104// CHECK:   %[[OPPOSITE_SIGN:.*]] = arith.cmpi ne, %[[NEG_DIVISOR]], %[[NEG_DIVIDEND]] : vector<4xi1>105// CHECK:   %[[CONDITION:.*]] = arith.andi %[[NOT_EQ_PRODUCT]], %[[OPPOSITE_SIGN]] : vector<4xi1>106// CHECK-DAG:   %[[NEG_ONE:.*]] = arith.constant dense<-1> : vector<4xi32>107// CHECK:   %[[MINUS_ONE:.*]] = arith.addi %[[QUOTIENT]], %[[NEG_ONE]] : vector<4xi32>108// CHECK:   %[[RES:.*]] = arith.select %[[CONDITION]], %[[MINUS_ONE]], %[[QUOTIENT]] : vector<4xi1>, vector<4xi32>109}110 111// -----112 113// Test ceil divide with unsigned integer114// CHECK-LABEL:       func @ceildivui115// CHECK-SAME:     ([[ARG0:%.+]]: i32, [[ARG1:%.+]]: i32) -> i32 {116func.func @ceildivui(%arg0: i32, %arg1: i32) -> (i32) {117  %res = arith.ceildivui %arg0, %arg1 : i32118  return %res : i32119// CHECK:           [[ZERO:%.+]] = arith.constant 0 : i32120// CHECK:           [[ISZERO:%.+]] = arith.cmpi eq, %arg0, [[ZERO]] : i32121// CHECK:           [[ONE:%.+]] = arith.constant 1 : i32122// CHECK:           [[SUB:%.+]] = arith.subi %arg0, [[ONE]] : i32123// CHECK:           [[DIV:%.+]] = arith.divui [[SUB]], %arg1 : i32124// CHECK:           [[REM:%.+]] = arith.addi [[DIV]], [[ONE]] : i32125// CHECK:           [[RES:%.+]] = arith.select [[ISZERO]], [[ZERO]], [[REM]] : i32126}127 128// -----129 130// Test unsigned ceil divide with index131// CHECK-LABEL:       func @ceildivui_index132// CHECK-SAME:     ([[ARG0:%.+]]: index, [[ARG1:%.+]]: index) -> index {133func.func @ceildivui_index(%arg0: index, %arg1: index) -> (index) {134  %res = arith.ceildivui %arg0, %arg1 : index135  return %res : index136// CHECK:           [[ZERO:%.+]] = arith.constant 0 : index137// CHECK:           [[ISZERO:%.+]] = arith.cmpi eq, %arg0, [[ZERO]] : index138// CHECK:           [[ONE:%.+]] = arith.constant 1 : index139// CHECK:           [[SUB:%.+]] = arith.subi %arg0, [[ONE]] : index140// CHECK:           [[DIV:%.+]] = arith.divui [[SUB]], %arg1 : index141// CHECK:           [[REM:%.+]] = arith.addi [[DIV]], [[ONE]] : index142// CHECK:           [[RES:%.+]] = arith.select [[ISZERO]], [[ZERO]], [[REM]] : index143}144 145// -----146 147// CHECK-LABEL: func @maximumf148func.func @maximumf(%a: f32, %b: f32) -> f32 {149  %result = arith.maximumf %a, %b : f32150  return %result : f32151}152// CHECK-SAME: %[[LHS:.*]]: f32, %[[RHS:.*]]: f32)153// CHECK-NEXT: %[[CMP:.*]] = arith.cmpf ugt, %[[LHS]], %[[RHS]] : f32154// CHECK-NEXT: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : f32155// CHECK-NEXT: %[[IS_NAN:.*]] = arith.cmpf uno, %[[RHS]], %[[RHS]] : f32156// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[IS_NAN]], %[[RHS]], %[[SELECT]] : f32157// CHECK-NEXT: return %[[RESULT]] : f32158 159// -----160 161// CHECK-LABEL: func @maximumf_vector162func.func @maximumf_vector(%a: vector<4xf16>, %b: vector<4xf16>) -> vector<4xf16> {163  %result = arith.maximumf %a, %b : vector<4xf16>164  return %result : vector<4xf16>165}166// CHECK-SAME: %[[LHS:.*]]: vector<4xf16>, %[[RHS:.*]]: vector<4xf16>)167// CHECK-NEXT: %[[CMP:.*]] = arith.cmpf ugt, %[[LHS]], %[[RHS]] : vector<4xf16>168// CHECK-NEXT: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]]169// CHECK-NEXT: %[[IS_NAN:.*]] = arith.cmpf uno, %[[RHS]], %[[RHS]] : vector<4xf16>170// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[IS_NAN]], %[[RHS]], %[[SELECT]]171// CHECK-NEXT: return %[[RESULT]] : vector<4xf16>172 173// -----174 175// CHECK-LABEL: func @maxnumf176func.func @maxnumf(%a: f32, %b: f32) -> f32 {177  %result = arith.maxnumf %a, %b : f32178  return %result : f32179}180 181// CHECK-SAME: %[[LHS:.*]]: f32, %[[RHS:.*]]: f32)182// CHECK-NEXT: %[[CMP:.*]] = arith.cmpf ugt, %[[LHS]], %[[RHS]] : f32183// CHECK-NEXT: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : f32184// CHECK-NEXT: %[[IS_NAN:.*]] = arith.cmpf uno, %[[LHS]], %[[LHS]] : f32185// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[IS_NAN]], %[[RHS]], %[[SELECT]] : f32186// CHECK-NEXT: return %[[RESULT]] : f32187 188// -----189 190// CHECK-LABEL: func @minimumf191func.func @minimumf(%a: f32, %b: f32) -> f32 {192  %result = arith.minimumf %a, %b : f32193  return %result : f32194}195 196// CHECK-SAME: %[[LHS:.*]]: f32, %[[RHS:.*]]: f32)197// CHECK-NEXT: %[[CMP:.*]] = arith.cmpf ult, %[[LHS]], %[[RHS]] : f32198// CHECK-NEXT: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : f32199// CHECK-NEXT: %[[IS_NAN:.*]] = arith.cmpf uno, %[[RHS]], %[[RHS]] : f32200// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[IS_NAN]], %[[RHS]], %[[SELECT]] : f32201// CHECK-NEXT: return %[[RESULT]] : f32202 203// -----204 205// CHECK-LABEL: func @minnumf206func.func @minnumf(%a: f32, %b: f32) -> f32 {207  %result = arith.minnumf %a, %b : f32208  return %result : f32209}210 211// CHECK-SAME: %[[LHS:.*]]: f32, %[[RHS:.*]]: f32)212// CHECK-NEXT: %[[CMP:.*]] = arith.cmpf ult, %[[LHS]], %[[RHS]] : f32213// CHECK-NEXT: %[[SELECT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : f32214// CHECK-NEXT: %[[IS_NAN:.*]] = arith.cmpf uno, %[[LHS]], %[[LHS]] : f32215// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[IS_NAN]], %[[RHS]], %[[SELECT]] : f32216// CHECK-NEXT: return %[[RESULT]] : f32217 218// -----219 220func.func @truncf_f32(%arg0 : f32) -> bf16 {221    %0 = arith.truncf %arg0 : f32 to bf16222    return %0 : bf16223}224 225// CHECK-LABEL: @truncf_f32226// CHECK-DAG: %[[C1:.+]] = arith.constant 1 : i32227// CHECK-DAG: %[[C16:.+]] = arith.constant 16 : i32228// CHECK-DAG: %[[C7FC0_i16:.+]] = arith.constant 32704 : i16229// CHECK-DAG: %[[C7FFF:.+]] = arith.constant 32767 : i32230// CHECK-DAG: %[[ISNAN:.+]] = arith.cmpf une, %arg0, %arg0 : f32231// CHECK-DAG: %[[BITCAST:.+]] = arith.bitcast %arg0 : f32 to i32232// CHECK-DAG: %[[SHRUI:.+]] = arith.shrui %[[BITCAST]], %[[C16]] : i32233// CHECK-DAG: %[[BIT16:.+]] = arith.andi %[[SHRUI]], %[[C1]] : i32234// CHECK-DAG: %[[ROUNDING_BIAS:.+]] = arith.addi %[[BIT16]], %[[C7FFF]] : i32235// CHECK-DAG: %[[BIASED:.+]] = arith.addi %[[BITCAST]], %[[ROUNDING_BIAS]] : i32236// CHECK-DAG: %[[BIASED_SHIFTED:.+]] = arith.shrui %[[BIASED]], %[[C16]] : i32237// CHECK-DAG: %[[NORMAL_CASE_RESULT_i16:.+]] = arith.trunci %[[BIASED_SHIFTED]] : i32 to i16238// CHECK-DAG: %[[SELECT:.+]] = arith.select %[[ISNAN]], %[[C7FC0_i16]], %[[NORMAL_CASE_RESULT_i16]] : i16239// CHECK-DAG: %[[RESULT:.+]] = arith.bitcast %[[SELECT]] : i16 to bf16240// CHECK: return %[[RESULT]]241 242// -----243 244func.func @truncf_vector_f32(%arg0 : vector<4xf32>) -> vector<4xbf16> {245    %0 = arith.truncf %arg0 : vector<4xf32> to vector<4xbf16>246    return %0 : vector<4xbf16>247}248 249// CHECK-LABEL: @truncf_vector_f32250// CHECK-NOT: arith.truncf251 252// -----253func.func @truncf_f32_to_f8E8M0FNU(%arg0 : f32) -> f8E8M0FNU {254    %0 = arith.truncf %arg0 : f32 to f8E8M0FNU255    return %0 : f8E8M0FNU256}257// CHECK-LABEL: @truncf_f32_to_f8E8M0FNU258// CHECK: %[[BITCAST:.+]] = arith.bitcast %arg0 : f32 to i32259// CHECK: %[[C23_i32:.+]] = arith.constant 23 : i32260// CHECK: %[[SHRUI:.+]] = arith.shrui %[[BITCAST]], %[[C23_i32]] : i32261// CHECK: %[[TRUNCI:.+]] = arith.trunci %[[SHRUI]] : i32 to i8262// CHECK: %[[RESULT:.+]] = arith.bitcast %[[TRUNCI]] : i8 to f8E8M0FNU263// CHECK: return %[[RESULT]]264 265// -----266 267func.func @truncf_f16_to_f8E8M0FNU(%arg0 : f16) -> f8E8M0FNU {268    %0 = arith.truncf %arg0 : f16 to f8E8M0FNU269    return %0 : f8E8M0FNU270}271// CHECK-LABEL: @truncf_f16_to_f8E8M0FNU272// CHECK: %[[EXTF:.+]] = arith.extf %arg0 : f16 to f32273// CHECK: %[[BITCAST:.+]] = arith.bitcast %[[EXTF]] : f32 to i32274// CHECK: %[[C23_i32:.+]] = arith.constant 23 : i32275// CHECK: %[[SHRUI:.+]] = arith.shrui %[[BITCAST]], %[[C23_i32]] : i32276// CHECK: %[[TRUNCI:.+]] = arith.trunci %[[SHRUI]] : i32 to i8277// CHECK: %[[RESULT:.+]] = arith.bitcast %[[TRUNCI]] : i8 to f8E8M0FNU278// CHECK: return %[[RESULT]]279 280// -----281 282func.func @truncf_vector_f32_to_f8E8M0FNU(%arg0 : vector<4xf32>) -> vector<4xf8E8M0FNU> {283    %0 = arith.truncf %arg0 : vector<4xf32> to vector<4xf8E8M0FNU>284    return %0 : vector<4xf8E8M0FNU>285}286 287// CHECK-LABEL: @truncf_vector_f32_to_f8E8M0FNU288// CHECK-NOT: arith.truncf289 290// -----291 292func.func @truncf_vector_f16_to_f8E8M0FNU(%arg0 : vector<4xf16>) -> vector<4xf8E8M0FNU> {293    %0 = arith.truncf %arg0 : vector<4xf16> to vector<4xf8E8M0FNU>294    return %0 : vector<4xf8E8M0FNU>295}296 297// CHECK-LABEL: @truncf_vector_f16_to_f8E8M0FNU298// CHECK-NOT: arith.truncf299 300// -----301 302func.func @truncf_vector_bf16_to_f8E8M0FNU(%arg0 : vector<4xbf16>) -> vector<4xf8E8M0FNU> {303    %0 = arith.truncf %arg0 : vector<4xbf16> to vector<4xf8E8M0FNU>304    return %0 : vector<4xf8E8M0FNU>305}306 307// CHECK-LABEL: @truncf_vector_bf16_to_f8E8M0FNU308// CHECK-NOT: arith.truncf309// CHECK: return310 311// -----312 313func.func @scaling_truncf_f32_to_f4E2M1FN(%arg0 : f32, %arg1: f8E8M0FNU) -> f4E2M1FN {314    %0 = arith.scaling_truncf %arg0, %arg1 : f32, f8E8M0FNU to f4E2M1FN315    return %0 : f4E2M1FN316}317 318// SCHECK-LABEL: @scaling_truncf_f32_to_f4E2M1FN319// SCHECK: %[[SCALEF32:.+]] = arith.extf %arg1 : f8E8M0FNU to f32320// SCHECK: %[[DIVF:.+]] = arith.divf %arg0, %[[SCALEF32]] : f32321// SCHECK: %[[RESULT:.+]] = arith.truncf %[[DIVF]] : f32 to f4E2M1FN322// SCHECK: return %[[RESULT]]323 324// -----325 326func.func @scaling_truncf_vector_f16_to_f6E3M2FN(%arg0 : vector<4xf16>, %arg1: vector<4xf8E8M0FNU>) -> vector<4xf6E3M2FN> {327    %0 = arith.scaling_truncf %arg0, %arg1 : vector<4xf16>, vector<4xf8E8M0FNU> to vector<4xf6E3M2FN>328    return %0 : vector<4xf6E3M2FN>329}330 331// SCHECK-LABEL: @scaling_truncf_vector_f16_to_f6E3M2FN332// SCHECK: %[[SCALEF16:.+]] = arith.extf %arg1 : vector<4xf8E8M0FNU> to vector<4xf16>333// SCHECK: %[[DIVF:.+]] = arith.divf %arg0, %[[SCALEF16]] : vector<4xf16>334// SCHECK: %[[RESULT:.+]] = arith.truncf %[[DIVF]] : vector<4xf16> to vector<4xf6E3M2FN>335// SCHECK: return %[[RESULT]] : vector<4xf6E3M2FN>336 337// -----338 339func.func @scaling_truncf_propagate_rounding_mode_fast_math(%arg0 : vector<4xf16>, %arg1: vector<4xf16>) -> vector<4xf6E3M2FN> {340    %0 = arith.scaling_truncf %arg0, %arg1 to_nearest_even fastmath<fast> : vector<4xf16>, vector<4xf16> to vector<4xf6E3M2FN>341    return %0 : vector<4xf6E3M2FN>342}343// SCHECK-LABEL: @scaling_truncf_propagate_rounding_mode_fast_math344// SCHECK: %[[SCALEF8:.+]] = arith.truncf %arg1 fastmath<fast> : vector<4xf16> to vector<4xf8E8M0FNU>345// SCHECK: %[[SCALEINTY:.+]] = arith.extf %[[SCALEF8]] fastmath<fast> : vector<4xf8E8M0FNU> to vector<4xf16>346// SCHECK: %[[DIVF:.+]] = arith.divf %arg0, %[[SCALEINTY]] fastmath<fast> : vector<4xf16>347// SCHECK: %[[TRUNCF:.+]] = arith.truncf [[_:%[a-zA-Z0-9_]+]] to_nearest_even fastmath<fast> : vector<4xf16> to vector<4xf6E3M2FN>348// SCHECK: return %[[TRUNCF]] : vector<4xf6E3M2FN>349 350// -----351 352func.func @scaling_truncf_f16_to_f4E2M1FN_using_f16_scales(%arg0: f16, %arg1 : f16) -> f4E2M1FN {353    %0 = arith.scaling_truncf %arg0, %arg1 : f16, f16 to f4E2M1FN354    return %0 : f4E2M1FN355}356// SCHECK-LABEL: @scaling_truncf_f16_to_f4E2M1FN_using_f16_scales357// SCHECK: %[[SCALETRUNCF:.+]] = arith.truncf %arg1 : f16 to f8E8M0FN358// SCHECK: return359 360// -----361func.func @scaling_truncf_vector_f16_to_f4E2M1FN_using_f16_scales(%arg0: vector<4xf16>, %arg1 : vector<4xf16>) -> vector<4xf4E2M1FN> {362    %0 = arith.scaling_truncf %arg0, %arg1 : vector<4xf16>, vector<4xf16> to vector<4xf4E2M1FN>363    return %0 : vector<4xf4E2M1FN>364}365// SCHECK-LABEL: @scaling_truncf_vector_f16_to_f4E2M1FN_using_f16_scales366// SCHECK: %[[SCALETRUNCF:.+]] = arith.truncf %arg1 : vector<4xf16> to vector<4xf8E8M0FNU>367// SCHECK: return368 369// -----370 371func.func @invalid_scaling_truncf_to_f4E2M1FN(%arg0: f16, %arg1 : f8E5M2FNUZ) -> f4E2M1FN {372    // expected-error@+1 {{failed to legalize operation 'arith.scaling_truncf' that was explicitly marked illegal}}373    %0 = arith.scaling_truncf %arg0, %arg1 : f16, f8E5M2FNUZ to f4E2M1FN374    return %0 : f4E2M1FN375}376 377// -----378 379func.func @extf_f8E8M0FNU_to_f32(%arg0 : f8E8M0FNU) -> f32 {380    %0 = arith.extf %arg0 : f8E8M0FNU to f32381    return %0 : f32382}383 384// CHECK-LABLE: @extf_f8E8M0FNU_to_f32385// CHECK: %[[BITCAST:.+]] = arith.bitcast %arg0 : f8E8M0FNU to i8386// CHECK-DAG: %[[CF8NAN:.+]] = arith.constant -1 : i8387// CHECK-DAG: %[[CF32NAN:.+]] = arith.constant -1 : i32388// CHECK-DAG: %[[C23_i32:.+]] = arith.constant 23 : i32389// CHECK: %[[EXTUI:.+]] = arith.extui %[[BITCAST]] : i8 to i32390// CHECK: %[[SHLI:.+]] = arith.shli %[[EXTUI]], %[[C23_i32]] : i32391// CHECK: %[[CMP_NAN:.+]] = arith.cmpi eq, %[[BITCAST]], %[[CF8NAN]] : i8392// CHECK: %[[SELECT_NAN:.+]] = arith.select %[[CMP_NAN]], %[[CF32NAN]], %[[SHLI]] : i32393// CHECK: %[[RESULT:.+]] = arith.bitcast %[[SELECT_NAN]] : i32 to f32394// CHECK: return %[[RESULT]]395 396// -----397 398func.func @extf_f8E8M0FNU_to_f16(%arg0 : f8E8M0FNU) -> f16 {399    %0 = arith.extf %arg0 : f8E8M0FNU to f16400    return %0 : f16401}402 403// CHECK-LABEL: @extf_f8E8M0FNU_to_f16404// CHECK: %[[BITCAST:.+]] = arith.bitcast %arg0 : f8E8M0FNU to i8405// CHECK-DAG: %[[CF8NAN:.+]] = arith.constant -1 : i8406// CHECK-DAG: %[[CF32NAN:.+]] = arith.constant -1 : i32407// CHECK-DAG: %[[C23_i32:.+]] = arith.constant 23 : i32408// CHECK: %[[EXTUI:.+]] = arith.extui %[[BITCAST]] : i8 to i32409// CHECK: %[[SHLI:.+]] = arith.shli %[[EXTUI]], %[[C23_i32]] : i32410// CHECK: %[[CMP_NAN:.+]] = arith.cmpi eq, %[[BITCAST]], %[[CF8NAN]] : i8411// CHECK: %[[SELECT_NAN:.+]] = arith.select %[[CMP_NAN]], %[[CF32NAN]], %[[SHLI]] : i32412// CHECK: %[[F32_RESULT:.+]] = arith.bitcast %[[SELECT_NAN]] : i32 to f32413// CHECK: %[[F16_RESULT:.+]] = arith.truncf %[[F32_RESULT]] : f32 to f16414// CHECK: return %[[F16_RESULT]]415 416// -----417 418func.func @extf_vector_f8E8M0FNU_to_f32(%arg0 : vector<4xf8E8M0FNU>) -> vector<4xf32> {419    %0 = arith.extf %arg0 : vector<4xf8E8M0FNU> to vector<4xf32>420    return %0 : vector<4xf32>421}422 423// CHECK-LABEL: @extf_vector_f8E8M0FNU_to_f32424// CHECK-NOT: arith.extf425 426// -----427 428func.func @extf_vector_f8E8M0FNU_to_f16(%arg0 : vector<4xf8E8M0FNU>) -> vector<4xf16> {429    %0 = arith.extf %arg0 : vector<4xf8E8M0FNU> to vector<4xf16>430    return %0 : vector<4xf16>431}432 433// CHECK-LABEL: @extf_vector_f8E8M0FNU_to_f16434// CHECK-NOT: arith.extf435 436// -----437 438func.func @extf_vector_f8E8M0FNU_to_bf16(%arg0 : vector<4xf8E8M0FNU>) -> vector<4xbf16> {439    %0 = arith.extf %arg0 : vector<4xf8E8M0FNU> to vector<4xbf16>440    return %0 : vector<4xbf16>441}442 443// CHECK-LABEL: @extf_vector_f8E8M0FNU_to_bf16444// CHECK-NOT: arith.extf445// CHECK: return446 447// -----448 449func.func @scaling_extf_to_f32(%arg0: f4E2M1FN, %arg1 : f8E8M0FNU) -> f32 {450    %0 = arith.scaling_extf %arg0, %arg1 : f4E2M1FN, f8E8M0FNU to f32451    return %0 : f32 452}453 454// SCHECK-LABEL: @scaling_extf_to_f32455// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %arg1 : f8E8M0FNU to f32456// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : f4E2M1FN to f32457// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : f32458// SCHECK: return %[[RESULT]]459 460// -----461 462func.func @scaling_extf_to_f32_using_f16_scales(%arg0: f4E2M1FN, %arg1 : f16) -> f32 {463    %0 = arith.scaling_extf %arg0, %arg1 : f4E2M1FN, f16 to f32464    return %0 : f32 465}466 467// SCHECK-LABEL: @scaling_extf_to_f32_using_f16_scales468// SCHECK: %[[TRUNCF_SCALE:.+]] = arith.truncf %arg1 : f16 to f8E8M0FNU469// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %[[TRUNCF_SCALE]] : f8E8M0FNU to f32470// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : f4E2M1FN to f32471// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : f32472// SCHECK: return %[[RESULT]]473 474// -----475 476func.func @invalid_scaling_extf_to_f32(%arg0: f4E2M1FN, %arg1 : f8E5M2FNUZ) -> f32 {477    // expected-error@+1 {{failed to legalize operation 'arith.scaling_extf' that was explicitly marked illegal}}478    %0 = arith.scaling_extf %arg0, %arg1 : f4E2M1FN, f8E5M2FNUZ to f32479    return %0 : f32480}481 482// -----483 484func.func @scaling_extf_vector_to_f32(%arg0: vector<4xf4E2M1FN>, %arg1 : vector<4xf8E8M0FNU>) -> vector<4xf32> {485    %0 = arith.scaling_extf %arg0, %arg1 : vector<4xf4E2M1FN>, vector<4xf8E8M0FNU> to vector<4xf32>486    return %0 : vector<4xf32>487}488 489// SCHECK-LABEL: @scaling_extf_vector_to_f32490// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %arg1 : vector<4xf8E8M0FNU> to vector<4xf32>491// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : vector<4xf4E2M1FN> to vector<4xf32>492// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : vector<4xf32> 493// SCHECK: return %[[RESULT]]494 495// -----496 497func.func @scaling_extf_vector_to_f16(%arg0: vector<4xf4E2M1FN>, %arg1 : vector<4xf8E8M0FNU>) -> vector<4xf16> {498    %0 = arith.scaling_extf %arg0, %arg1 : vector<4xf4E2M1FN>, vector<4xf8E8M0FNU> to vector<4xf16>499    return %0 : vector<4xf16>500}501 502// SCHECK-LABEL: @scaling_extf_vector_to_f16503// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %arg1 : vector<4xf8E8M0FNU> to vector<4xf16>504// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : vector<4xf4E2M1FN> to vector<4xf16>505// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : vector<4xf16> 506// SCHECK: return %[[RESULT]]507 508// -----509 510func.func @scaling_extf_vector_to_bf16(%arg0: vector<4xf4E2M1FN>, %arg1 : vector<4xf8E8M0FNU>) -> vector<4xbf16> {511    %0 = arith.scaling_extf %arg0, %arg1 : vector<4xf4E2M1FN>, vector<4xf8E8M0FNU> to vector<4xbf16>512    return %0 : vector<4xbf16>513}514 515// SCHECK-LABEL: @scaling_extf_vector_to_bf16516// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %arg1 : vector<4xf8E8M0FNU> to vector<4xbf16>517// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : vector<4xf4E2M1FN> to vector<4xbf16>518// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : vector<4xbf16> 519// SCHECK: return %[[RESULT]]520 521// -----522 523func.func @scaling_extf_vector_to_f32_using_f16_scales(%arg0: vector<4xf4E2M1FN>, %arg1 : vector<4xf16>) -> vector<4xf32> {524    %0 = arith.scaling_extf %arg0, %arg1 : vector<4xf4E2M1FN>, vector<4xf16> to vector<4xf32>525    return %0 : vector<4xf32>526}527 528// SCHECK-LABEL: @scaling_extf_vector_to_f32_using_f16_scales529// SCHECK: %[[TRUNCF_SCALE:.+]] = arith.truncf %arg1 : vector<4xf16> to vector<4xf8E8M0FNU>530// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %[[TRUNCF_SCALE]] : vector<4xf8E8M0FNU> to vector<4xf32>531// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 : vector<4xf4E2M1FN> to vector<4xf32>532// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] : vector<4xf32>533// SCHECK: return %[[RESULT]]534 535// -----536 537func.func @scaling_extf_vector_to_f32_using_f16_scales_fastmath(%arg0: vector<4xf4E2M1FN>, %arg1 : vector<4xf16>) -> vector<4xf32> {538    %0 = arith.scaling_extf %arg0, %arg1 fastmath<fast> : vector<4xf4E2M1FN>, vector<4xf16> to vector<4xf32>539    return %0 : vector<4xf32>540}541 542// SCHECK-LABEL: @scaling_extf_vector_to_f32_using_f16_scales_fastmath543// SCHECK: %[[TRUNCF_SCALE:.+]] = arith.truncf %arg1 fastmath<fast> : vector<4xf16> to vector<4xf8E8M0FNU>544// SCHECK: %[[EXT_SCALE:.+]] = arith.extf %[[TRUNCF_SCALE]] fastmath<fast> : vector<4xf8E8M0FNU> to vector<4xf32>545// SCHECK: %[[EXT_INPUT:.+]] = arith.extf %arg0 fastmath<fast> : vector<4xf4E2M1FN> to vector<4xf32>546// SCHECK: %[[RESULT:.+]] = arith.mulf %[[EXT_INPUT]], %[[EXT_SCALE]] fastmath<fast> : vector<4xf32>547// SCHECK: return %[[RESULT]]548 549// -----550 551func.func @maxsi(%a: i32, %b: i32) -> i32 {552  %result = arith.maxsi %a, %b : i32553  return %result : i32554}555// CHECK-LABEL: func @maxsi556// CHECK-SAME: %[[LHS:.*]]: i32, %[[RHS:.*]]: i32557// CHECK-NEXT: %[[CMP:.*]] = arith.cmpi sgt, %[[LHS]], %[[RHS]] : i32558// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : i32559// CHECK-NEXT: return %[[RESULT]] : i32560 561// -----562 563func.func @minsi(%a: i32, %b: i32) -> i32 {564  %result = arith.minsi %a, %b : i32565  return %result : i32566}567// CHECK-LABEL: func @minsi568// CHECK-SAME: %[[LHS:.*]]: i32, %[[RHS:.*]]: i32569// CHECK-NEXT: %[[CMP:.*]] = arith.cmpi slt, %[[LHS]], %[[RHS]] : i32570// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : i32571// CHECK-NEXT: return %[[RESULT]] : i32572 573// -----574 575func.func @maxui(%a: i32, %b: i32) -> i32 {576  %result = arith.maxui %a, %b : i32577  return %result : i32578}579// CHECK-LABEL: func @maxui580// CHECK-SAME: %[[LHS:.*]]: i32, %[[RHS:.*]]: i32581// CHECK-NEXT: %[[CMP:.*]] = arith.cmpi ugt, %[[LHS]], %[[RHS]] : i32582// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : i32583// CHECK-NEXT: return %[[RESULT]] : i32584 585// -----586 587func.func @minui(%a: i32, %b: i32) -> i32 {588  %result = arith.minui %a, %b : i32589  return %result : i32590}591// CHECK-LABEL: func @minui592// CHECK-SAME: %[[LHS:.*]]: i32, %[[RHS:.*]]: i32593// CHECK-NEXT: %[[CMP:.*]] = arith.cmpi ult, %[[LHS]], %[[RHS]] : i32594// CHECK-NEXT: %[[RESULT:.*]] = arith.select %[[CMP]], %[[LHS]], %[[RHS]] : i32595// CHECK-NEXT: return %[[RESULT]] : i32596 597// -----598 599func.func @truncf_f32_to_f4E2M1FN(%arg0 : f32) -> f4E2M1FN {600    %0 = arith.truncf %arg0 : f32 to f4E2M1FN601    return %0 : f4E2M1FN602}603 604// CHECK-LABEL: @truncf_f32_to_f4E2M1FN605// CHECK-NOT: arith.truncf606 607// -----608 609func.func @truncf_vector_f32_to_f4E2M1FN(%arg0 : vector<4xf32>) -> vector<4xf4E2M1FN> {610    %0 = arith.truncf %arg0 : vector<4xf32> to vector<4xf4E2M1FN>611    return %0 : vector<4xf4E2M1FN>612}613 614// CHECK-LABEL: @truncf_vector_f32_to_f4E2M1FN615// CHECK-NOT: arith.truncf616 617// -----618 619func.func @extf_f4E2M1FN_to_f32(%arg0 : f4E2M1FN) -> f32 {620    %0 = arith.extf %arg0 : f4E2M1FN to f32621    return %0 : f32622}623 624// CHECK-LABEL: @extf_f4E2M1FN_to_f32625// CHECK-NOT: arith.extf626 627// -----628 629func.func @extf_vector_f4E2M1FN_to_f32(%arg0 : vector<4xf4E2M1FN>) -> vector<4xf32> {630    %0 = arith.extf %arg0 : vector<4xf4E2M1FN> to vector<4xf32>631    return %0 : vector<4xf32>632}633 634// CHECK-LABEL: @extf_vector_f4E2M1FN_to_f32635// CHECK-NOT: arith.extf636