[PATCH] D25387: When optimizing for size, enable loop rerolling by default.

Hal Finkel via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 18:22:29 PDT 2016


hfinkel created this revision.
hfinkel added a reviewer: jmolloy.
hfinkel added a subscriber: cfe-commits.
Herald added a subscriber: mcrosier.

We have a loop-rerolling optimization which can be enabled by using -freroll-loops. While sometimes loops are hand-unrolled for performance reasons, when optimizing for size, we should always undo this manual optimization to produce smaller code (our optimizer's unroller will still unroll the rerolled loops if it thinks that is a good idea).


https://reviews.llvm.org/D25387

Files:
  lib/Driver/Tools.cpp
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===================================================================
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -47,7 +47,12 @@
 // CHECK-NO-UNROLL-LOOPS: "-fno-unroll-loops"
 
 // RUN: %clang -### -S -freroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-REROLL-LOOPS %s
+// RUN: %clang -### -S -Os %s 2>&1 | FileCheck -check-prefix=CHECK-REROLL-LOOPS %s
+// RUN: %clang -### -S -Oz %s 2>&1 | FileCheck -check-prefix=CHECK-REROLL-LOOPS %s
 // RUN: %clang -### -S -fno-reroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-REROLL-LOOPS %s
+// RUN: %clang -### -S -Os -fno-reroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-REROLL-LOOPS %s
+// RUN: %clang -### -S -Oz -fno-reroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-REROLL-LOOPS %s
+// RUN: %clang -### -S -O1 %s 2>&1 | FileCheck -check-prefix=CHECK-NO-REROLL-LOOPS %s
 // RUN: %clang -### -S -fno-reroll-loops -freroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-REROLL-LOOPS %s
 // RUN: %clang -### -S -freroll-loops -fno-reroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-NO-REROLL-LOOPS %s
 // CHECK-REROLL-LOOPS: "-freroll-loops"
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5226,9 +5226,18 @@
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_freroll_loops,
-                               options::OPT_fno_reroll_loops))
+                               options::OPT_fno_reroll_loops)) {
     if (A->getOption().matches(options::OPT_freroll_loops))
       CmdArgs.push_back("-freroll-loops");
+  } else if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+    // If rerolling is not explicitly enabled or disabled, then enable when
+    // optimizing for size.
+    if (A->getOption().matches(options::OPT_O)) {
+      StringRef S(A->getValue());
+      if (S == "s" || S == "z")
+        CmdArgs.push_back("-freroll-loops");
+    }
+  }
 
   Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
   Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25387.74007.patch
Type: text/x-patch
Size: 2100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161008/d971c578/attachment-0001.bin>


More information about the cfe-commits mailing list