[flang] Lower anint with math.round (#186039)
Use `math.round` in lowering of `anint` so we can use passes like `MathToNVVM` to target device code differently.
This commit is contained in:
committed by
GitHub
parent
3c391665ec
commit
1800651c86
@@ -1198,11 +1198,11 @@ static constexpr MathOperation mathOperations[] = {
|
||||
{"aint", RTNAME_STRING(TruncF128), FuncTypeReal16Real16, genLibF128Call},
|
||||
// llvm.round behaves the same way as libm's round.
|
||||
{"anint", "llvm.round.f32", genFuncType<Ty::Real<4>, Ty::Real<4>>,
|
||||
genMathOp<mlir::LLVM::RoundOp>},
|
||||
genMathOp<mlir::math::RoundOp>},
|
||||
{"anint", "llvm.round.f64", genFuncType<Ty::Real<8>, Ty::Real<8>>,
|
||||
genMathOp<mlir::LLVM::RoundOp>},
|
||||
genMathOp<mlir::math::RoundOp>},
|
||||
{"anint", "llvm.round.f80", genFuncType<Ty::Real<10>, Ty::Real<10>>,
|
||||
genMathOp<mlir::LLVM::RoundOp>},
|
||||
genMathOp<mlir::math::RoundOp>},
|
||||
{"anint", RTNAME_STRING(RoundF128), FuncTypeReal16Real16, genLibF128Call},
|
||||
{"asin", "asinf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
|
||||
genMathOp<mlir::math::AsinOp>},
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
! CHECK: %[[VAL_0:.*]]:2 = hlfir.declare %[[VAL_0_b]]
|
||||
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_1_b]]
|
||||
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]]#0 : !fir.ref<f32>
|
||||
! CHECK: %[[VAL_3:.*]] = llvm.intr.round(%[[VAL_2]]) : (f32) -> f32
|
||||
! CHECK: %[[VAL_3:.*]] = math.round %[[VAL_2]] fastmath<contract> : f32
|
||||
! CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_1]]#0 : f32, !fir.ref<f32>
|
||||
! CHECK: return
|
||||
! CHECK: }
|
||||
@@ -17,7 +17,7 @@ subroutine anint_test(a, b)
|
||||
end subroutine
|
||||
|
||||
! CHECK-LABEL: func.func @_QPanint_test_real8(
|
||||
! CHECK: llvm.intr.round(%{{.*}}) : (f64) -> f64
|
||||
! CHECK: math.round %{{.*}} fastmath<contract> : f64
|
||||
|
||||
subroutine anint_test_real8(a, b)
|
||||
real(8) :: a, b
|
||||
@@ -25,7 +25,7 @@ subroutine anint_test_real8(a, b)
|
||||
end subroutine
|
||||
|
||||
! CHECK-KIND10-LABEL: func.func @_QPanint_test_real10(
|
||||
! CHECK-KIND10: llvm.intr.round(%{{.*}}) : (f80) -> f80
|
||||
! CHECK-KIND10: math.round %{{.*}} fastmath<contract> : f80
|
||||
|
||||
subroutine anint_test_real10(a, b)
|
||||
integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10)
|
||||
|
||||
@@ -13,8 +13,8 @@ function test_real4(x)
|
||||
end function
|
||||
|
||||
! ALL-LABEL: @_QPtest_real4
|
||||
! FAST: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f32) -> f32
|
||||
! RELAXED: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f32) -> f32
|
||||
! FAST: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f32
|
||||
! RELAXED: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f32
|
||||
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f32({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
|
||||
|
||||
function test_real8(x)
|
||||
@@ -23,8 +23,8 @@ function test_real8(x)
|
||||
end function
|
||||
|
||||
! ALL-LABEL: @_QPtest_real8
|
||||
! FAST: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f64) -> f64
|
||||
! RELAXED: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f64) -> f64
|
||||
! FAST: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f64
|
||||
! RELAXED: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f64
|
||||
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f64({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
|
||||
|
||||
function test_real10(x)
|
||||
@@ -34,8 +34,8 @@ function test_real10(x)
|
||||
end function
|
||||
|
||||
! ALL-KIND10-LABEL: @_QPtest_real10
|
||||
! FAST-KIND10: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f80) -> f80
|
||||
! RELAXED-KIND10: {{%[A-Za-z0-9._]+}} = llvm.intr.round({{%[A-Za-z0-9._]+}}) : (f80) -> f80
|
||||
! FAST-KIND10: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f80
|
||||
! RELAXED-KIND10: {{%[A-Za-z0-9._]+}} = math.round {{%[A-Za-z0-9._]+}} fastmath<contract> : f80
|
||||
! PRECISE-KIND10: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f80({{%[A-Za-z0-9._]+}}) {{.*}}: (f80) -> f80
|
||||
|
||||
! TODO: wait until fp128 is supported well in llvm.round
|
||||
|
||||
Reference in New Issue
Block a user