|
| 1 | + |
| 2 | +// RUN: fir-opt %s --fir-to-scf | FileCheck %s |
| 3 | + |
| 4 | +// CHECK: func.func @_QFPtest_only( |
| 5 | +// CHECK: %[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<f32>>>) { |
| 6 | +// CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32 |
| 7 | +// CHECK: %[[VAL_1:.*]] = arith.constant false |
| 8 | +// CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32 |
| 9 | +// CHECK: scf.if %[[VAL_1:.*]] { |
| 10 | +// CHECK: %[[VAL_3:.*]] = arith.addi %[[VAL_2:.*]], %[[VAL_0:.*]] : i32 |
| 11 | +// CHECK: } |
| 12 | +// CHECK: return |
| 13 | +// CHECK: } |
| 14 | +func.func @_QFPtest_only(%arg0: !fir.ref<tuple<!fir.ref<f32>>>) { |
| 15 | + %c1_i32 = arith.constant 1 : i32 |
| 16 | + %false = arith.constant false |
| 17 | + %c0_i32 = arith.constant 0 : i32 |
| 18 | + fir.if %false { |
| 19 | + %0 = arith.addi %c0_i32, %c1_i32 : i32 |
| 20 | + } |
| 21 | + return |
| 22 | + } |
| 23 | + |
| 24 | +// CHECK: func.func @_QFPtest_else( |
| 25 | +// CHECK: %[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<f32>>>) { |
| 26 | +// CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32 |
| 27 | +// CHECK: %[[VAL_1:.*]] = arith.constant false |
| 28 | +// CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32 |
| 29 | +// CHECK: %[[VAL_3:.*]] = fir.dummy_scope : !fir.dscope |
| 30 | +// CHECK: %[[VAL_4:.*]] = fir.coordinate_of %[[ARG0:.*]], %[[VAL_2:.*]] : (!fir.ref<tuple<!fir.ref<f32>>>, i32) -> !fir.llvm_ptr<!fir.ref<f32>> |
| 31 | +// CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4:.*]] : !fir.llvm_ptr<!fir.ref<f32>> |
| 32 | +// CHECK: %[[VAL_6:.*]] = fir.declare %[[VAL_5:.*]] {fortran_attrs = #fir.var_attrs<host_assoc>, uniq_name = "_QFEx"} : (!fir.ref<f32>) -> !fir.ref<f32> |
| 33 | +// CHECK: %[[VAL_7:.*]] = fir.address_of(@_QFFtest_elseEsum) : !fir.ref<i32> |
| 34 | +// CHECK: %[[VAL_10:.*]] = fir.declare %[[VAL_7:.*]] {uniq_name = "_QFFtest_elseEsum"} : (!fir.ref<i32>) -> !fir.ref<i32> |
| 35 | +// CHECK: scf.if %[[VAL_1:.*]] { |
| 36 | +// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_10:.*]] : !fir.ref<i32> |
| 37 | +// CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_8:.*]], %[[VAL_0:.*]] : i32 |
| 38 | +// CHECK: fir.store %[[VAL_9:.*]] to %[[VAL_10:.*]] : !fir.ref<i32> |
| 39 | +// CHECK: } else { |
| 40 | +// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_10:.*]] : !fir.ref<i32> |
| 41 | +// CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_8:.*]], %c1_i32 : i32 |
| 42 | +// CHECK: fir.store %[[VAL_9:.*]] to %[[VAL_10:.*]] : !fir.ref<i32> |
| 43 | +// CHECK: } |
| 44 | +// CHECK: return |
| 45 | +// CHECK: } |
| 46 | +func.func @_QFPtest_else(%arg0: !fir.ref<tuple<!fir.ref<f32>>> {}) attributes {} { |
| 47 | + %c1_i32 = arith.constant 1 : i32 |
| 48 | + %false = arith.constant false |
| 49 | + %c0_i32 = arith.constant 0 : i32 |
| 50 | + %0 = fir.dummy_scope : !fir.dscope |
| 51 | + %1 = fir.coordinate_of %arg0, %c0_i32 : (!fir.ref<tuple<!fir.ref<f32>>>, i32) -> !fir.llvm_ptr<!fir.ref<f32>> |
| 52 | + %2 = fir.load %1 : !fir.llvm_ptr<!fir.ref<f32>> |
| 53 | + %3 = fir.declare %2 {fortran_attrs = #fir.var_attrs<host_assoc>, uniq_name = "_QFEx"} : (!fir.ref<f32>) -> !fir.ref<f32> |
| 54 | + %4 = fir.address_of(@_QFFtest_elseEsum) : !fir.ref<i32> |
| 55 | + %5 = fir.declare %4 {uniq_name = "_QFFtest_elseEsum"} : (!fir.ref<i32>) -> !fir.ref<i32> |
| 56 | + fir.if %false { |
| 57 | + %6 = fir.load %5 : !fir.ref<i32> |
| 58 | + %7 = arith.addi %6, %c1_i32 : i32 |
| 59 | + fir.store %7 to %5 : !fir.ref<i32> |
| 60 | + } else { |
| 61 | + %6 = fir.load %5 : !fir.ref<i32> |
| 62 | + %7 = arith.addi %6, %c1_i32 : i32 |
| 63 | + fir.store %7 to %5 : !fir.ref<i32> |
| 64 | + } |
| 65 | + return |
| 66 | +} |
| 67 | +
|
| 68 | +// CHECK-LABEL: func.func @test_two_result() { |
| 69 | +// CHECK: %[[VAL_0:.*]] = arith.constant 10 : i32 |
| 70 | +// CHECK: %[[VAL_1:.*]] = arith.constant 5 : i32 |
| 71 | +// CHECK: %[[VAL_2:.*]] = arith.cmpi sgt, %[[VAL_0:.*]], %[[VAL_1:.*]] : i32 |
| 72 | +// CHECK: %[[VAL_3:.*]] = arith.constant 3.140000e+00 : f32 |
| 73 | +// CHECK: %[[VAL_4:.*]] = arith.constant 2.710000e+00 : f32 |
| 74 | +// CHECK: %[[VAL_5:.*]] = arith.constant 1.000000e+00 : f32 |
| 75 | +// CHECK: %[[VAL_6:.*]] = arith.constant 2.000000e+00 : f32 |
| 76 | +// CHECK: %[[RES:[0-9]+]]:2 = scf.if %[[VAL_2:.*]] -> (f32, f32) { |
| 77 | +// CHECK: scf.yield %[[VAL_3:.*]], %[[VAL_4:.*]] : f32, f32 |
| 78 | +// CHECK: } else { |
| 79 | +// CHECK: scf.yield %[[VAL_5:.*]], %[[VAL_6:.*]] : f32, f32 |
| 80 | +// CHECK: } |
| 81 | +// CHECK: return |
| 82 | +// CHECK: } |
| 83 | +func.func @test_two_result() { |
| 84 | + %c10_i32 = arith.constant 10 : i32 |
| 85 | + %c5_i32 = arith.constant 5 : i32 |
| 86 | + %cmp = arith.cmpi sgt, %c10_i32, %c5_i32 : i32 |
| 87 | + %c3_14_f32 = arith.constant 3.14 : f32 |
| 88 | + %c2_71_f32 = arith.constant 2.71 : f32 |
| 89 | + %c1_0_f32 = arith.constant 1.0 : f32 |
| 90 | + %c2_0_f32 = arith.constant 2.0 : f32 |
| 91 | + %x, %y = fir.if %cmp -> (f32, f32) { |
| 92 | + fir.result %c3_14_f32, %c2_71_f32 : f32, f32 |
| 93 | + } else { |
| 94 | + fir.result %c1_0_f32, %c2_0_f32 : f32, f32 |
| 95 | + } |
| 96 | + return |
| 97 | +} |
0 commit comments