! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s -check-prefixes=HONORINF,ALL ! RUN: %flang_fc1 -menable-no-infs -emit-hlfir %s -o - | FileCheck %s -check-prefixes=CHECK,ALL,%if flang-supports-f128-math %{F128%} %else %{F64%} ! ALL-LABEL: func @_QPmodulo_testr( ! ALL-SAME: %[[arg0:.*]]: !fir.ref{{.*}}, %[[arg1:.*]]: !fir.ref{{.*}}, %[[arg2:.*]]: !fir.ref{{.*}}) { subroutine modulo_testr(r, a, p) real(8) :: r, a, p ! ALL: %[[a_decl:.*]]:2 = hlfir.declare %[[arg1]] {{.*}} {uniq_name = "_QFmodulo_testrEa"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL: %[[p_decl:.*]]:2 = hlfir.declare %[[arg2]] {{.*}} {uniq_name = "_QFmodulo_testrEp"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL: %[[r_decl:.*]]:2 = hlfir.declare %[[arg0]] {{.*}} {uniq_name = "_QFmodulo_testrEr"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL-DAG: %[[a:.*]] = fir.load %[[a_decl]]#0 : !fir.ref ! ALL-DAG: %[[p:.*]] = fir.load %[[p_decl]]#0 : !fir.ref ! HONORINF: %[[res:.*]] = fir.call @_FortranAModuloReal8(%[[a]], %[[p]] ! CHECK-DAG: %[[rem:.*]] = arith.remf %[[a]], %[[p]] {{.*}}: f64 ! CHECK-DAG: %[[zero:.*]] = arith.constant 0.000000e+00 : f64 ! CHECK-DAG: %[[remNotZero:.*]] = arith.cmpf une, %[[rem]], %[[zero]] {{.*}} : f64 ! CHECK-DAG: %[[aNeg:.*]] = arith.cmpf olt, %[[a]], %[[zero]] {{.*}} : f64 ! CHECK-DAG: %[[pNeg:.*]] = arith.cmpf olt, %[[p]], %[[zero]] {{.*}} : f64 ! CHECK-DAG: %[[signDifferent:.*]] = arith.xori %[[aNeg]], %[[pNeg]] : i1 ! CHECK-DAG: %[[mustAddP:.*]] = arith.andi %[[remNotZero]], %[[signDifferent]] : i1 ! CHECK-DAG: %[[remPlusP:.*]] = arith.addf %[[rem]], %[[p]] {{.*}}: f64 ! CHECK: %[[res:.*]] = arith.select %[[mustAddP]], %[[remPlusP]], %[[rem]] : f64 ! ALL: hlfir.assign %[[res]] to %[[r_decl]]#0 : f64, !fir.ref r = modulo(a, p) end subroutine ! ALL-LABEL: func @_QPmodulo_testi( ! ALL-SAME: %[[arg0:.*]]: !fir.ref{{.*}}, %[[arg1:.*]]: !fir.ref{{.*}}, %[[arg2:.*]]: !fir.ref{{.*}}) { subroutine modulo_testi(r, a, p) integer(8) :: r, a, p ! ALL: %[[a_decl:.*]]:2 = hlfir.declare %[[arg1]] {{.*}} {uniq_name = "_QFmodulo_testiEa"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL: %[[p_decl:.*]]:2 = hlfir.declare %[[arg2]] {{.*}} {uniq_name = "_QFmodulo_testiEp"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL: %[[r_decl:.*]]:2 = hlfir.declare %[[arg0]] {{.*}} {uniq_name = "_QFmodulo_testiEr"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) ! ALL-DAG: %[[a:.*]] = fir.load %[[a_decl]]#0 : !fir.ref ! ALL-DAG: %[[p:.*]] = fir.load %[[p_decl]]#0 : !fir.ref ! ALL-DAG: %[[rem:.*]] = arith.remsi %[[a]], %[[p]] : i64 ! ALL-DAG: %[[argXor:.*]] = arith.xori %[[a]], %[[p]] : i64 ! ALL-DAG: %[[signDifferent:.*]] = arith.cmpi slt, %[[argXor]], %c0{{.*}} : i64 ! ALL-DAG: %[[remNotZero:.*]] = arith.cmpi ne, %[[rem]], %c0{{.*}} : i64 ! ALL-DAG: %[[mustAddP:.*]] = arith.andi %[[remNotZero]], %[[signDifferent]] : i1 ! ALL-DAG: %[[remPlusP:.*]] = arith.addi %[[rem]], %[[p]] : i64 ! ALL: %[[res:.*]] = arith.select %[[mustAddP]], %[[remPlusP]], %[[rem]] : i64 ! ALL: hlfir.assign %[[res]] to %[[r_decl]]#0 : i64, !fir.ref r = modulo(a, p) end subroutine ! CHECK-LABEL: func @_QPmodulo_testr16( ! F128-SAME: %[[arg0:.*]]: !fir.ref{{.*}}, %[[arg1:.*]]: !fir.ref{{.*}}, %[[arg2:.*]]: !fir.ref{{.*}}) { ! F64-SAME: %[[arg0:.*]]: !fir.ref{{.*}}, %[[arg1:.*]]: !fir.ref{{.*}}, %[[arg2:.*]]: !fir.ref{{.*}}) { subroutine modulo_testr16(r, a, p) integer, parameter :: rk = merge(16, 8, selected_real_kind(33, 4931)==16) real(rk) :: r, a, p !F128: fir.call @_FortranAModuloReal16({{.*}}){{.*}}: (f128, f128, !fir.ref, i32) -> f128 !F64: arith.remf %{{.*}}, %{{.*}} fastmath : f64 r = modulo(a, p) end subroutine