xref: /llvm-project/flang/test/Lower/Intrinsics/dshiftl.f90 (revision f35f863a88f83332bef9605ef4cfe4f05c066efb)
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
3
4! CHECK-LABEL: dshiftl1_test
5! CHECK-SAME: %[[A:.*]]: !fir.ref<i8>{{.*}}, %[[B:.*]]: !fir.ref<i8>{{.*}}, %[[S:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i8>{{.*}}
6subroutine dshiftl1_test(a, b, s, c)
7  integer(kind=1) :: a, b
8  integer :: s
9  integer(kind=1) :: c
10
11  ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i8>
12  ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i8>
13  ! CHECK: %[[S_VAL:.*]] = fir.load %[[S]] : !fir.ref<i32>
14  c = dshiftl(a, b, s)
15  ! CHECK: %[[S_CONV:.*]] = fir.convert %[[S_VAL]] : (i32) -> i8
16  ! CHECK: %[[C_BITS:.*]] = arith.constant 8 : i8
17  ! CHECK: %[[DIFF:.*]] = arith.subi %[[C_BITS]], %[[S_CONV]] : i8
18  ! CHECK: %[[C_BITS_L:.*]] = arith.constant 8 : i8
19  ! CHECK: %[[C_0_L:.*]] = arith.constant 0 : i8
20  ! CHECK: %[[UNDER_L:.*]] = arith.cmpi slt, %[[S_CONV]], %[[C_0_L]] : i8
21  ! CHECK: %[[OVER_L:.*]] = arith.cmpi sge, %[[S_CONV]], %[[C_BITS_L]] : i8
22  ! CHECK: %[[INV_L:.*]] = arith.ori %[[UNDER_L]], %[[OVER_L]] : i1
23  ! CHECK: %[[SHL:.*]] = arith.shli %[[A_VAL]], %[[S_CONV]] : i8
24  ! CHECK: %[[LFT:.*]] = arith.select %[[INV_L]], %[[C_0_L]], %[[SHL]] : i8
25  ! CHECK: %[[C_BITS_R:.*]] = arith.constant 8 : i8
26  ! CHECK: %[[C_0_R:.*]] = arith.constant 0 : i8
27  ! CHECK: %[[UNDER_R:.*]] = arith.cmpi slt, %[[DIFF]], %[[C_0_R]] : i8
28  ! CHECK: %[[OVER_R:.*]] = arith.cmpi sge, %[[DIFF]], %[[C_BITS_R]] : i8
29  ! CHECK: %[[INV_R:.*]] = arith.ori %[[UNDER_R]], %[[OVER_R]] : i1
30  ! CHECK: %[[SHR:.*]] = arith.shrui %[[B_VAL]], %[[DIFF]] : i8
31  ! CHECK: %[[RGT:.*]] = arith.select %[[INV_R]], %[[C_0_R]], %[[SHR]] : i8
32  ! CHECK: %[[SHIFT:.*]] = arith.ori %[[LFT]], %[[RGT]] : i8
33end subroutine dshiftl1_test
34
35! CHECK-LABEL: dshiftl2_test
36! CHECK-SAME: %[[A:.*]]: !fir.ref<i16>{{.*}}, %[[B:.*]]: !fir.ref<i16>{{.*}}, %[[S:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i16>{{.*}}
37subroutine dshiftl2_test(a, b, s, c)
38  integer(kind=2) :: a, b
39  integer :: s
40  integer(kind=2) :: c
41
42  ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i16>
43  ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i16>
44  ! CHECK: %[[S_VAL:.*]] = fir.load %[[S]] : !fir.ref<i32>
45  c = dshiftl(a, b, s)
46  ! CHECK: %[[S_CONV:.*]] = fir.convert %[[S_VAL]] : (i32) -> i16
47  ! CHECK: %[[C_BITS:.*]] = arith.constant 16 : i16
48  ! CHECK: %[[DIFF:.*]] = arith.subi %[[C_BITS]], %[[S_CONV]] : i16
49  ! CHECK: %[[C_BITS_L:.*]] = arith.constant 16 : i16
50  ! CHECK: %[[C_0_L:.*]] = arith.constant 0 : i16
51  ! CHECK: %[[UNDER_L:.*]] = arith.cmpi slt, %[[S_CONV]], %[[C_0_L]] : i16
52  ! CHECK: %[[OVER_L:.*]] = arith.cmpi sge, %[[S_CONV]], %[[C_BITS_L]] : i16
53  ! CHECK: %[[INV_L:.*]] = arith.ori %[[UNDER_L]], %[[OVER_L]] : i1
54  ! CHECK: %[[SHL:.*]] = arith.shli %[[A_VAL]], %[[S_CONV]] : i16
55  ! CHECK: %[[LFT:.*]] = arith.select %[[INV_L]], %[[C_0_L]], %[[SHL]] : i16
56  ! CHECK: %[[C_BITS_R:.*]] = arith.constant 16 : i16
57  ! CHECK: %[[C_0_R:.*]] = arith.constant 0 : i16
58  ! CHECK: %[[UNDER_R:.*]] = arith.cmpi slt, %[[DIFF]], %[[C_0_R]] : i16
59  ! CHECK: %[[OVER_R:.*]] = arith.cmpi sge, %[[DIFF]], %[[C_BITS_R]] : i16
60  ! CHECK: %[[INV_R:.*]] = arith.ori %[[UNDER_R]], %[[OVER_R]] : i1
61  ! CHECK: %[[SHR:.*]] = arith.shrui %[[B_VAL]], %[[DIFF]] : i16
62  ! CHECK: %[[RGT:.*]] = arith.select %[[INV_R]], %[[C_0_R]], %[[SHR]] : i16
63  ! CHECK: %[[SHIFT:.*]] = arith.ori %[[LFT]], %[[RGT]] : i16
64end subroutine dshiftl2_test
65
66! CHECK-LABEL: dshiftl4_test
67! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[S:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i32>{{.*}}
68subroutine dshiftl4_test(a, b, s, c)
69  integer(kind=4) :: a, b
70  integer :: s
71  integer(kind=4) :: c
72
73  ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
74  ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32>
75  ! CHECK: %[[S_VAL:.*]] = fir.load %[[S]] : !fir.ref<i32>
76  c = dshiftl(a, b, s)
77  ! CHECK: %[[C_BITS:.*]] = arith.constant 32 : i32
78  ! CHECK: %[[DIFF:.*]] = arith.subi %[[C_BITS]], %[[S_VAL]] : i32
79  ! CHECK: %[[C_BITS_L:.*]] = arith.constant 32 : i32
80  ! CHECK: %[[C_0_L:.*]] = arith.constant 0 : i32
81  ! CHECK: %[[UNDER_L:.*]] = arith.cmpi slt, %[[S_VAL]], %[[C_0_L]] : i32
82  ! CHECK: %[[OVER_L:.*]] = arith.cmpi sge, %[[S_VAL]], %[[C_BITS_L]] : i32
83  ! CHECK: %[[INV_L:.*]] = arith.ori %[[UNDER_L]], %[[OVER_L]] : i1
84  ! CHECK: %[[SHL:.*]] = arith.shli %[[A_VAL]], %[[S_VAL]] : i32
85  ! CHECK: %[[LFT:.*]] = arith.select %[[INV_L]], %[[C_0_L]], %[[SHL]] : i32
86  ! CHECK: %[[C_BITS_R:.*]] = arith.constant 32 : i32
87  ! CHECK: %[[C_0_R:.*]] = arith.constant 0 : i32
88  ! CHECK: %[[UNDER_R:.*]] = arith.cmpi slt, %[[DIFF]], %[[C_0_R]] : i32
89  ! CHECK: %[[OVER_R:.*]] = arith.cmpi sge, %[[DIFF]], %[[C_BITS_R]] : i32
90  ! CHECK: %[[INV_R:.*]] = arith.ori %[[UNDER_R]], %[[OVER_R]] : i1
91  ! CHECK: %[[SHR:.*]] = arith.shrui %[[B_VAL]], %[[DIFF]] : i32
92  ! CHECK: %[[RGT:.*]] = arith.select %[[INV_R]], %[[C_0_R]], %[[SHR]] : i32
93  ! CHECK: %[[SHIFT:.*]] = arith.ori %[[LFT]], %[[RGT]] : i32
94end subroutine dshiftl4_test
95
96! CHECK-LABEL: dshiftl8_test
97! CHECK-SAME: %[[A:.*]]: !fir.ref<i64>{{.*}}, %[[B:.*]]: !fir.ref<i64>{{.*}}, %[[S:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i64>{{.*}}
98subroutine dshiftl8_test(a, b, s, c)
99  integer(kind=8) :: a, b
100  integer :: s
101  integer(kind=8) :: c
102
103  ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i64>
104  ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i64>
105  ! CHECK: %[[S_VAL:.*]] = fir.load %[[S]] : !fir.ref<i32>
106  c = dshiftl(a, b, s)
107  ! CHECK: %[[S_CONV:.*]] = fir.convert %[[S_VAL]] : (i32) -> i64
108  ! CHECK: %[[C_BITS:.*]] = arith.constant 64 : i64
109  ! CHECK: %[[DIFF:.*]] = arith.subi %[[C_BITS]], %[[S_CONV]] : i64
110  ! CHECK: %[[C_BITS_L:.*]] = arith.constant 64 : i64
111  ! CHECK: %[[C_0_L:.*]] = arith.constant 0 : i64
112  ! CHECK: %[[UNDER_L:.*]] = arith.cmpi slt, %[[S_CONV]], %[[C_0_L]] : i64
113  ! CHECK: %[[OVER_L:.*]] = arith.cmpi sge, %[[S_CONV]], %[[C_BITS_L]] : i64
114  ! CHECK: %[[INV_L:.*]] = arith.ori %[[UNDER_L]], %[[OVER_L]] : i1
115  ! CHECK: %[[SHL:.*]] = arith.shli %[[A_VAL]], %[[S_CONV]] : i64
116  ! CHECK: %[[LFT:.*]] = arith.select %[[INV_L]], %[[C_0_L]], %[[SHL]] : i64
117  ! CHECK: %[[C_BITS_R:.*]] = arith.constant 64 : i64
118  ! CHECK: %[[C_0_R:.*]] = arith.constant 0 : i64
119  ! CHECK: %[[UNDER_R:.*]] = arith.cmpi slt, %[[DIFF]], %[[C_0_R]] : i64
120  ! CHECK: %[[OVER_R:.*]] = arith.cmpi sge, %[[DIFF]], %[[C_BITS_R]] : i64
121  ! CHECK: %[[INV_R:.*]] = arith.ori %[[UNDER_R]], %[[OVER_R]] : i1
122  ! CHECK: %[[SHR:.*]] = arith.shrui %[[B_VAL]], %[[DIFF]] : i64
123  ! CHECK: %[[RGT:.*]] = arith.select %[[INV_R]], %[[C_0_R]], %[[SHR]] : i64
124  ! CHECK: %[[SHIFT:.*]] = arith.ori %[[LFT]], %[[RGT]] : i64
125end subroutine dshiftl8_test
126
127! CHECK-LABEL: dshiftl16_test
128! CHECK-SAME: %[[A:.*]]: !fir.ref<i128>{{.*}}, %[[B:.*]]: !fir.ref<i128>{{.*}}, %[[S:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i128>{{.*}}
129subroutine dshiftl16_test(a, b, s, c)
130  integer(kind=16) :: a, b
131  integer :: s
132  integer(kind=16) :: c
133
134  ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i128>
135  ! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i128>
136  ! CHECK: %[[S_VAL:.*]] = fir.load %[[S]] : !fir.ref<i32>
137  c = dshiftl(a, b, s)
138  ! CHECK: %[[S_CONV:.*]] = fir.convert %[[S_VAL]] : (i32) -> i128
139  ! CHECK: %[[C_BITS:.*]] = arith.constant 128 : i128
140  ! CHECK: %[[DIFF:.*]] = arith.subi %[[C_BITS]], %[[S_CONV]] : i128
141  ! CHECK: %[[C_BITS_L:.*]] = arith.constant 128 : i128
142  ! CHECK: %[[C_0_L:.*]] = arith.constant 0 : i128
143  ! CHECK: %[[UNDER_L:.*]] = arith.cmpi slt, %[[S_CONV]], %[[C_0_L]] : i128
144  ! CHECK: %[[OVER_L:.*]] = arith.cmpi sge, %[[S_CONV]], %[[C_BITS_L]] : i128
145  ! CHECK: %[[INV_L:.*]] = arith.ori %[[UNDER_L]], %[[OVER_L]] : i1
146  ! CHECK: %[[SHL:.*]] = arith.shli %[[A_VAL]], %[[S_CONV]] : i128
147  ! CHECK: %[[LFT:.*]] = arith.select %[[INV_L]], %[[C_0_L]], %[[SHL]] : i128
148  ! CHECK: %[[C_BITS_R:.*]] = arith.constant 128 : i128
149  ! CHECK: %[[C_0_R:.*]] = arith.constant 0 : i128
150  ! CHECK: %[[UNDER_R:.*]] = arith.cmpi slt, %[[DIFF]], %[[C_0_R]] : i128
151  ! CHECK: %[[OVER_R:.*]] = arith.cmpi sge, %[[DIFF]], %[[C_BITS_R]] : i128
152  ! CHECK: %[[INV_R:.*]] = arith.ori %[[UNDER_R]], %[[OVER_R]] : i1
153  ! CHECK: %[[SHR:.*]] = arith.shrui %[[B_VAL]], %[[DIFF]] : i128
154  ! CHECK: %[[RGT:.*]] = arith.select %[[INV_R]], %[[C_0_R]], %[[SHR]] : i128
155  ! CHECK: %[[SHIFT:.*]] = arith.ori %[[LFT]], %[[RGT]] : i128
156end subroutine dshiftl16_test
157