Debian Codegraph @

flang/test/Fir/convert-fold.fir

raw
1 // RUN: fir-opt --canonicalize %s | FileCheck %s
2
3 // CHECK-LABEL: @ftest
4 func.func @ftest(%x : i1) -> i1 {
5 // this pair of converts should be folded and DCEd
6 %1 = fir.convert %x : (i1) -> !fir.logical<1>
7 %2 = fir.convert %1 : (!fir.logical<1>) -> i1
8 // CHECK-NEXT: return %{{.*}} : i1
9 return %2 : i1
10 }
11
12 // CHECK-LABEL: @gtest
13 func.func @gtest(%x : !fir.logical<2>) -> !fir.logical<2> {
14 // this pair of converts should be folded and DCEd
15 %1 = fir.convert %x : (!fir.logical<2>) -> i1
16 %2 = fir.convert %1 : (i1) -> !fir.logical<2>
17 // CHECK-NEXT: return %{{.*}} : !fir.logical<2>
18 return %2 : !fir.logical<2>
19 }
20
21 // CHECK-LABEL: @htest
22 func.func @htest(%x : !fir.int<4>) -> !fir.int<4> {
23 // these converts are NOPs and should be folded away
24 %1 = fir.convert %x : (!fir.int<4>) -> !fir.int<4>
25 %2 = fir.convert %1 : (!fir.int<4>) -> !fir.int<4>
26 // CHECK-NEXT: return %{{.*}} : !fir.int<4>
27 return %2 : !fir.int<4>
28 }
29
30 // CHECK-LABEL: @ctest
31 func.func @ctest() -> index {
32 %1 = arith.constant 10 : i32
33 %2 = fir.convert %1 : (i32) -> index
34 // CHECK-NEXT: %{{.*}} = arith.constant 10 : index
35 // CHECK-NEXT: return %{{.*}} : index
36 return %2 : index
37 }
38
39 // CHECK-LABEL: func.func @ptrtest(
40 // CHECK-SAME: %[[VAL_0:.*]]: !fir.heap<!fir.array<2xf32>>) -> !fir.heap<!fir.array<2xf32>> {
41 func.func @ptrtest(%0 : !fir.heap<!fir.array<2xf32>>) -> !fir.heap<!fir.array<2xf32>> {
42 %1 = fir.convert %0 : (!fir.heap<!fir.array<2xf32>>) -> !fir.ref<!fir.array<2xf32>>
43 %2 = fir.convert %1 : (!fir.ref<!fir.array<2xf32>>) -> !fir.heap<!fir.array<2xf32>>
44 // CHECK: return %[[VAL_0]] : !fir.heap<!fir.array<2xf32>>
45 return %2 : !fir.heap<!fir.array<2xf32>>
46 }