1 ! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
4 ! CHECK-LABEL: shifta1_test
5 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i8>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i8>{{.*}}
6 subroutine shifta1_test(a
, b
, c
)
11 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i8>
12 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
14 ! CHECK: %[[C_BITS:.*]] = arith.constant 8 : i8
15 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i8
16 ! CHECK: %[[SHIFT_IS_BITWIDTH:.*]] = arith.cmpi eq, %[[B_CONV]], %[[C_BITS]] : i8
17 ! CHECK: %[[C0:.*]] = arith.constant 0 : i8
18 ! CHECK: %[[CM1:.*]] = arith.constant -1 : i8
19 ! CHECK: %[[IS_NEG:.*]] = arith.cmpi slt, %[[A_VAL]], %[[C0]] : i8
20 ! CHECK: %[[RES:.*]] = arith.select %[[IS_NEG]], %[[CM1]], %[[C0]] : i8
21 ! CHECK: %[[SHIFTED:.*]] = arith.shrsi %[[A_VAL]], %[[B_CONV]] : i8
22 ! CHECK: %{{.*}} = arith.select %[[SHIFT_IS_BITWIDTH]], %[[RES]], %[[SHIFTED]] : i8
23 end subroutine shifta1_test
25 ! CHECK-LABEL: shifta2_test
26 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i16>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i16>{{.*}}
27 subroutine shifta2_test(a
, b
, c
)
32 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i16>
33 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
35 ! CHECK: %[[C_BITS:.*]] = arith.constant 16 : i16
36 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i16
37 ! CHECK: %[[SHIFT_IS_BITWIDTH:.*]] = arith.cmpi eq, %[[B_CONV]], %[[C_BITS]] : i16
38 ! CHECK: %[[C0:.*]] = arith.constant 0 : i16
39 ! CHECK: %[[CM1:.*]] = arith.constant -1 : i16
40 ! CHECK: %[[IS_NEG:.*]] = arith.cmpi slt, %[[A_VAL]], %[[C0]] : i16
41 ! CHECK: %[[RES:.*]] = arith.select %[[IS_NEG]], %[[CM1]], %[[C0]] : i16
42 ! CHECK: %[[SHIFTED:.*]] = arith.shrsi %[[A_VAL]], %[[B_CONV]] : i16
43 ! CHECK: %{{.*}} = arith.select %[[SHIFT_IS_BITWIDTH]], %[[RES]], %[[SHIFTED]] : i16
44 end subroutine shifta2_test
46 ! CHECK-LABEL: shifta4_test
47 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i32>{{.*}}
48 subroutine shifta4_test(a
, b
, c
)
53 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
54 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
56 ! CHECK: %[[C_BITS:.*]] = arith.constant 32 : i32
57 ! CHECK: %[[SHIFT_IS_BITWIDTH:.*]] = arith.cmpi eq, %[[B_VAL]], %[[C_BITS]] : i32
58 ! CHECK: %[[C0:.*]] = arith.constant 0 : i32
59 ! CHECK: %[[CM1:.*]] = arith.constant -1 : i32
60 ! CHECK: %[[IS_NEG:.*]] = arith.cmpi slt, %[[A_VAL]], %[[C0]] : i32
61 ! CHECK: %[[RES:.*]] = arith.select %[[IS_NEG]], %[[CM1]], %[[C0]] : i32
62 ! CHECK: %[[SHIFTED:.*]] = arith.shrsi %[[A_VAL]], %[[B_VAL]] : i32
63 ! CHECK: %{{.*}} = arith.select %[[SHIFT_IS_BITWIDTH]], %[[RES]], %[[SHIFTED]] : i32
64 end subroutine shifta4_test
66 ! CHECK-LABEL: shifta8_test
67 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i64>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i64>{{.*}}
68 subroutine shifta8_test(a
, b
, c
)
73 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i64>
74 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
76 ! CHECK: %[[C_BITS:.*]] = arith.constant 64 : i64
77 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i64
78 ! CHECK: %[[SHIFT_IS_BITWIDTH:.*]] = arith.cmpi eq, %[[B_CONV]], %[[C_BITS]] : i64
79 ! CHECK: %[[C0:.*]] = arith.constant 0 : i64
80 ! CHECK: %[[CM1:.*]] = arith.constant -1 : i64
81 ! CHECK: %[[IS_NEG:.*]] = arith.cmpi slt, %[[A_VAL]], %[[C0]] : i64
82 ! CHECK: %[[RES:.*]] = arith.select %[[IS_NEG]], %[[CM1]], %[[C0]] : i64
83 ! CHECK: %[[SHIFTED:.*]] = arith.shrsi %[[A_VAL]], %[[B_CONV]] : i64
84 ! CHECK: %{{.*}} = arith.select %[[SHIFT_IS_BITWIDTH]], %[[RES]], %[[SHIFTED]] : i64
85 end subroutine shifta8_test
87 ! CHECK-LABEL: shifta16_test
88 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i128>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i128>{{.*}}
89 subroutine shifta16_test(a
, b
, c
)
94 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i128>
95 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
97 ! CHECK: %[[C_BITS:.*]] = arith.constant 128 : i128
98 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i128
99 ! CHECK: %[[SHIFT_IS_BITWIDTH:.*]] = arith.cmpi eq, %[[B_CONV]], %[[C_BITS]] : i128
100 ! CHECK: %[[C0:.*]] = arith.constant 0 : i128
101 ! CHECK: %[[CM1:.*]] = arith.constant {{.*}} : i128
102 ! CHECK: %[[IS_NEG:.*]] = arith.cmpi slt, %[[A_VAL]], %[[C0]] : i128
103 ! CHECK: %[[RES:.*]] = arith.select %[[IS_NEG]], %[[CM1]], %[[C0]] : i128
104 ! CHECK: %[[SHIFTED:.*]] = arith.shrsi %[[A_VAL]], %[[B_CONV]] : i128
105 ! CHECK: %{{.*}} = arith.select %[[SHIFT_IS_BITWIDTH]], %[[RES]], %[[SHIFTED]] : i128
106 end subroutine shifta16_test