llvm-project
46 строк · 1.7 Кб
1// RUN: fir-opt --canonicalize %s -split-input-file | FileCheck %s
2
3// CHECK-LABEL: func @check_no_folding
4func.func @check_no_folding(%arg0 : !fir.ref<!fir.array<?xi32>>) {
5%0 = fir.alloca i32 {adapt.valuebyref}
6%c1_i32 = arith.constant 1 : i32
7%1 = fir.load %0 : !fir.ref<i32>
8%2 = arith.addi %1, %c1_i32 : i32
9%3 = fir.convert %2 : (i32) -> index
10%c1 = arith.constant 1 : index
11%5 = arith.subi %3, %c1 : index
12%6 = fir.shape %3 : (index) -> !fir.shape<1>
13%7 = fir.slice %3, %5, %3 : (index, index, index) -> !fir.slice<1>
14%8 = fir.embox %arg0(%6) [%7] : (!fir.ref<!fir.array<?xi32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>>
15%9 = fir.box_addr %8 : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>>
16// CHECK: %[[BOX_ADDR:.*]] = fir.box_addr
17// CHECK: fir.call @check(%[[BOX_ADDR]])
18fir.call @check(%9) : (!fir.ref<!fir.array<?xi32>>) -> ()
19return
20}
21
22func.func @check(%arg0: !fir.ref<!fir.array<?xi32>>) {
23return
24}
25
26// -----
27
28// CHECK-LABEL: func @check_folding
29func.func @check_folding(%arg0 : !fir.ref<!fir.array<?xi32>>) {
30%0 = fir.alloca i32 {adapt.valuebyref}
31%c1_i32 = arith.constant 1 : i32
32%1 = fir.load %0 : !fir.ref<i32>
33%2 = arith.addi %1, %c1_i32 : i32
34%3 = fir.convert %2 : (i32) -> index
35%c1 = arith.constant 1 : index
36%6 = fir.shape %3 : (index) -> !fir.shape<1>
37%7 = fir.embox %arg0(%6) : (!fir.ref<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>
38%8 = fir.box_addr %7 : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>>
39// CHECK-NOT: fir.box_addr
40fir.call @check(%8) : (!fir.ref<!fir.array<?xi32>>) -> ()
41return
42}
43
44func.func @check(%arg0: !fir.ref<!fir.array<?xi32>>) {
45return
46}
47