84 lines · plain
1// Test translation to llvm IR of fir.rebox with substring array sections.2 3// RUN: fir-opt -o - -cg-rewrite --fir-to-llvm-ir -cse %s | FileCheck %s4// RUN: tco -o - -cg-rewrite --fir-to-llvm-ir -cse %s | FileCheck %s5 6// Test a fir.rebox with a substring on a character array with constant7// length (like c(:)(2:*) where c is a fir.box array with constant length).8 9// CHECK-LABEL: llvm.func @char_section(10// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) {11func.func @char_section(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {12 %c7_i64 = arith.constant 7 : i6413 %c1_i64 = arith.constant 1 : i6414 %c0 = arith.constant 0 : index15 %c1 = arith.constant 1 : index16 %0:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,20>>>, index) -> (index, index, index)17 %1 = fir.slice %c1, %0#1, %c1_i64 substr %c1_i64, %c7_i64 : (index, index, i64, i64, i64) -> !fir.slice<1>18 19// Only test the computation of the base address offset computation accounting for the substring20 21// CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i64) : i6422 23// CHECK: %[[VAL_37:.*]] = llvm.getelementptr %[[VAL_0]]{{\[}}0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<{{.*}}>24// CHECK: %[[VAL_38:.*]] = llvm.load %[[VAL_37]] : !llvm.ptr -> !llvm.ptr25// CHECK: %[[VAL_30:.*]] = llvm.mlir.constant(0 : i64) : i6426// CHECK: %[[VAL_40:.*]] = llvm.getelementptr %[[VAL_38]]{{\[}}%[[VAL_30]], %[[VAL_4]]] : (!llvm.ptr, i64, i64) -> !llvm.ptr, !llvm.array<20 x i8>27 28// More offset computation with descriptor strides and triplets that is not character specific ...29 30 %2 = fir.rebox %arg0 [%1] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>31 fir.call @bar(%2) : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()32 return33}34 35// Test a rebox of an array section like x(3:60:9)%c(2:8) with both a triplet, a component and a substring where x is a fir.box.36 37// CHECK-LABEL: llvm.func @foo(38// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr) {39func.func private @bar(!fir.box<!fir.array<?x!fir.char<1,?>>>)40func.func @foo(%arg0: !fir.box<!fir.array<?x!fir.type<t{i:i32,c:!fir.char<1,10>}>>>) {41 %c7_i64 = arith.constant 7 : i6442 %c1_i64 = arith.constant 1 : i6443 %c9_i64 = arith.constant 9 : i6444 %c60_i64 = arith.constant 60 : i6445 %c3_i64 = arith.constant 3 : i6446 %0 = fir.field_index c, !fir.type<t{i:i32,c:!fir.char<1,10>}>47 %1 = fir.slice %c3_i64, %c60_i64, %c9_i64 path %0 substr %c1_i64, %c7_i64 : (i64, i64, i64, !fir.field, i64, i64) -> !fir.slice<1>48 49// Only test the computation of the base address offset computation accounting for the substring of the component50 51// CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(1 : i32) : i3252 53// CHECK: %[[VAL_30:.*]] = llvm.getelementptr %[[VAL_0]]{{\[}}0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<{{.*}}>54// CHECK: %[[VAL_31:.*]] = llvm.load %[[VAL_30]] : !llvm.ptr -> !llvm.ptr55// CHECK: %[[VAL_21:.*]] = llvm.mlir.constant(0 : i64) : i6456// CHECK: %[[VAL_33:.*]] = llvm.getelementptr %[[VAL_31]]{{\[}}%[[VAL_21]], 1, %[[VAL_4]]] : (!llvm.ptr, i64, i64) -> !llvm.ptr, !llvm.struct<{{.*}}>57 58// More offset computation with descriptor strides and triplets that is not character specific ...59 60 %2 = fir.rebox %arg0 [%1] : (!fir.box<!fir.array<?x!fir.type<t{i:i32,c:!fir.char<1,10>}>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>61 fir.call @bar(%2) : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()62 return63}64 65// Test that a rebox with `index` substring parameter is converted66// to legal IR. It used to produce:67// %63 = "llvm.mul"(%62, <<NULL VALUE>>) : (i64, <<NULL TYPE>>) -> i6468// because the substr was not accessed via the adaptor's operands.69 70// CHECK-LABEL: llvm.func @index_substr(71// CHECK-NOT: NULL_VALUE72// CHECK-NOT: NULL_TYPE73func.func @index_substr(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {74 %c7_index = arith.constant 7 : index75 %c1_i64 = arith.constant 1 : i6476 %c0 = arith.constant 0 : index77 %c1 = arith.constant 1 : index78 %0:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,20>>>, index) -> (index, index, index)79 %1 = fir.slice %c1, %0#1, %c1_i64 substr %c1_i64, %c7_index : (index, index, i64, i64, index) -> !fir.slice<1>80 %2 = fir.rebox %arg0 [%1] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>81 fir.call @bar(%2) : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()82 return83}84