diff --git a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h --- a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h +++ b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h @@ -16,6 +16,7 @@ void populateExpandCtlzPattern(RewritePatternSet &patterns); void populateExpandTanPattern(RewritePatternSet &patterns); void populateExpandTanhPattern(RewritePatternSet &patterns); +void populateExpandRoundEvenPattern(RewritePatternSet &patterns); void populateMathAlgebraicSimplificationPatterns(RewritePatternSet &patterns); diff --git a/mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp b/mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp --- a/mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp +++ b/mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp @@ -16,6 +16,7 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/Builders.h" #include "mlir/IR/ImplicitLocOpBuilder.h" +#include "mlir/IR/TypeUtilities.h" #include "mlir/Transforms/DialectConversion.h" using namespace mlir; @@ -115,6 +116,150 @@ return success(); } +// Convert `math.roundeven` into `math.round` + arith ops +static LogicalResult convertRoundEvenOp(math::RoundEvenOp op, + PatternRewriter &rewriter) { + ImplicitLocOpBuilder b(op.getLoc(), rewriter); + auto operand = op.getOperand(); + Type operandTy = operand.getType(); + Type resultTy = op.getType(); + Type operandETy = getElementTypeOrSelf(operandTy); + Type resultETy = getElementTypeOrSelf(resultTy); + + if (!operandETy.isF32() || !resultETy.isF32()) { + return rewriter.notifyMatchFailure(op, "not a roundeven of f32."); + } + + Type i32Ty = b.getI32Type(); + Type f32Ty = b.getF32Type(); + if (auto shapedTy = dyn_cast(operandTy)) { + i32Ty = shapedTy.clone(i32Ty); + f32Ty = shapedTy.clone(f32Ty); + } + + auto getAttr = [](Type type, int val) -> Attribute { + Type elTy = getElementTypeOrSelf(type); + Attribute constantAttr; + if (elTy.isInteger(32)) { + constantAttr = IntegerAttr::get(elTy, val); + } else if (elTy.isF32()) { + constantAttr = FloatAttr::get(elTy, static_cast(val)); + } else { + llvm_unreachable( + "Pattern `convertRoundEvenOp` only deals with f32 and i32"); + } + if (type.isa()) + return DenseElementsAttr::get(type, constantAttr); + return constantAttr; + }; + + Value c0 = b.create(i32Ty, getAttr(i32Ty, 0)); + Value c1 = b.create(i32Ty, getAttr(i32Ty, 1)); + Value cNeg1 = b.create(i32Ty, getAttr(i32Ty, -1)); + Value c1Float = b.create(f32Ty, getAttr(f32Ty, 1)); + Value c23 = b.create(i32Ty, getAttr(i32Ty, 23)); + Value c31 = b.create(i32Ty, getAttr(i32Ty, 31)); + Value c127 = b.create(i32Ty, getAttr(i32Ty, 127)); + Value c2To22 = b.create(i32Ty, getAttr(i32Ty, 1 << 22)); + Value c23Mask = + b.create(i32Ty, getAttr(i32Ty, (1 << 23) - 1)); + Value expMask = + b.create(i32Ty, getAttr(i32Ty, (1 << 8) - 1)); + + Value operandBitcast = b.create(i32Ty, operand); + Value round = b.create(operand); + Value roundBitcast = b.create(i32Ty, round); + + // Get biased exponents for operand and round(operand) + Value operandExp = b.create( + b.create(operandBitcast, c23), expMask); + Value operandBiasedExp = b.create(operandExp, c127); + Value roundExp = b.create( + b.create(roundBitcast, c23), expMask); + Value roundBiasedExp = b.create(roundExp, c127); + + auto safeShiftRight = [&](Value x, Value shift) -> Value { + // Clamp shift to valid range [0, 31] to avoid undefined behavior + Value clampedShift = b.create(shift, c0); + clampedShift = b.create(clampedShift, c31); + return b.create(x, clampedShift); + }; + + auto maskMantissa = [&](Value mantissa, + Value mantissaMaskRightShift) -> Value { + Value shiftedMantissaMask = safeShiftRight(c23Mask, mantissaMaskRightShift); + return b.create(mantissa, shiftedMantissaMask); + }; + + // A whole number `x`, such that `|x| != 1`, is even if the mantissa, ignoring + // the leftmost `clamp(biasedExp - 1, 0, 23)` bits, is zero. Large numbers + // with `biasedExp > 23` (numbers where there is not enough precision to store + // decimals) are always even, and they satisfy the even condition trivially + // since the mantissa without all its bits is zero. The even condition + // is also true for +-0, since they have `biasedExp = -127` and the entire + // mantissa is zero. The case of +-1 has to be handled separately. Here + // we identify these values by noting that +-1 are the only whole numbers with + // `biasedExp == 0`. + // + // The special values +-inf and +-nan also satisfy the same property that + // whole non-unit even numbers satisfy. In particular, the special values have + // `biasedExp > 23`, so they get treated as large numbers with no room for + // decimals, which are always even. + Value roundBiasedExpEq0 = + b.create(arith::CmpIPredicate::eq, roundBiasedExp, c0); + Value roundBiasedExpMinus1 = b.create(roundBiasedExp, c1); + Value roundMaskedMantissa = maskMantissa(roundBitcast, roundBiasedExpMinus1); + Value roundIsNotEvenOrSpecialVal = b.create( + arith::CmpIPredicate::ne, roundMaskedMantissa, c0); + roundIsNotEvenOrSpecialVal = + b.create(roundIsNotEvenOrSpecialVal, roundBiasedExpEq0); + + // A value `x` with `0 <= biasedExp < 23`, is halfway between two consecutive + // integers if the bit at index `biasedExp` starting from the left in the + // mantissa is 1 and all the bits to the right are zero. Values with + // `biasedExp >= 23` don't have decimals, so they are never halfway. The + // values +-0.5 are the only halfway values that have `biasedExp == -1 < 0`, + // so these are handled separately. In particular, if `biasedExp == -1`, the + // value is halfway if the entire mantissa is zero. + Value operandBiasedExpEqNeg1 = b.create( + arith::CmpIPredicate::eq, operandBiasedExp, cNeg1); + Value expectedOperandMaskedMantissa = b.create( + operandBiasedExpEqNeg1, c0, safeShiftRight(c2To22, operandBiasedExp)); + Value operandMaskedMantissa = maskMantissa(operandBitcast, operandBiasedExp); + Value operandIsHalfway = + b.create(arith::CmpIPredicate::eq, operandMaskedMantissa, + expectedOperandMaskedMantissa); + // Ensure `biasedExp` is in the valid range for half values. + Value operandBiasedExpGeNeg1 = b.create( + arith::CmpIPredicate::sge, operandBiasedExp, cNeg1); + Value operandBiasedExpLt23 = + b.create(arith::CmpIPredicate::slt, operandBiasedExp, c23); + operandIsHalfway = + b.create(operandIsHalfway, operandBiasedExpLt23); + operandIsHalfway = + b.create(operandIsHalfway, operandBiasedExpGeNeg1); + + // Grab the sign bit and turn it into -1.0 or 1.0 + Value signIsPositive = b.create( + arith::CmpIPredicate::eq, b.create(operandBitcast, c31), + c0); + Value sign = b.create(signIsPositive, c1Float, + b.create(c1Float)); + + Value roundShifted = b.create(round, sign); + // If the rounded value is even or a special value, we default to the behavior + // of `math.round`. + Value needsShift = + b.create(roundIsNotEvenOrSpecialVal, operandIsHalfway); + Value result = b.create(needsShift, roundShifted, round); + // The `x - sign` adjustment does not preserve the sign when we are adjusting + // the value -1 to -0. So here the sign is copied again to ensure that -0.5 is + // rounded to -0.0. + result = b.create(result, operand); + rewriter.replaceOp(op, result); + return success(); +} + void mlir::populateExpandCtlzPattern(RewritePatternSet &patterns) { patterns.add(convertCtlzOp); } @@ -126,3 +271,7 @@ void mlir::populateExpandTanhPattern(RewritePatternSet &patterns) { patterns.add(convertTanhOp); } + +void mlir::populateExpandRoundEvenPattern(RewritePatternSet &patterns) { + patterns.add(convertRoundEvenOp); +} diff --git a/mlir/test/Dialect/Math/expand-math.mlir b/mlir/test/Dialect/Math/expand-math.mlir --- a/mlir/test/Dialect/Math/expand-math.mlir +++ b/mlir/test/Dialect/Math/expand-math.mlir @@ -53,3 +53,63 @@ // CHECK: return %[[WHILE]]#1 return %res : i32 } + +// ----- + +// CHECK-LABEL: func.func @roundeven +func.func @roundeven(%arg: f32) -> f32 { + %res = math.roundeven %arg : f32 + return %res : f32 +} + +// CHECK-SAME: %[[VAL_0:.*]]: f32) -> f32 { +// CHECK-DAG: %[[C_0:.*]] = arith.constant 0 : i32 +// CHECK-DAG: %[[C_1:.*]] = arith.constant 1 : i32 +// CHECK-DAG: %[[C_NEG_1:.*]] = arith.constant -1 : i32 +// CHECK-DAG: %[[C_1_FLOAT:.*]] = arith.constant 1.000000e+00 : f32 +// CHECK-DAG: %[[C_23:.*]] = arith.constant 23 : i32 +// CHECK-DAG: %[[C_31:.*]] = arith.constant 31 : i32 +// CHECK-DAG: %[[C_127:.*]] = arith.constant 127 : i32 +// CHECK-DAG: %[[C_4194304:.*]] = arith.constant 4194304 : i32 +// CHECK-DAG: %[[C_8388607:.*]] = arith.constant 8388607 : i32 +// CHECK-DAG: %[[C_255:.*]] = arith.constant 255 : i32 +// CHECK-DAG: %[[C_NEG_1_FLOAT:.*]] = arith.constant -1.000000e+00 : f32 +// CHECK: %[[OPERAND_BITCAST:.*]] = arith.bitcast %[[VAL_0]] : f32 to i32 +// CHECK: %[[ROUND:.*]] = math.round %[[VAL_0]] : f32 +// CHECK: %[[ROUND_BITCAST:.*]] = arith.bitcast %[[ROUND]] : f32 to i32 +// CHECK: %[[SHIFTED_OPERAND_BITCAST:.*]] = arith.shrui %[[OPERAND_BITCAST]], %[[C_23]] : i32 +// CHECK: %[[OPERAND_EXP:.*]] = arith.andi %[[SHIFTED_OPERAND_BITCAST]], %[[C_255]] : i32 +// CHECK: %[[OPERAND_BIASED_EXP:.*]] = arith.subi %[[OPERAND_EXP]], %[[C_127]] : i32 +// CHECK: %[[SHIFTED_ROUND_BITCAST:.*]] = arith.shrui %[[ROUND_BITCAST]], %[[C_23]] : i32 +// CHECK: %[[ROUND_EXP:.*]] = arith.andi %[[SHIFTED_ROUND_BITCAST]], %[[C_255]] : i32 +// CHECK: %[[ROUND_BIASED_EXP:.*]] = arith.subi %[[ROUND_EXP]], %[[C_127]] : i32 +// CHECK: %[[ROUND_BIASED_EXP_EQ_0:.*]] = arith.cmpi eq, %[[ROUND_BIASED_EXP]], %[[C_0]] : i32 +// CHECK: %[[ROUND_BIASED_EXP_MINUS_1:.*]] = arith.subi %[[ROUND_BIASED_EXP]], %[[C_1]] : i32 +// CHECK: %[[CLAMPED_SHIFT_0:.*]] = arith.maxsi %[[ROUND_BIASED_EXP_MINUS_1]], %[[C_0]] : i32 +// CHECK: %[[CLAMPED_SHIFT_1:.*]] = arith.minsi %[[CLAMPED_SHIFT_0]], %[[C_31]] : i32 +// CHECK: %[[SHIFTED_MANTISSA_MASK_0:.*]] = arith.shrui %[[C_8388607]], %[[CLAMPED_SHIFT_1]] : i32 +// CHECK: %[[ROUND_MASKED_MANTISSA:.*]] = arith.andi %[[ROUND_BITCAST]], %[[SHIFTED_MANTISSA_MASK_0]] : i32 +// CHECK: %[[ROUND_IS_NOT_EVEN_OR_SPECIAL_0:.*]] = arith.cmpi ne, %[[ROUND_MASKED_MANTISSA]], %[[C_0]] : i32 +// CHECK: %[[ROUND_IS_NOT_EVEN_OR_SPECIAL_1:.*]] = arith.ori %[[ROUND_IS_NOT_EVEN_OR_SPECIAL_0]], %[[ROUND_BIASED_EXP_EQ_0]] : i1 +// CHECK: %[[OPERAND_BIASED_EXP_EQ_NEG_1:.*]] = arith.cmpi eq, %[[OPERAND_BIASED_EXP]], %[[C_NEG_1]] : i32 +// CHECK: %[[CLAMPED_SHIFT_2:.*]] = arith.maxsi %[[OPERAND_BIASED_EXP]], %[[C_0]] : i32 +// CHECK: %[[CLAMPED_SHIFT_3:.*]] = arith.minsi %[[CLAMPED_SHIFT_2]], %[[C_31]] : i32 +// CHECK: %[[SHIFTED_2_TO_22:.*]] = arith.shrui %[[C_4194304]], %[[CLAMPED_SHIFT_3]] : i32 +// CHECK: %[[EXPECTED_OPERAND_MASKED_MANTISSA:.*]] = arith.select %[[OPERAND_BIASED_EXP_EQ_NEG_1]], %[[C_0]], %[[SHIFTED_2_TO_22]] : i32 +// CHECK: %[[CLAMPED_SHIFT_4:.*]] = arith.maxsi %[[OPERAND_BIASED_EXP]], %[[C_0]] : i32 +// CHECK: %[[CLAMPED_SHIFT_5:.*]] = arith.minsi %[[CLAMPED_SHIFT_4]], %[[C_31]] : i32 +// CHECK: %[[SHIFTED_MANTISSA_MASK_1:.*]] = arith.shrui %[[C_8388607]], %[[CLAMPED_SHIFT_5]] : i32 +// CHECK: %[[OPERAND_MASKED_MANTISSA:.*]] = arith.andi %[[OPERAND_BITCAST]], %[[SHIFTED_MANTISSA_MASK_1]] : i32 +// CHECK: %[[OPERAND_IS_HALFWAY_0:.*]] = arith.cmpi eq, %[[OPERAND_MASKED_MANTISSA]], %[[EXPECTED_OPERAND_MASKED_MANTISSA]] : i32 +// CHECK: %[[OPERAND_BIASED_EXP_GE_NEG_1:.*]] = arith.cmpi sge, %[[OPERAND_BIASED_EXP]], %[[C_NEG_1]] : i32 +// CHECK: %[[OPERAND_BIASED_EXP_LT_23:.*]] = arith.cmpi slt, %[[OPERAND_BIASED_EXP]], %[[C_23]] : i32 +// CHECK: %[[OPERAND_IS_HALFWAY_1:.*]] = arith.andi %[[OPERAND_IS_HALFWAY_0]], %[[OPERAND_BIASED_EXP_LT_23]] : i1 +// CHECK: %[[OPERAND_IS_HALFWAY_2:.*]] = arith.andi %[[OPERAND_IS_HALFWAY_1]], %[[OPERAND_BIASED_EXP_GE_NEG_1]] : i1 +// CHECK: %[[SIGN_BIT:.*]] = arith.shrui %[[OPERAND_BITCAST]], %[[C_31]] : i32 +// CHECK: %[[SIGN_IS_POSITIVE:.*]] = arith.cmpi eq, %[[SIGN_BIT]], %[[C_0]] : i32 +// CHECK: %[[SIGN:.*]] = arith.select %[[SIGN_IS_POSITIVE]], %[[C_1_FLOAT]], %[[C_NEG_1_FLOAT]] : f32 +// CHECK: %[[ROUND_SHIFTED:.*]] = arith.subf %[[ROUND]], %[[SIGN]] : f32 +// CHECK: %[[NEEDS_SHIFT:.*]] = arith.andi %[[ROUND_IS_NOT_EVEN_OR_SPECIAL_1]], %[[OPERAND_IS_HALFWAY_2]] : i1 +// CHECK: %[[RESULT:.*]] = arith.select %[[NEEDS_SHIFT]], %[[ROUND_SHIFTED]], %[[ROUND]] : f32 +// CHECK: %[[COPYSIGN:.*]] = math.copysign %[[RESULT]], %[[VAL_0]] : f32 +// CHECK: return %[[COPYSIGN]] : f32 diff --git a/mlir/test/lib/Dialect/Math/TestExpandMath.cpp b/mlir/test/lib/Dialect/Math/TestExpandMath.cpp --- a/mlir/test/lib/Dialect/Math/TestExpandMath.cpp +++ b/mlir/test/lib/Dialect/Math/TestExpandMath.cpp @@ -37,6 +37,7 @@ populateExpandCtlzPattern(patterns); populateExpandTanPattern(patterns); populateExpandTanhPattern(patterns); + populateExpandRoundEvenPattern(patterns); (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); } diff --git a/mlir/test/mlir-cpu-runner/expand-math-ops.mlir b/mlir/test/mlir-cpu-runner/expand-math-ops.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-cpu-runner/expand-math-ops.mlir @@ -0,0 +1,182 @@ +// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(test-expand-math,convert-math-to-llvm,convert-arith-to-llvm),convert-vector-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \ +// RUN: | mlir-cpu-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 + +func.func @roundeven(%a : f32) { + %b = math.roundeven %a : f32 + vector.print %b : f32 + return +} + +func.func @roundeven$bitcast_result_to_int(%a : f32) { + %b = math.roundeven %a : f32 + %c = arith.bitcast %b : f32 to i32 + vector.print %c : i32 + return +} + +func.func @roundeven$vector(%a : vector<1xf32>) { + %b = math.roundeven %a : vector<1xf32> + vector.print %b : vector<1xf32> + return +} + +func.func @main() { + %c0_25 = arith.constant 0.25 : f32 + %c0_5 = arith.constant 0.5 : f32 + %c0_75 = arith.constant 0.75 : f32 + %c1 = arith.constant 1.0 : f32 + %c1_25 = arith.constant 1.25 : f32 + %c1_5 = arith.constant 1.5 : f32 + %c1_75 = arith.constant 1.75 : f32 + %c2 = arith.constant 2.0 : f32 + %c2_25 = arith.constant 2.25 : f32 + %c2_5 = arith.constant 2.5 : f32 + %c2_75 = arith.constant 2.75 : f32 + %c3 = arith.constant 3.0 : f32 + %c3_25 = arith.constant 3.25 : f32 + %c3_5 = arith.constant 3.5 : f32 + %c3_75 = arith.constant 3.75 : f32 + + %cNeg0_25 = arith.constant -0.25 : f32 + %cNeg0_5 = arith.constant -0.5 : f32 + %cNeg0_75 = arith.constant -0.75 : f32 + %cNeg1 = arith.constant -1.0 : f32 + %cNeg1_25 = arith.constant -1.25 : f32 + %cNeg1_5 = arith.constant -1.5 : f32 + %cNeg1_75 = arith.constant -1.75 : f32 + %cNeg2 = arith.constant -2.0 : f32 + %cNeg2_25 = arith.constant -2.25 : f32 + %cNeg2_5 = arith.constant -2.5 : f32 + %cNeg2_75 = arith.constant -2.75 : f32 + %cNeg3 = arith.constant -3.0 : f32 + %cNeg3_25 = arith.constant -3.25 : f32 + %cNeg3_5 = arith.constant -3.5 : f32 + %cNeg3_75 = arith.constant -3.75 : f32 + + // CHECK: 0 + call @roundeven(%c0_25) : (f32) -> () + // CHECK-NEXT: 0 + call @roundeven(%c0_5) : (f32) -> () + // CHECK-NEXT: 1 + call @roundeven(%c0_75) : (f32) -> () + // CHECK-NEXT: 1 + call @roundeven(%c1) : (f32) -> () + // CHECK-NEXT: 1 + call @roundeven(%c1_25) : (f32) -> () + // CHECK-NEXT: 2 + call @roundeven(%c1_5) : (f32) -> () + // CHECK-NEXT: 2 + call @roundeven(%c1_75) : (f32) -> () + // CHECK-NEXT: 2 + call @roundeven(%c2) : (f32) -> () + // CHECK-NEXT: 2 + call @roundeven(%c2_25) : (f32) -> () + // CHECK-NEXT: 2 + call @roundeven(%c2_5) : (f32) -> () + // CHECK-NEXT: 3 + call @roundeven(%c2_75) : (f32) -> () + // CHECK-NEXT: 3 + call @roundeven(%c3) : (f32) -> () + // CHECK-NEXT: 3 + call @roundeven(%c3_25) : (f32) -> () + // CHECK-NEXT: 4 + call @roundeven(%c3_5) : (f32) -> () + // CHECK-NEXT: 4 + call @roundeven(%c3_75) : (f32) -> () + + // CHECK-NEXT: -0 + call @roundeven(%cNeg0_25) : (f32) -> () + // CHECK-NEXT: -0 + call @roundeven(%cNeg0_5) : (f32) -> () + // CHECK-NEXT: -1 + call @roundeven(%cNeg0_75) : (f32) -> () + // CHECK-NEXT: -1 + call @roundeven(%cNeg1) : (f32) -> () + // CHECK-NEXT: -1 + call @roundeven(%cNeg1_25) : (f32) -> () + // CHECK-NEXT: -2 + call @roundeven(%cNeg1_5) : (f32) -> () + // CHECK-NEXT: -2 + call @roundeven(%cNeg1_75) : (f32) -> () + // CHECK-NEXT: -2 + call @roundeven(%cNeg2) : (f32) -> () + // CHECK-NEXT: -2 + call @roundeven(%cNeg2_25) : (f32) -> () + // CHECK-NEXT: -2 + call @roundeven(%cNeg2_5) : (f32) -> () + // CHECK-NEXT: -3 + call @roundeven(%cNeg2_75) : (f32) -> () + // CHECK-NEXT: -3 + call @roundeven(%cNeg3) : (f32) -> () + // CHECK-NEXT: -3 + call @roundeven(%cNeg3_25) : (f32) -> () + // CHECK-NEXT: -4 + call @roundeven(%cNeg3_5) : (f32) -> () + // CHECK-NEXT: -4 + call @roundeven(%cNeg3_75) : (f32) -> () + + + // Special values: 0, -0, inf, -inf, nan, -nan + %cNeg0 = arith.constant -0.0 : f32 + %c0 = arith.constant 0.0 : f32 + %cInfInt = arith.constant 0x7f800000 : i32 + %cInf = arith.bitcast %cInfInt : i32 to f32 + %cNegInfInt = arith.constant 0xff800000 : i32 + %cNegInf = arith.bitcast %cNegInfInt : i32 to f32 + %cNanInt = arith.constant 0x7fc00000 : i32 + %cNan = arith.bitcast %cNanInt : i32 to f32 + %cNegNanInt = arith.constant 0xffc00000 : i32 + %cNegNan = arith.bitcast %cNegNanInt : i32 to f32 + + // CHECK-NEXT: -0 + call @roundeven(%cNeg0) : (f32) -> () + // CHECK-NEXT: 0 + call @roundeven(%c0) : (f32) -> () + // CHECK-NEXT: inf + call @roundeven(%cInf) : (f32) -> () + // CHECK-NEXT: -inf + call @roundeven(%cNegInf) : (f32) -> () + // CHECK-NEXT: nan + call @roundeven(%cNan) : (f32) -> () + // CHECK-NEXT: -nan + call @roundeven(%cNegNan) : (f32) -> () + + + // Values above and below 2^23 = 8388608 + %c8388606_5 = arith.constant 8388606.5 : f32 + %c8388607 = arith.constant 8388607.0 : f32 + %c8388607_5 = arith.constant 8388607.5 : f32 + %c8388608 = arith.constant 8388608.0 : f32 + %c8388609 = arith.constant 8388609.0 : f32 + + // Bitcast result to int to avoid printing in scientific notation, + // which does not display all significant digits. + + // CHECK-NEXT: 1258291196 + // hex: 0x4AFFFFFC + call @roundeven$bitcast_result_to_int(%c8388606_5) : (f32) -> () + // CHECK-NEXT: 1258291198 + // hex: 0x4AFFFFFE + call @roundeven$bitcast_result_to_int(%c8388607) : (f32) -> () + // CHECK-NEXT: 1258291200 + // hex: 0x4B000000 + call @roundeven$bitcast_result_to_int(%c8388607_5) : (f32) -> () + // CHECK-NEXT: 1258291200 + // hex: 0x4B000000 + call @roundeven$bitcast_result_to_int(%c8388608) : (f32) -> () + // CHECK-NEXT: 1258291201 + // hex: 0x4B000001 + call @roundeven$bitcast_result_to_int(%c8388609) : (f32) -> () + + + // Check that vector type works + %cVec = arith.constant dense<[0.5]> : vector<1xf32> + // CHECK-NEXT: ( 0 ) + call @roundeven$vector(%cVec) : (vector<1xf32>) -> () + + return +}