Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / Intrinsics / merge_bits.f90
blobb5c2745d2b2ffdee1c7ec4414a7466f31df07f7d
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
4 ! CHECK-LABEL: merge_bits1_test
5 ! CHECK-SAME: %[[IREF:.*]]: !fir.ref<i8>{{.*}}, %[[JREF:.*]]: !fir.ref<i8>{{.*}}, %[[MREF:.*]]: !fir.ref<i8>{{.*}}, %[[RREF:.*]]: !fir.ref<i8>{{.*}}
6 subroutine merge_bits1_test(i, j, m, r)
7 integer(1) :: i, j, m
8 integer(1) :: r
10 ! CHECK: %[[I:.*]] = fir.load %[[IREF]] : !fir.ref<i8>
11 ! CHECK: %[[J:.*]] = fir.load %[[JREF]] : !fir.ref<i8>
12 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i8>
13 r = merge_bits(i, j, m)
14 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i8
15 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i8
16 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i8
17 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i8
18 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i8
19 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i8>
20 end subroutine merge_bits1_test
22 ! CHECK-LABEL: merge_bits2_test
23 ! CHECK-SAME: %[[IREF:.*]]: !fir.ref<i16>{{.*}}, %[[JREF:.*]]: !fir.ref<i16>{{.*}}, %[[MREF:.*]]: !fir.ref<i16>{{.*}}, %[[RREF:.*]]: !fir.ref<i16>{{.*}}
24 subroutine merge_bits2_test(i, j, m, r)
25 integer(2) :: i, j, m
26 integer(2) :: r
28 ! CHECK: %[[I:.*]] = fir.load %[[IREF]] : !fir.ref<i16>
29 ! CHECK: %[[J:.*]] = fir.load %[[JREF]] : !fir.ref<i16>
30 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i16>
31 r = merge_bits(i, j, m)
32 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i16
33 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i16
34 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i16
35 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i16
36 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i16
37 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i16>
38 end subroutine merge_bits2_test
40 ! CHECK-LABEL: merge_bits4_test
41 ! CHECK-SAME: %[[IREF:.*]]: !fir.ref<i32>{{.*}}, %[[JREF:.*]]: !fir.ref<i32>{{.*}}, %[[MREF:.*]]: !fir.ref<i32>{{.*}}, %[[RREF:.*]]: !fir.ref<i32>{{.*}}
42 subroutine merge_bits4_test(i, j, m, r)
43 integer(4) :: i, j, m
44 integer(4) :: r
46 ! CHECK: %[[I:.*]] = fir.load %[[IREF]] : !fir.ref<i32>
47 ! CHECK: %[[J:.*]] = fir.load %[[JREF]] : !fir.ref<i32>
48 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i32>
49 r = merge_bits(i, j, m)
50 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i32
51 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i32
52 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i32
53 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i32
54 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i32
55 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i32>
56 end subroutine merge_bits4_test
58 ! CHECK-LABEL: merge_bits8_test
59 ! CHECK-SAME: %[[IREF:.*]]: !fir.ref<i64>{{.*}}, %[[JREF:.*]]: !fir.ref<i64>{{.*}}, %[[MREF:.*]]: !fir.ref<i64>{{.*}}, %[[RREF:.*]]: !fir.ref<i64>{{.*}}
60 subroutine merge_bits8_test(i, j, m, r)
61 integer(8) :: i, j, m
62 integer(8) :: r
64 ! CHECK: %[[I:.*]] = fir.load %[[IREF]] : !fir.ref<i64>
65 ! CHECK: %[[J:.*]] = fir.load %[[JREF]] : !fir.ref<i64>
66 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i64>
67 r = merge_bits(i, j, m)
68 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i64
69 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i64
70 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i64
71 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i64
72 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i64
73 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i64>
74 end subroutine merge_bits8_test
76 ! CHECK-LABEL: merge_bitsz0_test
77 ! CHECK-SAME: %[[JREF:.*]]: !fir.ref<i32>{{.*}}, %[[MREF:.*]]: !fir.ref<i32>{{.*}}, %[[RREF:.*]]: !fir.ref<i32>{{.*}}
78 subroutine merge_bitsz0_test(j, m, r)
79 integer :: j, m
80 integer :: r
82 ! CHECK: %[[I:.*]] = arith.constant 13 : i32
83 ! CHECK: %[[J:.*]] = fir.load %[[JREF]] : !fir.ref<i32>
84 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i32>
85 r = merge_bits(B'1101', j, m)
86 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i32
87 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i32
88 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i32
89 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i32
90 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i32
91 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i32>
92 end subroutine merge_bitsz0_test
94 ! CHECK-LABEL: merge_bitsz1_test
95 ! CHECK-SAME: %[[IREF:.*]]: !fir.ref<i32>{{.*}}, %[[MREF:.*]]: !fir.ref<i32>{{.*}}, %[[RREF:.*]]: !fir.ref<i32>{{.*}}
96 subroutine merge_bitsz1_test(i, m, r)
97 integer :: i, m
98 integer :: r
100 ! CHECK: %[[I:.*]] = fir.load %[[IREF]] : !fir.ref<i32>
101 ! CHECK: %[[J:.*]] = arith.constant 13 : i32
102 ! CHECK: %[[M:.*]] = fir.load %[[MREF]] : !fir.ref<i32>
103 r = merge_bits(i, Z'0D', m)
104 ! CHECK: %[[C__1:.*]] = arith.constant -1 : i32
105 ! CHECK: %[[NM:.*]] = arith.xori %[[M]], %[[C__1]] : i32
106 ! CHECK: %[[LFT:.*]] = arith.andi %[[I]], %[[M]] : i32
107 ! CHECK: %[[RGT:.*]] = arith.andi %[[J]], %[[NM]] : i32
108 ! CHECK: %[[RES:.*]] = arith.ori %[[LFT]], %[[RGT]] : i32
109 ! CHECK: fir.store %[[RES]] to %[[RREF]] : !fir.ref<i32>
110 end subroutine merge_bitsz1_test