If "optimize for size" attribute is set then block non-trivial loop unswitches but...
authorDevang Patel <dpatel@apple.com>
Tue, 3 Feb 2009 22:04:27 +0000 (22:04 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 3 Feb 2009 22:04:27 +0000 (22:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63670 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnswitch.cpp

index a563c7a9ee92aa10ae7297f62b0549c4afe45bf1..436e6a5786ce266fb76c86987b1370c17fdb80af 100644 (file)
@@ -430,9 +430,6 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val){
   initLoopData();
   Function *F = loopHeader->getParent();
 
-  // Do not unswitch if the function is optimized for size.
-  if (!F->isDeclaration() && F->hasFnAttr(Attribute::OptimizeForSize))
-    return false;
 
   // Check to see if it would be profitable to unswitch current loop.
   unsigned Cost = getLoopUnswitchCost(LoopCond);
@@ -440,6 +437,8 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val){
   // Do not do non-trivial unswitch while optimizing for size.
   if (Cost && OptimizeForSize)
     return false;
+  if (Cost && !F->isDeclaration() && F->hasFnAttr(Attribute::OptimizeForSize))
+    return false;
 
   if (Cost > Threshold) {
     // FIXME: this should estimate growth by the amount of code shared by the