[llvm-commits] CVS: llvm/lib/CodeGen/IfConversion.cpp

Evan Cheng evan.cheng at apple.com
Fri Jun 15 14:18:27 PDT 2007



Changes in directory llvm/lib/CodeGen:

IfConversion.cpp updated: 1.53 -> 1.54
---
Log message:

Not every predicable block can be safely duplicated.

---
Diffs of the changes:  (+35 -8)

 IfConversion.cpp |   43 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 35 insertions(+), 8 deletions(-)


Index: llvm/lib/CodeGen/IfConversion.cpp
diff -u llvm/lib/CodeGen/IfConversion.cpp:1.53 llvm/lib/CodeGen/IfConversion.cpp:1.54
--- llvm/lib/CodeGen/IfConversion.cpp:1.53	Fri Jun 15 14:06:07 2007
+++ llvm/lib/CodeGen/IfConversion.cpp	Fri Jun 15 16:18:05 2007
@@ -100,6 +100,7 @@
       bool IsBrAnalyzable  : 1;
       bool HasFallThrough  : 1;
       bool IsUnpredicable  : 1;
+      bool CannotBeCopied  : 1;
       bool ClobbersPred    : 1;
       unsigned NonPredSize;
       MachineBasicBlock *BB;
@@ -111,7 +112,7 @@
       BBInfo() : Kind(ICNotClassfied), IsDone(false), IsBeingAnalyzed(false),
                  IsAnalyzed(false), IsEnqueued(false), IsBrAnalyzable(false),
                  HasFallThrough(false), IsUnpredicable(false),
-                 ClobbersPred(false), NonPredSize(0),
+                 CannotBeCopied(false), ClobbersPred(false), NonPredSize(0),
                  BB(0), TrueBB(0), FalseBB(0), TailBB(0) {}
     };
 
@@ -334,8 +335,9 @@
   if (TrueBBI.IsBeingAnalyzed)
     return false;
 
-  if (TrueBBI.BB->pred_size() != 1) {
-    if (TrueBBI.NonPredSize > TLI->getIfCvtDupBlockSizeLimit())
+  if (TrueBBI.BB->pred_size() > 1) {
+    if (TrueBBI.CannotBeCopied ||
+        TrueBBI.NonPredSize > TLI->getIfCvtDupBlockSizeLimit())
       return false;
   }
 
@@ -349,7 +351,10 @@
   if (TrueBBI.IsBeingAnalyzed)
     return false;
 
-  if (TrueBBI.BB->pred_size() != 1) {
+  if (TrueBBI.BB->pred_size() > 1) {
+    if (TrueBBI.CannotBeCopied)
+      return false;
+
     unsigned Size = TrueBBI.NonPredSize;
     if (TrueBBI.FalseBB)
       ++Size;
@@ -420,6 +425,9 @@
   bool SeenCondBr = false;
   for (MachineBasicBlock::iterator I = BBI.BB->begin(), E = BBI.BB->end();
        I != E; ++I) {
+    if (!BBI.CannotBeCopied && !TII->CanBeDuplicated(I))
+      BBI.CannotBeCopied = true;
+
     const TargetInstrDescriptor *TID = I->getInstrDescriptor();
     bool isPredicated = TII->isPredicated(I);
     bool isCondBr = BBI.IsBrAnalyzable &&
@@ -721,11 +729,20 @@
   BBInfo *NextBBI = &FalseBBI;
 
   std::vector<MachineOperand> Cond(BBI.BrCond);
-  if (BBI.Kind == ICSimpleFalse) {
+  if (BBI.Kind == ICSimpleFalse)
     std::swap(CvtBBI, NextBBI);
-    TII->ReverseBranchCondition(Cond);
+
+  if (CvtBBI->CannotBeCopied && CvtBBI->BB->pred_size() > 1) {
+    // Something has changed. It's no longer safe to predicate this block.
+    BBI.Kind = ICNotClassfied;
+    BBI.IsAnalyzed = false;
+    CvtBBI->IsAnalyzed = false;
+    return false;
   }
 
+  if (BBI.Kind == ICSimpleFalse)
+    TII->ReverseBranchCondition(Cond);
+
   if (CvtBBI->BB->pred_size() > 1) {
     BBI.NonPredSize -= TII->RemoveBranch(*BBI.BB);
     // Copy instructions in the true block, predicate them add them to
@@ -777,10 +794,20 @@
   BBInfo *NextBBI = &FalseBBI;
 
   std::vector<MachineOperand> Cond(BBI.BrCond);
-  if (BBI.Kind == ICTriangleFalse || BBI.Kind == ICTriangleFRev) {
+  if (BBI.Kind == ICTriangleFalse || BBI.Kind == ICTriangleFRev)
     std::swap(CvtBBI, NextBBI);
-    TII->ReverseBranchCondition(Cond);
+
+  if (CvtBBI->CannotBeCopied && CvtBBI->BB->pred_size() > 1) {
+    // Something has changed. It's no longer safe to predicate this block.
+    BBI.Kind = ICNotClassfied;
+    BBI.IsAnalyzed = false;
+    CvtBBI->IsAnalyzed = false;
+    return false;
   }
+
+  if (BBI.Kind == ICTriangleFalse || BBI.Kind == ICTriangleFRev)
+    TII->ReverseBranchCondition(Cond);
+
   if (BBI.Kind == ICTriangleRev || BBI.Kind == ICTriangleFRev) {
     ReverseBranchCondition(*CvtBBI);
     // BB has been changed, modify its predecessors (except for this






More information about the llvm-commits mailing list