136 lines · plain
1! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s2 3#ifndef RK4#define RK 85#endif6 7module m8 integer, parameter :: k = RK9 character(20) :: tag(11)10contains11 ! CHECK-LABEL: func @_QMmPinit12 subroutine init13 tag( 1) = 'signaling_nan'; tag( 2) = 'quiet_nan'14 tag( 3) = 'negative_inf'; tag( 4) = 'negative_normal'15 tag( 5) = 'negative_denormal'; tag( 6) = 'negative_zero'16 tag( 7) = 'positive_zero'; tag( 8) = 'positive_denormal'17 tag( 9) = 'positive_normal'; tag(10) = 'positive_inf'18 tag(11) = 'other_value'19 end20 ! CHECK-LABEL: func @_QMmPout21 subroutine out(x,v)22 use ieee_arithmetic23 real(k) :: x24 integer :: v25 logical :: L(4)26 L(1) = ieee_is_finite(x)27 L(2) = ieee_is_nan(x)28 L(3) = ieee_is_negative(x)29 L(4) = ieee_is_normal(x)30! if (k== 2) print "(' k=2 ',f7.2,z6.4, i4,': ',a18,4L2)", x,x, v, tag(v), L31! if (k== 3) print "(' k=3 ',f7.2,z6.4, i4,': ',a18,4L2)", x,x, v, tag(v), L32! if (k== 4) print "(' k=4 ',f7.2,z10.8, i4,': ',a18,4L2)", x,x, v, tag(v), L33 if (k== 8) print "(' k=8 ',f7.2,z18.16,i4,': ',a18,4L2)", x,x, v, tag(v), L34! if (k==10) print "(' k=10',f7.2,z22.20,i4,': ',a18,4L2)", x,x, v, tag(v), L35! if (k==16) print "(' k=16',f7.2,z34.32,i4,': ',a18,4L2)", x,x, v, tag(v), L36 end37end module m38 39! CHECK-LABEL: func @_QPclassify40subroutine classify(x)41 use m; use ieee_arithmetic42 real(k) :: x43 ! CHECK-DAG: %[[V_0:[0-9]+]] = fir.alloca i32 {adapt.valuebyref}44 ! CHECK-DAG: %[[V_1:[0-9]+]] = fir.alloca !fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>45 ! CHECK-DAG: %[[V_2:[0-9]+]] = fir.alloca !fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}> {bindc_name = "r", uniq_name = "_QFclassifyEr"}46 type(ieee_class_type) :: r47 48 ! CHECK: %[[V_8:[0-9]+]] = fir.load %arg0 : !fir.ref<f64>49 ! CHECK: %[[V_9:[0-9]+]] = arith.bitcast %[[V_8]] : f64 to i6450 ! CHECK: %[[V_10:[0-9]+]] = arith.shrui %[[V_9]], %c59{{.*}} : i6451 ! CHECK: %[[V_11:[0-9]+]] = arith.andi %[[V_10]], %c16{{.*}} : i6452 ! CHECK: %[[V_12:[0-9]+]] = arith.andi %[[V_9]], %c9218868437227405312{{.*}} : i6453 ! CHECK: %[[V_13:[0-9]+]] = arith.cmpi ne, %[[V_12]], %c0{{.*}} : i6454 ! CHECK: %[[V_14:[0-9]+]] = arith.select %[[V_13]], %c8{{.*}}, %c0{{.*}} : i6455 ! CHECK: %[[V_15:[0-9]+]] = arith.ori %[[V_11]], %[[V_14]] : i6456 ! CHECK: %[[V_16:[0-9]+]] = arith.cmpi eq, %[[V_12]], %c9218868437227405312{{.*}} : i6457 ! CHECK: %[[V_17:[0-9]+]] = arith.select %[[V_16]], %c4{{.*}}, %c0{{.*}} : i6458 ! CHECK: %[[V_18:[0-9]+]] = arith.ori %[[V_15]], %[[V_17]] : i6459 ! CHECK: %[[V_19:[0-9]+]] = arith.andi %[[V_9]], %c2251799813685247{{.*}} : i6460 ! CHECK: %[[V_20:[0-9]+]] = arith.cmpi ne, %[[V_19]], %c0{{.*}} : i6461 ! CHECK: %[[V_21:[0-9]+]] = arith.select %[[V_20]], %c2{{.*}}, %c0{{.*}} : i6462 ! CHECK: %[[V_22:[0-9]+]] = arith.ori %[[V_18]], %[[V_21]] : i6463 ! CHECK: %[[V_23:[0-9]+]] = arith.shrui %[[V_9]], %c51{{.*}} : i6464 ! CHECK: %[[V_24:[0-9]+]] = arith.andi %[[V_23]], %c1{{.*}} : i6465 ! CHECK: %[[V_25:[0-9]+]] = arith.ori %[[V_22]], %[[V_24]] : i6466 ! CHECK: %[[V_26:[0-9]+]] = fir.address_of(@_FortranAIeeeClassTable) : !fir.ref<!fir.array<32xi8>>67 ! CHECK: %[[V_27:[0-9]+]] = fir.coordinate_of %[[V_26]], %[[V_25]] : (!fir.ref<!fir.array<32xi8>>, i64) -> !fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>68 ! CHECK: %[[V_29:[0-9]+]] = fir.coordinate_of %[[V_27]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>69 ! CHECK: %[[V_31:[0-9]+]] = fir.coordinate_of %[[V_2]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>70 ! CHECK: %[[V_32:[0-9]+]] = fir.load %[[V_29]] : !fir.ref<i8>71 ! CHECK: fir.store %[[V_32]] to %[[V_31]] : !fir.ref<i8>72 r = ieee_class(x)73 74! if (r==ieee_signaling_nan) call out(x, 1)75! if (r==ieee_quiet_nan) call out(x, 2)76 ! CHECK: %[[V_39:[0-9]+]] = fir.coordinate_of %[[V_1]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>77 ! CHECK: fir.store %c3{{.*}} to %[[V_39]] : !fir.ref<i8>78 ! CHECK: %[[V_41:[0-9]+]] = fir.coordinate_of %[[V_2]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>79 ! CHECK: %[[V_43:[0-9]+]] = fir.coordinate_of %[[V_1]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>80 ! CHECK: %[[V_44:[0-9]+]] = fir.load %[[V_41]] : !fir.ref<i8>81 ! CHECK: %[[V_45:[0-9]+]] = fir.load %[[V_43]] : !fir.ref<i8>82 ! CHECK: %[[V_46:[0-9]+]] = arith.cmpi eq, %[[V_44]], %[[V_45]] : i883 ! CHECK: fir.if %[[V_46]] {84 ! CHECK: fir.store %c3{{.*}} to %[[V_0]] : !fir.ref<i32>85 ! CHECK: fir.call @_QMmPout(%arg0, %[[V_0]]) {{.*}} : (!fir.ref<f64>, !fir.ref<i32>) -> ()86 ! CHECK: }87 if (r==ieee_negative_inf) call out(x, 3)88! if (r==ieee_negative_normal) call out(x, 4)89! if (r==ieee_negative_denormal) call out(x, 5)90! if (r==ieee_negative_zero) call out(x, 6)91! if (r==ieee_positive_zero) call out(x, 7)92! if (r==ieee_positive_denormal) call out(x, 8)93! if (r==ieee_positive_normal) call out(x, 9)94! if (r==ieee_positive_inf) call out(x,10)95! if (r==ieee_other_value) call out(x,11)96end97 98! CHECK-LABEL: func @_QQmain99program p100 use m; use ieee_arithmetic101 real(k) :: x(10)102 103 call init104 105! x(1) = ieee_value(x(1), ieee_signaling_nan)106! x(2) = ieee_value(x(1), ieee_quiet_nan)107 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca !fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>108 ! CHECK: %[[V_2:[0-9]+]] = fir.address_of(@_QFEx) : !fir.ref<!fir.array<10xf64>>109 ! CHECK: %[[V_9:[0-9]+]] = fir.coordinate_of %[[V_0]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>110 ! CHECK: fir.store %c3{{.*}} to %[[V_9]] : !fir.ref<i8>111 ! CHECK: %[[V_11:[0-9]+]] = fir.coordinate_of %[[V_0]], _QMieee_arithmeticTieee_class_type.which : (!fir.ref<!fir.type<_QMieee_arithmeticTieee_class_type{_QMieee_arithmeticTieee_class_type.which:i8}>>) -> !fir.ref<i8>112 ! CHECK: %[[V_12:[0-9]+]] = fir.load %[[V_11]] : !fir.ref<i8>113 ! CHECK: %[[V_13:[0-9]+]] = fir.address_of(@_FortranAIeeeValueTable_8) : !fir.ref<!fir.array<12xi64>>114 ! CHECK: %[[V_14:[0-9]+]] = fir.coordinate_of %[[V_13]], %[[V_12]] : (!fir.ref<!fir.array<12xi64>>, i8) -> !fir.ref<i64>115 ! CHECK: %[[V_15:[0-9]+]] = fir.load %[[V_14]] : !fir.ref<i64>116 ! CHECK: %[[V_16:[0-9]+]] = arith.bitcast %[[V_15]] : i64 to f64117 ! CHECK: %[[V_17:[0-9]+]] = arith.subi %c3{{.*}}, %c1{{.*}} : i64118 ! CHECK: %[[V_18:[0-9]+]] = fir.coordinate_of %[[V_2]], %[[V_17]] : (!fir.ref<!fir.array<10xf64>>, i64) -> !fir.ref<f64>119 ! CHECK: fir.store %[[V_16]] to %[[V_18]] : !fir.ref<f64>120 x(3) = ieee_value(x(1), ieee_negative_inf)121! x(4) = ieee_value(x(1), ieee_negative_normal)122! x(5) = ieee_value(x(1), ieee_negative_subnormal)123! x(6) = ieee_value(x(1), ieee_negative_zero)124! x(7) = ieee_value(x(1), ieee_positive_zero)125! x(8) = ieee_value(x(1), ieee_positive_subnormal)126! x(9) = ieee_value(x(1), ieee_positive_normal)127! x(10) = ieee_value(x(1), ieee_positive_inf)128 129 do i = 1,10130 call classify(x(i))131 enddo132end133 134! CHECK: fir.global linkonce @_FortranAIeeeClassTable(dense<[7, 8, 8, 8, 11, 11, 11, 11, 9, 9, 9, 9, 10, 2, 1, 2, 6, 5, 5, 5, 11, 11, 11, 11, 4, 4, 4, 4, 3, 2, 1, 2]> : tensor<32xi8>) constant : !fir.array<32xi8>135! CHECK: fir.global linkonce @_FortranAIeeeValueTable_8(dense<[0, 9219994337134247936, 9221120237041090560, -4503599627370496, -4616189618054758400, -9221120237041090560, -9223372036854775808, 0, 2251799813685248, 4607182418800017408, 9218868437227405312, 0]> : tensor<12xi64>) constant : !fir.array<12xi64>136