brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 5c5f631 Raw
99 lines · plain
1// Test regrouping of + and - operations on complex components into complex operations2// RUN: fir-opt --canonicalize %s | FileCheck %s3 4 5// CHECK-LABEL: @add6func.func @add(%z: !fir.ref<complex<f64>>, %z1 : complex<f64>, %z2 : complex<f64>) {7  %c0 = arith.constant 0 : index8  %c1 = arith.constant 1 : index9  %real1 = fir.extract_value %z1, [0 : index] : (complex<f64>) -> f6410  %imag1 = fir.extract_value %z1, [1 : index] : (complex<f64>) -> f6411  %real2 = fir.extract_value %z2, [0 : index] : (complex<f64>) -> f6412  %imag2 = fir.extract_value %z2, [1 : index] : (complex<f64>) -> f6413 14  // CHECK-LABEL: fir.addc15  %real = arith.addf %real1, %real2 : f6416  %imag = arith.addf %imag1, %imag2 : f6417  %undef = fir.undefined complex<f64>18  %insert_real = fir.insert_value %undef, %real, [0 : index] : (complex<f64>, f64) -> complex<f64>19  %insert_imag = fir.insert_value %insert_real, %imag, [1 : index] : (complex<f64>, f64) -> complex<f64>20  fir.store %insert_imag to %z : !fir.ref<complex<f64>>21  return22}23 24// CHECK-LABEL: @sub25func.func @sub(%z: !fir.ref<complex<f64>>, %z1 : complex<f64>, %z2 : complex<f64>) {26  %c0 = arith.constant 0 : index27  %c1 = arith.constant 1 : index28  %real1 = fir.extract_value %z1, [0 : index] : (complex<f64>) -> f6429  %imag1 = fir.extract_value %z1, [1 : index] : (complex<f64>) -> f6430  %real2 = fir.extract_value %z2, [0 : index] : (complex<f64>) -> f6431  %imag2 = fir.extract_value %z2, [1 : index] : (complex<f64>) -> f6432 33  // CHECK-LABEL: fir.subc34  %real = arith.subf %real1, %real2 : f6435  %imag = arith.subf %imag1, %imag2 : f6436  %undef = fir.undefined complex<f64>37  %insert_real = fir.insert_value %undef, %real, [0 : index] : (complex<f64>, f64) -> complex<f64>38  %insert_imag = fir.insert_value %insert_real, %imag, [1 : index] : (complex<f64>, f64) -> complex<f64>39  fir.store %insert_imag to %z : !fir.ref<complex<f64>>40  return41}42 43// CHECK-LABEL: @undefOpHiddenByBranch44func.func @undefOpHiddenByBranch(%z: !fir.ref<complex<f64>>, %b: i1) {45  %c0 = arith.constant 0 : index46  %c1 = arith.constant 1 : index47  cf.cond_br %b, ^bb1, ^bb248^bb1:  // pred: ^bb049  %u1 = fir.undefined complex<f64>50  %z1l = fir.call @bar1() : () -> complex<f64>51  %z1r = fir.call @bar1() : () -> complex<f64>52  cf.br ^bb3(%u1, %z1l, %z1r : complex<f64>, complex<f64>, complex<f64>)53^bb2:  // pred: ^bb054  %u2 = fir.undefined complex<f64>55  %z2l = fir.call @bar2() : () -> complex<f64>56  %z2r = fir.call @bar2() : () -> complex<f64>57  cf.br ^bb3(%u2, %z2l, %z2r : complex<f64>, complex<f64>, complex<f64>)58 59// CHECK: ^bb3(%[[z1:.*]]: complex<f64>, %[[z2:.*]]: complex<f64>):  // 2 preds: ^bb1, ^bb260// CHECK:  fir.addc %[[z1]], %[[z2]] : complex<f64>61 62^bb3(%undef : complex<f64>, %z1 : complex<f64>, %z2 : complex<f64>):  // 2 preds: ^bb1, ^bb263  %real1 = fir.extract_value %z1, [0 : index] : (complex<f64>) -> f6464  %imag1 = fir.extract_value %z1, [1 : index] : (complex<f64>) -> f6465  %real2 = fir.extract_value %z2, [0 : index] : (complex<f64>) -> f6466  %imag2 = fir.extract_value %z2, [1 : index] : (complex<f64>) -> f6467  %real = arith.addf %real1, %real2 : f6468  %imag = arith.addf %imag1, %imag2 : f6469  %insert_real = fir.insert_value %undef, %real, [0 : index] : (complex<f64>, f64) -> complex<f64>70  %insert_imag = fir.insert_value %insert_real, %imag, [1 : index] : (complex<f64>, f64) -> complex<f64>71  fir.store %insert_imag to %z : !fir.ref<complex<f64>>72  return73}74func.func private @bar1() -> complex<f64>75func.func private @bar2() -> complex<f64>76 77// CHECK-LABEL: @close_but_bad_pattern78func.func @close_but_bad_pattern(%z: !fir.ref<complex<f64>>, %z1 : complex<f64>, %z2 : complex<f64>) {79  %c0 = arith.constant 0 : index80  %c1 = arith.constant 1 : index81  %real1 = fir.extract_value %z1, [0 : index] : (complex<f64>) -> f6482  // extracting %c0 instead of %c1 83  %imag1 = fir.extract_value %z1, [0 : index] : (complex<f64>) -> f6484  %real2 = fir.extract_value %z2, [0 : index] : (complex<f64>) -> f6485  %imag2 = fir.extract_value %z2, [1 : index] : (complex<f64>) -> f6486  // CHECK: arith.subf87  // CHECK: subf88  %real = arith.subf %real1, %real2 : f6489  %imag = arith.subf %imag1, %imag2 : f6490  %undef = fir.undefined complex<f64>91  // CHECK: %[[insert1:.*]] = fir.insert_value %{{.*}}, %{{.*}}, [092  // CHECK: %[[insert2:.*]] = fir.insert_value %[[insert1]], %{{.*}}, [193  %insert_real = fir.insert_value %undef, %real, [0 : index] : (complex<f64>, f64) -> complex<f64>94  %insert_imag = fir.insert_value %insert_real, %imag, [1 : index] : (complex<f64>, f64) -> complex<f64>95  // CHECK: fir.store %[[insert2]] to {{.*}}96  fir.store %insert_imag to %z : !fir.ref<complex<f64>>97  return98}99