Reprioritize tests for tail duplication to be aggressive about indirect
authorBob Wilson <bob.wilson@apple.com>
Mon, 30 Nov 2009 18:56:45 +0000 (18:56 +0000)
committerBob Wilson <bob.wilson@apple.com>
Mon, 30 Nov 2009 18:56:45 +0000 (18:56 +0000)
branches even when optimizing for code size.  Unless we find evidence to the
contrary in the future, the special treatment for indirect branches does not
have a significant effect on code size, and performance still matters with -Os.

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

lib/CodeGen/TailDuplication.cpp

index 68fa2099c814f02350d7561ebe7cc48765cdcf80..9c0b596c33f5a6dddc7637507dad6e13861e3fdf 100644 (file)
@@ -116,14 +116,14 @@ bool TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB,
   // duplicate only one, because one branch instruction can be eliminated to
   // compensate for the duplication.
   unsigned MaxDuplicateCount;
-  if (MF.getFunction()->hasFnAttr(Attribute::OptimizeForSize))
-    MaxDuplicateCount = 1;
-  else if (!TailBB->empty() && TailBB->back().getDesc().isIndirectBranch())
+  if (!TailBB->empty() && TailBB->back().getDesc().isIndirectBranch())
     // If the target has hardware branch prediction that can handle indirect
     // branches, duplicating them can often make them predictable when there
     // are common paths through the code.  The limit needs to be high enough
     // to allow undoing the effects of tail merging.
     MaxDuplicateCount = 20;
+  else if (MF.getFunction()->hasFnAttr(Attribute::OptimizeForSize))
+    MaxDuplicateCount = 1;
   else
     MaxDuplicateCount = TailDuplicateSize;