| 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: shifta1_test |
| 5 |
! CHECK-SAME: %[[A:.*]]: !fir.ref<i8>{{.*}}, %[[B:.*]]: !fir.ref<i32>{{.*}}, %[[C:.*]]: !fir.ref<i8>{{.*}} |
| 6 |
subroutine shifta1_test(a, b, c) |
| 7 |
integer(kind=1) :: a |
| 8 |
integer :: b |
| 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<i32> |
| 13 |
c = shifta(a, b) |
| 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 |
| 24 |
|
| 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) |
| 28 |
integer(kind=2) :: a |
| 29 |
integer :: b |
| 30 |
integer(kind=2) :: c |
| 31 |
|
| 32 |
! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i16> |
| 33 |
! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32> |
| 34 |
c = shifta(a, b) |
| 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 |
| 45 |
|
| 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) |
| 49 |
integer(kind=4) :: a |
| 50 |
integer :: b |
| 51 |
integer(kind=4) :: c |
| 52 |
|
| 53 |
! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i32> |
| 54 |
! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32> |
| 55 |
c = shifta(a, b) |
| 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 |
| 65 |
|
| 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) |
| 69 |
integer(kind=8) :: a |
| 70 |
integer :: b |
| 71 |
integer(kind=8) :: c |
| 72 |
|
| 73 |
! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i64> |
| 74 |
! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32> |
| 75 |
c = shifta(a, b) |
| 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 |
| 86 |
|
| 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) |
| 90 |
integer(kind=16) :: a |
| 91 |
integer :: b |
| 92 |
integer(kind=16) :: c |
| 93 |
|
| 94 |
! CHECK: %[[A_VAL:.*]] = fir.load %[[A]] : !fir.ref<i128> |
| 95 |
! CHECK: %[[B_VAL:.*]] = fir.load %[[B]] : !fir.ref<i32> |
| 96 |
c = shifta(a, b) |
| 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 |