[llvm] r223797 - [CGP] Rewrite pattern match for splitBranchCondition to work with Values instead.

Juergen Ributzka juergen at apple.com
Tue Dec 9 09:50:10 PST 2014


Author: ributzka
Date: Tue Dec  9 11:50:10 2014
New Revision: 223797

URL: http://llvm.org/viewvc/llvm-project?rev=223797&view=rev
Log:
[CGP] Rewrite pattern match for splitBranchCondition to work with Values instead.

Rewrite the pattern match code to work also with Values instead with
Instructions only. Also remove the no longer need matcher (m_Instruction).

Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=223797&r1=223796&r2=223797&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Tue Dec  9 11:50:10 2014
@@ -68,10 +68,6 @@ struct class_match {
 
 /// m_Value() - Match an arbitrary value and ignore it.
 inline class_match<Value> m_Value() { return class_match<Value>(); }
-/// m_Instruction() - Match an arbitrary instruction and ignore it.
-inline class_match<Instruction> m_Instruction() {
-  return class_match<Instruction>();
-}
 /// m_BinOp() - Match an arbitrary binary operation and ignore it.
 inline class_match<BinaryOperator> m_BinOp() {
   return class_match<BinaryOperator>();
@@ -311,9 +307,6 @@ struct bind_ty {
 /// m_Value - Match a value, capturing it if we match.
 inline bind_ty<Value> m_Value(Value *&V) { return V; }
 
-/// m_Instruction - Match a instruction, capturing it if we match.
-inline bind_ty<Instruction> m_Instruction(Instruction *&I) { return I; }
-
 /// m_BinOp - Match a instruction, capturing it if we match.
 inline bind_ty<BinaryOperator> m_BinOp(BinaryOperator *&I) { return I; }
 

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=223797&r1=223796&r2=223797&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue Dec  9 11:50:10 2014
@@ -3869,12 +3869,12 @@ bool CodeGenPrepare::splitBranchConditio
       continue;
 
     unsigned Opc;
-    Instruction *Cond1, *Cond2;
-    if (match(LogicOp, m_And(m_OneUse(m_Instruction(Cond1)),
-                             m_OneUse(m_Instruction(Cond2)))))
+    Value *Cond1, *Cond2;
+    if (match(LogicOp, m_And(m_OneUse(m_Value(Cond1)),
+                             m_OneUse(m_Value(Cond2)))))
       Opc = Instruction::And;
-    else if (match(LogicOp, m_Or(m_OneUse(m_Instruction(Cond1)),
-                                 m_OneUse(m_Instruction(Cond2)))))
+    else if (match(LogicOp, m_Or(m_OneUse(m_Value(Cond1)),
+                                 m_OneUse(m_Value(Cond2)))))
       Opc = Instruction::Or;
     else
       continue;
@@ -3897,7 +3897,7 @@ bool CodeGenPrepare::splitBranchConditio
     auto *Br1 = cast<BranchInst>(BB.getTerminator());
     Br1->setCondition(Cond1);
     LogicOp->eraseFromParent();
-    Cond2->removeFromParent();
+
     // Depending on the conditon we have to either replace the true or the false
     // successor of the original branch instruction.
     if (Opc == Instruction::And)
@@ -3907,7 +3907,10 @@ bool CodeGenPrepare::splitBranchConditio
 
     // Fill in the new basic block.
     auto *Br2 = IRBuilder<>(TmpBB).CreateCondBr(Cond2, TBB, FBB);
-    Cond2->insertBefore(Br2);
+    if (auto *I = dyn_cast<Instruction>(Cond2)) {
+      I->removeFromParent();
+      I->insertBefore(Br2);
+    }
 
     // Update PHI nodes in both successors. The original BB needs to be
     // replaced in one succesor's PHI nodes, because the branch comes now from





More information about the llvm-commits mailing list