|
| 1 | +// RUN: %flang_fc1 -emit-llvm -O1 -funroll-loops -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,UNROLL |
| 2 | +// RUN: %flang_fc1 -emit-llvm -O2 -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,UNROLL |
| 3 | +// RUN: %flang_fc1 -emit-llvm -O1 -fno-unroll-loops -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,NO-UNROLL |
| 4 | +// RUN: %flang_fc1 -emit-llvm -O1 -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,NO-UNROLL |
| 5 | + |
| 6 | +// CHECK-LABEL: @unroll |
| 7 | +// CHECK-SAME: (ptr nocapture writeonly %[[ARG0:.*]]) |
| 8 | +func.func @unroll(%arg0: !fir.ref<!fir.array<1000 x index>> {fir.bindc_name = "a"}) { |
| 9 | + %scope = fir.dummy_scope : !fir.dscope |
| 10 | + %c1000 = arith.constant 1000 : index |
| 11 | + %shape = fir.shape %c1000 : (index) -> !fir.shape<1> |
| 12 | + %a:2 = hlfir.declare %arg0(%shape) dummy_scope %scope {uniq_name = "unrollEa"} : (!fir.ref<!fir.array<1000xindex>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<1000 x index>>, !fir.ref<!fir.array<1000 x index>>) |
| 13 | + %c1 = arith.constant 1 : index |
| 14 | + fir.do_loop %arg1 = %c1 to %c1000 step %c1 { |
| 15 | + // CHECK: br label %[[BLK:.*]] |
| 16 | + // CHECK: [[BLK]]: |
| 17 | + // CHECK-NEXT: %[[IND:.*]] = phi i64 [ 0, %{{.*}} ], [ %[[NIV:.*]], %[[BLK]] ] |
| 18 | + // CHECK-NEXT: %[[VIND:.*]] = phi <2 x i64> [ <i64 1, i64 2>, %{{.*}} ], [ %[[NVIND:.*]], %[[BLK]] ] |
| 19 | + |
| 20 | + // NO-UNROLL-NEXT: %[[GEP:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]] |
| 21 | + // NO-UNROLL-NEXT: store <2 x i64> %[[VIND]], ptr %[[GEP]] |
| 22 | + // NO-UNROLL-NEXT: %[[NIV:.*]] = add nuw i64 %{{.*}}, 2 |
| 23 | + // NO-UNROLL-NEXT: %[[NVIND]] = add <2 x i64> %[[VIND]], splat (i64 2) |
| 24 | + |
| 25 | + // UNROLL-NEXT: %[[VIND1:.*]] = add <2 x i64> %[[VIND]], splat (i64 2) |
| 26 | + // UNROLL-NEXT: %[[GEP0:.*]] = getelementptr i64, ptr %[[ARG0]], i64 %[[IND]] |
| 27 | + // UNROLL-NEXT: %[[GEP1:.*]] = getelementptr i8, ptr %[[GEP0]], i64 16 |
| 28 | + // UNROLL-NEXT: store <2 x i64> %[[VIND]], ptr %[[GEP0]] |
| 29 | + // UNROLL-NEXT: store <2 x i64> %[[VIND1]], ptr %[[GEP1]] |
| 30 | + // UNROLL-NEXT: %[[NIV:.*]] = add nuw i64 %[[IND]], 4 |
| 31 | + // UNROLL-NEXT: %[[NVIND:.*]] = add <2 x i64> %[[VIND]], splat (i64 4) |
| 32 | + |
| 33 | + // CHECK-NEXT: %[[EXIT:.*]] = icmp eq i64 %[[NIV]], 1000 |
| 34 | + // CHECK-NEXT: br i1 %[[EXIT]], label %{{.*}}, label %[[BLK]] |
| 35 | + %ai = hlfir.designate %a#0 (%arg1) : (!fir.ref<!fir.array<1000 x index>>, index) -> !fir.ref<index> |
| 36 | + hlfir.assign %arg1 to %ai : index, !fir.ref<index> |
| 37 | + } |
| 38 | + return |
| 39 | +} |
0 commit comments