1315c88c5SSlava Zakharin! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s -check-prefixes=HONORINF,ALL 2*06eb10daSBrad Richardson! RUN: flang -fc1 -menable-no-infs -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s -check-prefixes=CHECK,ALL 369b3303eSValentin Clement 4315c88c5SSlava Zakharin! ALL-LABEL: func @_QPmodulo_testr( 5315c88c5SSlava Zakharin! ALL-SAME: %[[arg0:.*]]: !fir.ref<f64>{{.*}}, %[[arg1:.*]]: !fir.ref<f64>{{.*}}, %[[arg2:.*]]: !fir.ref<f64>{{.*}}) { 669b3303eSValentin Clementsubroutine modulo_testr(r, a, p) 769b3303eSValentin Clement real(8) :: r, a, p 8315c88c5SSlava Zakharin ! ALL-DAG: %[[a:.*]] = fir.load %[[arg1]] : !fir.ref<f64> 9315c88c5SSlava Zakharin ! ALL-DAG: %[[p:.*]] = fir.load %[[arg2]] : !fir.ref<f64> 10315c88c5SSlava Zakharin ! HONORINF: %[[res:.*]] = fir.call @_FortranAModuloReal8(%[[a]], %[[p]] 114cc9437aSTom Eccles ! CHECK-DAG: %[[rem:.*]] = arith.remf %[[a]], %[[p]] {{.*}}: f64 1269b3303eSValentin Clement ! CHECK-DAG: %[[zero:.*]] = arith.constant 0.000000e+00 : f64 13fcd06d77STom Eccles ! CHECK-DAG: %[[remNotZero:.*]] = arith.cmpf une, %[[rem]], %[[zero]] {{.*}} : f64 14fcd06d77STom Eccles ! CHECK-DAG: %[[aNeg:.*]] = arith.cmpf olt, %[[a]], %[[zero]] {{.*}} : f64 15fcd06d77STom Eccles ! CHECK-DAG: %[[pNeg:.*]] = arith.cmpf olt, %[[p]], %[[zero]] {{.*}} : f64 1669b3303eSValentin Clement ! CHECK-DAG: %[[signDifferent:.*]] = arith.xori %[[aNeg]], %[[pNeg]] : i1 1769b3303eSValentin Clement ! CHECK-DAG: %[[mustAddP:.*]] = arith.andi %[[remNotZero]], %[[signDifferent]] : i1 184cc9437aSTom Eccles ! CHECK-DAG: %[[remPlusP:.*]] = arith.addf %[[rem]], %[[p]] {{.*}}: f64 1969b3303eSValentin Clement ! CHECK: %[[res:.*]] = arith.select %[[mustAddP]], %[[remPlusP]], %[[rem]] : f64 20315c88c5SSlava Zakharin ! ALL: fir.store %[[res]] to %[[arg0]] : !fir.ref<f64> 2169b3303eSValentin Clement r = modulo(a, p) 2269b3303eSValentin Clementend subroutine 2369b3303eSValentin Clement 24315c88c5SSlava Zakharin! ALL-LABEL: func @_QPmodulo_testi( 25315c88c5SSlava Zakharin! ALL-SAME: %[[arg0:.*]]: !fir.ref<i64>{{.*}}, %[[arg1:.*]]: !fir.ref<i64>{{.*}}, %[[arg2:.*]]: !fir.ref<i64>{{.*}}) { 2669b3303eSValentin Clementsubroutine modulo_testi(r, a, p) 2769b3303eSValentin Clement integer(8) :: r, a, p 2869b3303eSValentin Clement ! CHECK-DAG: %[[a:.*]] = fir.load %[[arg1]] : !fir.ref<i64> 2969b3303eSValentin Clement ! CHECK-DAG: %[[p:.*]] = fir.load %[[arg2]] : !fir.ref<i64> 3069b3303eSValentin Clement ! CHECK-DAG: %[[rem:.*]] = arith.remsi %[[a]], %[[p]] : i64 3169b3303eSValentin Clement ! CHECK-DAG: %[[argXor:.*]] = arith.xori %[[a]], %[[p]] : i64 3269b3303eSValentin Clement ! CHECK-DAG: %[[signDifferent:.*]] = arith.cmpi slt, %[[argXor]], %c0{{.*}} : i64 3369b3303eSValentin Clement ! CHECK-DAG: %[[remNotZero:.*]] = arith.cmpi ne, %[[rem]], %c0{{.*}} : i64 3469b3303eSValentin Clement ! CHECK-DAG: %[[mustAddP:.*]] = arith.andi %[[remNotZero]], %[[signDifferent]] : i1 3569b3303eSValentin Clement ! CHECK-DAG: %[[remPlusP:.*]] = arith.addi %[[rem]], %[[p]] : i64 3669b3303eSValentin Clement ! CHECK: %[[res:.*]] = arith.select %[[mustAddP]], %[[remPlusP]], %[[rem]] : i64 3769b3303eSValentin Clement ! CHECK: fir.store %[[res]] to %[[arg0]] : !fir.ref<i64> 3869b3303eSValentin Clement r = modulo(a, p) 3969b3303eSValentin Clementend subroutine 4069b3303eSValentin Clement 41286c3b50SSlava Zakharin! CHECK-LABEL: func @_QPmodulo_testr16( 42286c3b50SSlava Zakharin! CHECK-SAME: %[[arg0:.*]]: !fir.ref<f128>{{.*}}, %[[arg1:.*]]: !fir.ref<f128>{{.*}}, %[[arg2:.*]]: !fir.ref<f128>{{.*}}) { 43286c3b50SSlava Zakharinsubroutine modulo_testr16(r, a, p) 44286c3b50SSlava Zakharin real(16) :: r, a, p 4586293a7cSSlava Zakharin ! CHECK: fir.call @_FortranAModuloReal16({{.*}}){{.*}}: (f128, f128, !fir.ref<i8>, i32) -> f128 46286c3b50SSlava Zakharin r = modulo(a, p) 47286c3b50SSlava Zakharinend subroutine 48