Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / Intrinsics / maskl.f90
blob19b6dcb33dcfede37ccbb43956f123edd9300099
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
4 ! CHECK-LABEL: maskl_test
5 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}
6 subroutine maskl_test(a, b)
7 integer :: a
8 integer :: b
10 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
11 b = maskl(a)
12 ! CHECK: %[[C__0:.*]] = arith.constant 0 : i32
13 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i32
14 ! CHECK: %[[BITS:.*]] = arith.constant 32 : i32
15 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_VAL]] : i32
16 ! CHECK: %[[SHIFT:.*]] = arith.shli %[[C__1]], %[[LEN]] : i32
17 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_VAL]], %[[C__0]] : i32
18 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i32
19 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i32>
20 end subroutine maskl_test
22 ! CHECK-LABEL: maskl1_test
23 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i8>{{.*}}
24 subroutine maskl1_test(a, b)
25 integer :: a
26 integer(kind=1) :: b
28 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
29 b = maskl(a, 1)
30 ! CHECK: %[[C__0:.*]] = arith.constant 0 : i8
31 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i8
32 ! CHECK: %[[BITS:.*]] = arith.constant 8 : i8
33 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i8
34 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i8
35 ! CHECK: %[[SHIFT:.*]] = arith.shli %[[C__1]], %[[LEN]] : i8
36 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i8
37 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i8
38 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i8>
39 end subroutine maskl1_test
41 ! CHECK-LABEL: maskl2_test
42 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i16>{{.*}}
43 subroutine maskl2_test(a, b)
44 integer :: a
45 integer(kind=2) :: b
47 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
48 b = maskl(a, 2)
49 ! CHECK: %[[C__0:.*]] = arith.constant 0 : i16
50 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i16
51 ! CHECK: %[[BITS:.*]] = arith.constant 16 : i16
52 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i16
53 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i16
54 ! CHECK: %[[SHIFT:.*]] = arith.shli %[[C__1]], %[[LEN]] : i16
55 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i16
56 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i16
57 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i16>
58 end subroutine maskl2_test
60 ! CHECK-LABEL: maskl4_test
61 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}
62 subroutine maskl4_test(a, b)
63 integer :: a
64 integer(kind=4) :: b
66 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
67 b = maskl(a, 4)
68 ! CHECK: %[[C__0:.*]] = arith.constant 0 : i32
69 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i32
70 ! CHECK: %[[BITS:.*]] = arith.constant 32 : i32
71 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_VAL]] : i32
72 ! CHECK: %[[SHIFT:.*]] = arith.shli %[[C__1]], %[[LEN]] : i32
73 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_VAL]], %[[C__0]] : i32
74 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i32
75 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i32>
76 end subroutine maskl4_test
78 ! CHECK-LABEL: maskl8_test
79 ! CHECK-SAME: %[[A:.*]]: !fir.ref<i32>{{.*}}, %[[B:.*]]: !fir.ref<i64>{{.*}}
80 subroutine maskl8_test(a, b)
81 integer :: a
82 integer(kind=8) :: b
84 ! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32>
85 b = maskl(a, 8)
86 ! CHECK: %[[C__0:.*]] = arith.constant 0 : i64
87 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i64
88 ! CHECK: %[[BITS:.*]] = arith.constant 64 : i64
89 ! CHECK: %[[A_CONV:.*]] = fir.convert %[[A_VAL]] : (i32) -> i64
90 ! CHECK: %[[LEN:.*]] = arith.subi %[[BITS]], %[[A_CONV]] : i64
91 ! CHECK: %[[SHIFT:.*]] = arith.shli %[[C__1]], %[[LEN]] : i64
92 ! CHECK: %[[IS0:.*]] = arith.cmpi eq, %[[A_CONV]], %[[C__0]] : i64
93 ! CHECK: %[[RESULT:.*]] = arith.select %[[IS0]], %[[C__0]], %[[SHIFT]] : i64
94 ! CHECK: fir.store %[[RESULT]] to %[[B]] : !fir.ref<i64>
95 end subroutine maskl8_test
97 ! TODO: Code containing 128-bit integer literals current breaks. This is
98 ! probably related to the issue linked below. When that is fixed, a test
99 ! for kind=16 should be added here.
101 ! https://github.com/llvm/llvm-project/issues/56446