1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
4 ! CHECK-LABEL: shiftr1_test
5 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i8>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i8>{{.*}}
6 subroutine shiftr1_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: %[[C_0:.*]] = arith.constant 0 : i8
16 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i8
17 ! CHECK: %[[UNDER:.*]] = arith.cmpi slt, %[[B_CONV]], %[[C_0]] : i8
18 ! CHECK: %[[OVER:.*]] = arith.cmpi sge, %[[B_CONV]], %[[C_BITS]] : i8
19 ! CHECK: %[[INVALID:.*]] = arith.ori %[[UNDER]], %[[OVER]] : i1
20 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[A_VAL]], %[[B_CONV]] : i8
21 ! CHECK: %[[RES:.*]] = arith.select %[[INVALID]], %[[C_0]], %[[SHIFT]] : i8
22 end subroutine shiftr1_test
24 ! CHECK-LABEL: shiftr2_test
25 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i16>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i16>{{.*}}
26 subroutine shiftr2_test(a
, b
, c
)
31 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i16>
32 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
34 ! CHECK: %[[C_BITS:.*]] = arith.constant 16 : i16
35 ! CHECK: %[[C_0:.*]] = arith.constant 0 : i16
36 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i16
37 ! CHECK: %[[UNDER:.*]] = arith.cmpi slt, %[[B_CONV]], %[[C_0]] : i16
38 ! CHECK: %[[OVER:.*]] = arith.cmpi sge, %[[B_CONV]], %[[C_BITS]] : i16
39 ! CHECK: %[[INVALID:.*]] = arith.ori %[[UNDER]], %[[OVER]] : i1
40 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[A_VAL]], %[[B_CONV]] : i16
41 ! CHECK: %[[RES:.*]] = arith.select %[[INVALID]], %[[C_0]], %[[SHIFT]] : i16
42 end subroutine shiftr2_test
44 ! CHECK-LABEL: shiftr4_test
45 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i32>{{.*}}
46 subroutine shiftr4_test(a
, b
, c
)
51 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
52 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
54 ! CHECK: %[[C_BITS:.*]] = arith.constant 32 : i32
55 ! CHECK: %[[C_0:.*]] = arith.constant 0 : i32
56 ! CHECK: %[[UNDER:.*]] = arith.cmpi slt, %[[B_VAL]], %[[C_0]] : i32
57 ! CHECK: %[[OVER:.*]] = arith.cmpi sge, %[[B_VAL]], %[[C_BITS]] : i32
58 ! CHECK: %[[INVALID:.*]] = arith.ori %[[UNDER]], %[[OVER]] : i1
59 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[A_VAL]], %[[B_VAL]] : i32
60 ! CHECK: %[[RES:.*]] = arith.select %[[INVALID]], %[[C_0]], %[[SHIFT]] : i32
61 end subroutine shiftr4_test
63 ! CHECK-LABEL: shiftr8_test
64 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i64>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i64>{{.*}}
65 subroutine shiftr8_test(a
, b
, c
)
70 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i64>
71 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
73 ! CHECK: %[[C_BITS:.*]] = arith.constant 64 : i64
74 ! CHECK: %[[C_0:.*]] = arith.constant 0 : i64
75 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i64
76 ! CHECK: %[[UNDER:.*]] = arith.cmpi slt, %[[B_CONV]], %[[C_0]] : i64
77 ! CHECK: %[[OVER:.*]] = arith.cmpi sge, %[[B_CONV]], %[[C_BITS]] : i64
78 ! CHECK: %[[INVALID:.*]] = arith.ori %[[UNDER]], %[[OVER]] : i1
79 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[A_VAL]], %[[B_CONV]] : i64
80 ! CHECK: %[[RES:.*]] = arith.select %[[INVALID]], %[[C_0]], %[[SHIFT]] : i64
81 end subroutine shiftr8_test
83 ! CHECK-LABEL: shiftr16_test
84 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i128>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i128>{{.*}}
85 subroutine shiftr16_test(a
, b
, c
)
90 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i128>
91 ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
93 ! CHECK: %[[C_BITS:.*]] = arith.constant 128 : i128
94 ! CHECK: %[[C_0:.*]] = arith.constant 0 : i128
95 ! CHECK: %[[B_CONV:.*]] = fir.convert %[[B_VAL]] : (i32) -> i128
96 ! CHECK: %[[UNDER:.*]] = arith.cmpi slt, %[[B_CONV]], %[[C_0]] : i128
97 ! CHECK: %[[OVER:.*]] = arith.cmpi sge, %[[B_CONV]], %[[C_BITS]] : i128
98 ! CHECK: %[[INVALID:.*]] = arith.ori %[[UNDER]], %[[OVER]] : i1
99 ! CHECK: %[[SHIFT:.*]] = arith.shrui %[[A_VAL]], %[[B_CONV]] : i128
100 ! CHECK: %[[RES:.*]] = arith.select %[[INVALID]], %[[C_0]], %[[SHIFT]] : i128
101 end subroutine shiftr16_test