Oz optimization level sets ForceSizeOpt attribute for each function
authorQuentin Colombet <qcolombet@apple.com>
Fri, 26 Oct 2012 00:29:48 +0000 (00:29 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Fri, 26 Oct 2012 00:29:48 +0000 (00:29 +0000)
llvm-svn: 166744

clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/attr-forcesizeopt.c [new file with mode: 0644]

index b356e64..f09332e 100644 (file)
@@ -968,6 +968,8 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
 
   if (CodeGenOpts.OptimizeSize)
     FuncAttrs.addAttribute(llvm::Attributes::OptimizeForSize);
+  if (CodeGenOpts.OptimizeSize == 2)
+    FuncAttrs.addAttribute(llvm::Attributes::ForceSizeOpt);
   if (CodeGenOpts.DisableRedZone)
     FuncAttrs.addAttribute(llvm::Attributes::NoRedZone);
   if (CodeGenOpts.NoImplicitFloat)
diff --git a/clang/test/CodeGen/attr-forcesizeopt.c b/clang/test/CodeGen/attr-forcesizeopt.c
new file mode 100644 (file)
index 0000000..c4e6c4a
--- /dev/null
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -Oz -emit-llvm %s -o - | FileCheck %s -check-prefix=Oz
+// RUN: %clang_cc1 -O0 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
+// RUN: %clang_cc1 -O1 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
+// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
+// RUN: %clang_cc1 -O3 -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
+// RUN: %clang_cc1 -Os -emit-llvm %s -o - | FileCheck %s -check-prefix=OTHER
+// Check that we set the forcesizeopt attribute on each function
+// when Oz optimization level is set.
+
+int test1() {
+  return 42;
+// Oz: @test1{{.*}}forcesizeopt
+// Oz: ret
+// OTHER: @test1
+// OTHER-NOT: forcesizeopt
+// OTHER: ret
+}
+
+int test2() {
+  return 42;
+// Oz: @test2{{.*}}forcesizeopt
+// Oz: ret
+// OTHER: @test2
+// OTHER-NOT: forcesizeopt
+// OTHER: ret
+}