]> granicus.if.org Git - clang/commitdiff
When optimizing for size, enable loop rerolling by default
authorHal Finkel <hfinkel@anl.gov>
Sun, 9 Oct 2016 03:06:31 +0000 (03:06 +0000)
committerHal Finkel <hfinkel@anl.gov>
Sun, 9 Oct 2016 03:06:31 +0000 (03:06 +0000)
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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283685 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d739071e13d4e675c695938efcd4ff934ba58d6c..c1a2179673af5b6405cc00a69042efa8870f326c 100644 (file)
@@ -5227,9 +5227,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   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,
index 2952d0e111751eabf62880d3b91fa580914a5eee..f940ed974d501474e407cb88d8062c421c2c68a6 100644 (file)
 // 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"