1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
4 ! CHECK-LABEL: maskr_test
5 subroutine maskr_test(a
, b
)
8 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 32 : i32
9 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i32
10 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i32
11 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
12 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
14 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
16 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_VAL]] : i32
17 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i32
18 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_VAL]], %[[C__0]] : i32
19 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i32
20 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i32>
21 end subroutine maskr_test
23 ! CHECK-LABEL: maskr1_test
24 subroutine maskr1_test(a
, b
)
27 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 8 : i8
28 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i8
29 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i8
30 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
31 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
33 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
35 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i8
36 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i8
37 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i8
38 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i8
39 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i8
40 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i8>
41 end subroutine maskr1_test
43 ! CHECK-LABEL: maskr2_test
44 subroutine maskr2_test(a
, b
)
47 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 16 : i16
48 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i16
49 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i16
50 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
51 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
53 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
55 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i16
56 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i16
57 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i16
58 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i16
59 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i16
60 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i16>
61 end subroutine maskr2_test
63 ! CHECK-LABEL: maskr4_test
64 subroutine maskr4_test(a
, b
)
67 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 32 : i32
68 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i32
69 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i32
70 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
71 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
73 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
75 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_VAL]] : i32
76 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i32
77 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_VAL]], %[[C__0]] : i32
78 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i32
79 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i32>
80 end subroutine maskr4_test
82 ! CHECK-LABEL: maskr8_test
83 subroutine maskr8_test(a
, b
)
86 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 64 : i64
87 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i64
88 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i64
89 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
90 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
92 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
94 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i64
95 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i64
96 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i64
97 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i64
98 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i64
99 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i64>
100 end subroutine maskr8_test
102 subroutine maskr16_test(a
, b
)
105 ! CHECK-DAG: %[[BITS:.*]] = arith.constant 128 : i128
106 ! CHECK-DAG: %[[C__1:.*]] = arith.constant -1 : i128
107 ! CHECK-DAG: %[[C__0:.*]] = arith.constant 0 : i128
108 ! CHECK: %[[A:.*]] = fir.declare %{{.*}}Ea
109 ! CHECK: %[[B:.*]] = fir.declare %{{.*}}Eb
111 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
113 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i128
114 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i128
115 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[C__1]], %[[LEN]] : i128
116 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i128
117 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i128
118 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i128>