| 1 |
// RUN: fir-opt -o - -cg-rewrite --fir-to-llvm-ir %s | FileCheck %s |
| 2 |
// RUN: tco -o - -cg-rewrite --fir-to-llvm-ir %s | FileCheck %s |
| 3 |
|
| 4 |
// CHECK-LABEL: llvm.func @embox_index_substr( |
| 5 |
// CHECK-NOT: NULL_VALUE |
| 6 |
// CHECK-NOT: NULL_TYPE |
| 7 |
func.func @embox_index_substr(%addr : !fir.ref<!fir.array<?x!fir.char<1,2>>>) { |
| 8 |
%0 = arith.constant 0 : index |
| 9 |
%1 = fir.shape_shift %0, %0 : (index, index) -> !fir.shapeshift<1> |
| 10 |
%2 = fir.slice %0, %0, %0 substr %0, %0: (index, index, index, index, index) -> !fir.slice<1> |
| 11 |
%3 = fir.embox %addr (%1) [%2] : (!fir.ref<!fir.array<?x!fir.char<1,2>>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>> |
| 12 |
return |
| 13 |
} |
| 14 |
|
| 15 |
// CHARACTER(*) :: C(2) |
| 16 |
// CALL DUMP(C(:)(1:1)) |
| 17 |
// Test that the resulting stride is based on the input length, not the substring one. |
| 18 |
func.func @substring_dyn_base(%base_addr: !fir.ref<!fir.array<2x!fir.char<1,?>>>, %base_len: index) { |
| 19 |
%c0 = arith.constant 0 : index |
| 20 |
%c1 = arith.constant 1 : index |
| 21 |
%c2 = arith.constant 2 : index |
| 22 |
%2 = fircg.ext_embox %base_addr(%c2)[%c1, %c2, %c1] substr %c0, %c1 typeparams %base_len : (!fir.ref<!fir.array<2x!fir.char<1,?>>>, index, index, index, index, index, index, index) -> !fir.box<!fir.array<2x!fir.char<1>>> |
| 23 |
fir.call @dump(%2) : (!fir.box<!fir.array<2x!fir.char<1>>>) -> () |
| 24 |
return |
| 25 |
} |
| 26 |
func.func private @dump(!fir.box<!fir.array<2x!fir.char<1>>>) |
| 27 |
|
| 28 |
// CHECK-LABEL: llvm.func @substring_dyn_base( |
| 29 |
// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr, |
| 30 |
// CHECK-SAME: %[[VAL_1:.*]]: i64) { |
| 31 |
// CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : index) : i64 |
| 32 |
// CHECK: llvm.mlir.constant(1 : i64) : i64 |
| 33 |
// CHECK: llvm.mlir.constant(1 : i64) : i64 |
| 34 |
// CHECK: %[[VAL_30:.*]] = llvm.mlir.constant(1 : i64) : i64 |
| 35 |
// CHECK: %[[VAL_31:.*]] = llvm.mul %[[VAL_30]], %[[VAL_1]] : i64 |
| 36 |
// CHECK: %[[VAL_42:.*]] = llvm.mul %[[VAL_31]], %[[VAL_5]] : i64 |
| 37 |
// CHECK: %[[VAL_43:.*]] = llvm.insertvalue %[[VAL_42]], %{{.*}}[7, 0, 2] : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> |