Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / HLFIR / unary-ops.f90
blob11503354930b1399317008382a9a61c1b806ae9b
1 ! Test lowering of unary intrinsic operations to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 subroutine parentheses_numeric_var(x)
5 integer :: x
6 call bar((x))
7 end subroutine
8 ! CHECK-LABEL: func.func @_QPparentheses_numeric_var(
9 ! CHECK: %[[VAL_2:.*]] = fir.load %{{.*}} : !fir.ref<i32>
10 ! CHECK: %[[VAL_3:.*]] = hlfir.no_reassoc %[[VAL_2]] : i32
12 subroutine parentheses_numeric_expr(x)
13 real :: x
14 call bar((x+1000.)*2.)
15 end subroutine
16 ! CHECK-LABEL: func.func @_QPparentheses_numeric_expr(
17 ! CHECK: %[[VAL_4:.*]] = arith.addf
18 ! CHECK: %[[VAL_5:.*]] = hlfir.no_reassoc %[[VAL_4]] : f32
19 ! CHECK: %[[VAL_7:.*]] = arith.mulf %[[VAL_5]], %{{.*}}
21 subroutine parentheses_char_var(x)
22 character(*) :: x
23 call bar2((x))
24 end subroutine
25 ! CHECK-LABEL: func.func @_QPparentheses_char_var(
26 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare
27 ! CHECK: %[[VAL_3:.*]] = hlfir.as_expr %[[VAL_2]]#0 : (!fir.boxchar<1>) -> !hlfir.expr<!fir.char<1,?>>
29 subroutine parentheses_char_expr(x)
30 character(*) :: x
31 call bar2((x//x)//x)
32 end subroutine
33 ! CHECK-LABEL: func.func @_QPparentheses_char_expr(
34 ! CHECK: %[[VAL_4:.*]] = hlfir.concat
35 ! CHECK: %[[VAL_5:.*]] = hlfir.no_reassoc %[[VAL_4]] : !hlfir.expr<!fir.char<1,?>>
36 ! CHECK: %[[VAL_7:.*]] = hlfir.concat %[[VAL_5]], %{{.*}} len %{{.*}}
37 subroutine test_not(l, x)
38 logical :: l, x
39 l = .not.x
40 end subroutine
41 ! CHECK-LABEL: func.func @_QPtest_not(
42 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
43 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.logical<4>>
44 ! CHECK: %[[VAL_5:.*]] = arith.constant true
45 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_4]] : (!fir.logical<4>) -> i1
46 ! CHECK: %[[VAL_7:.*]] = arith.xori %[[VAL_6]], %[[VAL_5]] : i1
48 subroutine test_negate_int(res, x)
49 integer :: res, x
50 res = -x
51 end subroutine
52 ! CHECK-LABEL: func.func @_QPtest_negate_int(
53 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
54 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i32>
55 ! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i32
56 ! CHECK: %[[VAL_6:.*]] = arith.subi %[[VAL_5]], %[[VAL_4]] : i32
58 subroutine test_negate_real(res, x)
59 real :: res, x
60 res = -x
61 end subroutine
62 ! CHECK-LABEL: func.func @_QPtest_negate_real(
63 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
64 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<f32>
65 ! CHECK: %[[VAL_5:.*]] = arith.negf %[[VAL_4]] fastmath<contract> : f32
67 subroutine test_negate_complex(res, x)
68 complex :: res, x
69 res = -x
70 end subroutine
71 ! CHECK-LABEL: func.func @_QPtest_negate_complex(
72 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
73 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.complex<4>>
74 ! CHECK: %[[VAL_5:.*]] = fir.negc %[[VAL_4]] : !fir.complex<4>
76 subroutine test_complex_component_real(res, x)
77 real :: res
78 complex :: x
79 res = real(x)
80 end subroutine
81 ! CHECK-LABEL: func.func @_QPtest_complex_component_real(
82 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
83 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.complex<4>>
84 ! CHECK: %[[VAL_5:.*]] = fir.extract_value %[[VAL_4]], [0 : index] : (!fir.complex<4>) -> f32
86 subroutine test_complex_component_imag(res, x)
87 real :: res
88 complex :: x
89 res = aimag(x)
90 end subroutine
91 ! CHECK-LABEL: func.func @_QPtest_complex_component_imag(
92 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<!fir.complex<4>>) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
93 ! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.complex<4>>
94 ! CHECK: %[[VAL_5:.*]] = fir.extract_value %[[VAL_4]], [1 : index] : (!fir.complex<4>) -> f32