Typo.
[oota-llvm.git] / lib / CodeGen / IfConversion.cpp
index 64328d6e04f4a6866a4d9a8adea69f2e06ca4039..3bddc771ab1daa4ee2c80bd55bf58e1dd1fc0f22 100644 (file)
@@ -84,7 +84,7 @@ namespace {
     /// IsBrAnalyzable  - True if AnalyzeBranch() returns false.
     /// HasFallThrough  - True if BB may fallthrough to the following BB.
     /// IsUnpredicable  - True if BB is known to be unpredicable.
-    /// ClobbersPredicate- True if BB would modify the predicate (e.g. has
+    /// ClobbersPred    - True if BB could modify predicates (e.g. has
     ///                   cmp, call, etc.)
     /// NonPredSize     - Number of non-predicated instructions.
     /// BB              - Corresponding MachineBasicBlock.
@@ -529,6 +529,7 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
   if (BBI.IsDone)
     return;
 
+  bool AlreadyPredicated = BBI.Predicate.size() > 0;
   // First analyze the end of BB branches.
   BBI.TrueBB = BBI.FalseBB = NULL;
   BBI.BrCond.clear();
@@ -558,8 +559,18 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
     bool isCondBr = BBI.IsBrAnalyzable &&
       (TID->Flags & M_BRANCH_FLAG) != 0 && (TID->Flags & M_BARRIER_FLAG) == 0;
 
-    if (!isPredicated && !isCondBr)
-      BBI.NonPredSize++;
+    if (!isCondBr) {
+      if (!isPredicated)
+        BBI.NonPredSize++;
+      else if (!AlreadyPredicated) {
+        // FIXME: This instruction is already predicated before the
+        // if-conversion pass. It's probably something like a conditional move.
+        // Mark this block unpredicable for now.
+        BBI.IsUnpredicable = true;
+        return;
+      }
+        
+    }
 
     if (BBI.ClobbersPred && !isPredicated) {
       // Predicate modification instruction should end the block (except for
@@ -572,12 +583,15 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
       }
 
       // Predicate may have been modified, the subsequent (currently)
-      // unpredocated instructions cannot be correctly predicated.
+      // unpredicated instructions cannot be correctly predicated.
       BBI.IsUnpredicable = true;
       return;
     }
 
-    if (TID->Flags & M_CLOBBERS_PRED)
+    // FIXME: Make use of PredDefs? e.g. ADDC, SUBC sets predicates but are
+    // still potentially predicable.
+    std::vector<MachineOperand> PredDefs;
+    if (TII->DefinesPredicate(I, PredDefs))
       BBI.ClobbersPred = true;
 
     if ((TID->Flags & M_PREDICABLE) == 0) {