1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: ishftc_test
4 function ishftc_test(i
, j
, k
)
5 ! CHECK-DAG: %[[result:.*]] = fir.alloca i32 {bindc_name = "ishftc_test"
6 ! CHECK-DAG: %[[i:.*]] = fir.load %arg0 : !fir.ref<i32>
7 ! CHECK-DAG: %[[j:.*]] = fir.load %arg1 : !fir.ref<i32>
8 ! CHECK-DAG: %[[k:.*]] = fir.load %arg2 : !fir.ref<i32>
9 ! CHECK-DAG: %[[VAL_7:.*]] = arith.constant 32 : i32
10 ! CHECK-DAG: %[[VAL_8:.*]] = arith.constant 0 : i32
11 ! CHECK-DAG: %[[VAL_9:.*]] = arith.constant -1 : i32
12 ! CHECK-DAG: %[[VAL_10:.*]] = arith.constant 31 : i32
13 ! CHECK: %[[VAL_11:.*]] = arith.shrsi %[[j]], %[[VAL_10]] : i32
14 ! CHECK: %[[VAL_12:.*]] = arith.xori %[[j]], %[[VAL_11]] : i32
15 ! CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_11]] : i32
16 ! CHECK: %[[VAL_14:.*]] = arith.subi %[[k]], %[[VAL_13]] : i32
17 ! CHECK: %[[VAL_15:.*]] = arith.cmpi eq, %[[j]], %[[VAL_8]] : i32
18 ! CHECK: %[[VAL_16:.*]] = arith.cmpi eq, %[[VAL_13]], %[[k]] : i32
19 ! CHECK: %[[VAL_17:.*]] = arith.ori %[[VAL_15]], %[[VAL_16]] : i1
20 ! CHECK: %[[VAL_18:.*]] = arith.cmpi sgt, %[[j]], %[[VAL_8]] : i32
21 ! CHECK: %[[VAL_19:.*]] = arith.select %[[VAL_18]], %[[VAL_13]], %[[VAL_14]] : i32
22 ! CHECK: %[[VAL_20:.*]] = arith.select %[[VAL_18]], %[[VAL_14]], %[[VAL_13]] : i32
23 ! CHECK: %[[VAL_21:.*]] = arith.cmpi ne, %[[k]], %[[VAL_7]] : i32
24 ! CHECK: %[[VAL_22:.*]] = arith.shrui %[[i]], %[[k]] : i32
25 ! CHECK: %[[VAL_23:.*]] = arith.shli %[[VAL_22]], %[[k]] : i32
26 ! CHECK: %[[VAL_24:.*]] = arith.select %[[VAL_21]], %[[VAL_23]], %[[VAL_8]] : i32
27 ! CHECK: %[[VAL_25:.*]] = arith.subi %[[VAL_7]], %[[VAL_19]] : i32
28 ! CHECK: %[[VAL_26:.*]] = arith.shrui %[[VAL_9]], %[[VAL_25]] : i32
29 ! CHECK: %[[VAL_27:.*]] = arith.shrui %[[i]], %[[VAL_20]] : i32
30 ! CHECK: %[[VAL_28:.*]] = arith.andi %[[VAL_27]], %[[VAL_26]] : i32
31 ! CHECK: %[[VAL_29:.*]] = arith.subi %[[VAL_7]], %[[VAL_20]] : i32
32 ! CHECK: %[[VAL_30:.*]] = arith.shrui %[[VAL_9]], %[[VAL_29]] : i32
33 ! CHECK: %[[VAL_31:.*]] = arith.andi %[[i]], %[[VAL_30]] : i32
34 ! CHECK: %[[VAL_32:.*]] = arith.shli %[[VAL_31]], %[[VAL_19]] : i32
35 ! CHECK: %[[VAL_33:.*]] = arith.ori %[[VAL_24]], %[[VAL_28]] : i32
36 ! CHECK: %[[VAL_34:.*]] = arith.ori %[[VAL_33]], %[[VAL_32]] : i32
37 ! CHECK: %[[VAL_35:.*]] = arith.select %[[VAL_17]], %[[i]], %[[VAL_34]] : i32
38 ! CHECK: fir.store %[[VAL_35]] to %[[result]] : !fir.ref<i32>
39 ! CHECK: %[[VAL_36:.*]] = fir.load %[[result]] : !fir.ref<i32>
40 ! CHECK: return %[[VAL_36]] : i32
41 ishftc_test
= ishftc(i
, j
, k
)
44 ! Test cases where the size argument presence can only be know at runtime
47 ! CHECK-LABEL: func @_QMtest_ishftcPdyn_optional_scalar(
48 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"},
49 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "shift"},
50 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "size", fir.optional}) {
51 subroutine dyn_optional_scalar(i
, shift
, size
)
52 integer, optional
:: size
54 print *, ishftc(i
, shift
, size
)
55 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
56 ! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
57 ! CHECK: %[[VAL_10:.*]] = fir.is_present %[[VAL_2]] : (!fir.ref<i32>) -> i1
58 ! CHECK: %[[VAL_11:.*]] = fir.if %[[VAL_10]] -> (i32) {
59 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
60 ! CHECK: fir.result %[[VAL_12]] : i32
62 ! CHECK: %[[VAL_13:.*]] = arith.constant 32 : i32
63 ! CHECK: fir.result %[[VAL_13]] : i32
65 ! CHECK: %[[VAL_17:.*]] = arith.constant 31 : i32
66 ! CHECK: %[[VAL_18:.*]] = arith.shrsi %[[VAL_9]], %[[VAL_17]] : i32
67 ! CHECK: %[[VAL_19:.*]] = arith.xori %[[VAL_9]], %[[VAL_18]] : i32
68 ! CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_19]], %[[VAL_18]] : i32
69 ! CHECK: %[[VAL_21:.*]] = arith.subi %[[VAL_11]], %[[VAL_20]] : i32
70 ! ... as in non optional case
73 ! CHECK-LABEL: func @_QMtest_ishftcPdyn_optional_array_scalar(
74 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "i"},
75 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "shift"},
76 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "size", fir.optional}) {
77 subroutine dyn_optional_array_scalar(i
, shift
, size
)
78 integer, optional
:: size
79 integer :: i(:), shift(:)
80 ! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
81 ! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
82 ! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_2]] : (!fir.ref<i32>) -> i1
83 ! CHECK: fir.do_loop %[[VAL_20:.*]] = %{{.*}} to %{{.*}}
84 ! CHECK: %[[VAL_22:.*]] = fir.array_fetch %[[VAL_10]], %[[VAL_20]] : (!fir.array<?xi32>, index) -> i32
85 ! CHECK: %[[VAL_23:.*]] = fir.array_fetch %[[VAL_11]], %[[VAL_20]] : (!fir.array<?xi32>, index) -> i32
86 ! CHECK: %[[VAL_24:.*]] = fir.if %[[VAL_12]] -> (i32) {
87 ! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
88 ! CHECK: fir.result %[[VAL_25]] : i32
90 ! CHECK: %[[VAL_26:.*]] = arith.constant 32 : i32
91 ! CHECK: fir.result %[[VAL_26]] : i32
93 ! ... as in non optional case
95 print *, ishftc(i
, shift
, size
)
98 ! CHECK-LABEL: func @_QMtest_ishftcPdyn_optional_array(
99 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "i"},
100 ! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "shift"},
101 ! CHECK-SAME: %[[VAL_2:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "size", fir.optional}) {
102 subroutine dyn_optional_array(i
, shift
, size
)
103 integer, optional
:: size(:)
104 integer :: i(:), shift(:)
105 ! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
106 ! CHECK: %[[VAL_11:.*]] = fir.array_load %[[VAL_1]] : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
107 ! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_2]] : (!fir.box<!fir.array<?xi32>>) -> i1
108 ! CHECK: %[[VAL_17:.*]] = arith.select %[[VAL_12]], %[[VAL_2]], %{{.*}} : !fir.box<!fir.array<?xi32>>
109 ! CHECK: %[[VAL_18:.*]] = fir.array_load %[[VAL_17]] {fir.optional} : (!fir.box<!fir.array<?xi32>>) -> !fir.array<?xi32>
110 ! CHECK: fir.do_loop %[[VAL_26:.*]] = %{{.*}} to %{{.*}}
111 ! CHECK: %[[VAL_28:.*]] = fir.array_fetch %[[VAL_10]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
112 ! CHECK: %[[VAL_29:.*]] = fir.array_fetch %[[VAL_11]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
113 ! CHECK: %[[VAL_30:.*]] = fir.if %[[VAL_12]] -> (i32) {
114 ! CHECK: %[[VAL_31:.*]] = fir.array_fetch %[[VAL_18]], %[[VAL_26]] : (!fir.array<?xi32>, index) -> i32
115 ! CHECK: fir.result %[[VAL_31]] : i32
117 ! CHECK: %[[VAL_32:.*]] = arith.constant 32 : i32
118 ! CHECK: fir.result %[[VAL_32]] : i32
120 ! ... as in non optional case
122 print *, ishftc(i
, shift
, size
)
127 integer :: i(4) = [333, 334, 335, 336]
128 integer :: shift(4) = [2, 1, -1, -2]
129 integer :: size(4) = [2, 4, 8, 16]
130 call dyn_optional_scalar(i(1), shift(1))
131 call dyn_optional_scalar(i(1), shift(1), size(1))
133 call dyn_optional_array_scalar(i
, shift
)
134 call dyn_optional_array_scalar(i
, shift
, size(1))
136 call dyn_optional_array(i
, shift
)
137 call dyn_optional_array(i
, shift
, size
)