fix minsize detection: minsize attribute implies optimizing for size
authorSanjay Patel <spatel@rotateright.com>
Tue, 11 Aug 2015 19:39:36 +0000 (19:39 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 11 Aug 2015 19:39:36 +0000 (19:39 +0000)
Also, add a test for optsize because this was not part of any existing regression test.

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

lib/CodeGen/CodeGenPrepare.cpp
test/CodeGen/X86/slow-div.ll

index 3768807702b515fe9e0bb25e85a7c0ef2f750363..9e0ac96ba56a40bf59d9fce39daba083c93c43e1 100644 (file)
@@ -214,8 +214,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
     TLI = TM->getSubtargetImpl(F)->getTargetLowering();
   TLInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
   TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
-  // FIXME: Use Function::optForSize().
-  OptSize = F.hasFnAttribute(Attribute::OptimizeForSize);
+  OptSize = F.optForSize();
 
   /// This optimization identifies DIV instructions that can be
   /// profitably bypassed and carried out with a shorter, faster divide.
index 52223824bf96132ecfcd5ad8d4c2c87de3dffd30..82928521ac2b28c0ddbe07d3951aa736a9473fa2 100644 (file)
@@ -25,4 +25,19 @@ entry:
   ret i64 %div
 }
 
+; Verify that no extra code is generated when optimizing for size.
+
+define i32 @div32_optsize(i32 %a, i32 %b) optsize {
+; DIV32-LABEL: div32_optsize:
+; DIV32-NOT: divb
+  %div = sdiv i32 %a, %b
+  ret i32 %div
+}
+
+define i32 @div32_minsize(i32 %a, i32 %b) minsize {
+; DIV32-LABEL: div32_minsize:
+; DIV32-NOT: divb
+  %div = sdiv i32 %a, %b
+  ret i32 %div
+}