[flang-commits] [clang] [flang] [flang] Add -f[no-]unroll-loops flag (PR #122906)
David Truby via flang-commits
flang-commits at lists.llvm.org
Wed Jan 15 06:25:39 PST 2025
================
@@ -0,0 +1,37 @@
+! RUN: %flang_fc1 -emit-llvm -O1 -funroll-loops -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,UNROLL
+! RUN: %flang_fc1 -emit-llvm -O2 -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,UNROLL
+! RUN: %flang_fc1 -emit-llvm -O1 -fno-unroll-loops -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,NO-UNROLL
+! RUN: %flang_fc1 -emit-llvm -O1 -mllvm -force-vector-width=2 -o- %s | FileCheck %s --check-prefixes=CHECK,NO-UNROLL
+
+! CHECK-LABEL: @unroll
+! CHECK-SAME: (ptr nocapture writeonly %[[ARG0:.*]])
+subroutine unroll(a)
+ real(kind=8), intent(out) :: a(1000)
+ integer(kind=8) :: i
+ ! CHECK: br label %[[BLK:.*]]
+ ! CHECK: [[BLK]]:
+ ! CHECK-NEXT: %[[IND:.*]] = phi i64 [ 0, %{{.*}} ], [ %[[NIV:.*]], %[[BLK]] ]
+ ! CHECK-NEXT: %[[VIND:.*]] = phi <2 x i64> [ <i64 1, i64 2>, %{{.*}} ], [ %[[NVIND:.*]], %[[BLK]] ]
+ !
+ ! NO-UNROLL-NEXT: %[[IV_D:.*]] = uitofp nneg <2 x i64> %[[VIND]] to <2 x double>
+ ! NO-UNROLL-NEXT: %[[GEP:.*]] = getelementptr double, ptr %[[ARG0]], i64 %[[IND]]
+ ! NO-UNROLL-NEXT: store <2 x double> %[[IV_D]], ptr %[[GEP]]
+ ! NO-UNROLL-NEXT: %[[NIV:.*]] = add nuw i64 %{{.*}}, 2
+ ! NO-UNROLL-NEXT: %[[NVIND]] = add <2 x i64> %[[VIND]], splat (i64 2)
----------------
DavidTruby wrote:
I actually did try to only have (e.g.) 2 iterations of the loop; for some reason the full loop is still emitted, at least at -O1. What I ended up with here was essentially copied from the clang `-funroll-loops` tests but converted to fortran.
https://github.com/llvm/llvm-project/pull/122906
More information about the flang-commits
mailing list