[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Jun 3 23:47:01 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.86 -> 1.87

---
Log message:

Implement combination of boolean not with branch


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.86 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.87
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.86	Sat May 31 22:35:25 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Tue Jun  3 23:46:00 2003
@@ -76,6 +76,7 @@
     Instruction *visitPHINode(PHINode &PN);
     Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
     Instruction *visitAllocationInst(AllocationInst &AI);
+    Instruction *visitBranchInst(BranchInst &BI);
 
     // visitInstruction - Specify what to return for unhandled instructions...
     Instruction *visitInstruction(Instruction &I) { return 0; }
@@ -1061,6 +1062,19 @@
   return 0;
 }
 
+Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
+  // Change br (not X), label True, label False to: br X, label False, True
+  if (BI.isConditional() && BinaryOperator::isNot(BI.getCondition())) {
+    BasicBlock *TrueDest = BI.getSuccessor(0);
+    BasicBlock *FalseDest = BI.getSuccessor(1);
+    // Swap Destinations and condition...
+    BI.setCondition(BinaryOperator::getNotArgument(cast<BinaryOperator>(BI.getCondition())));
+    BI.setSuccessor(0, FalseDest);
+    BI.setSuccessor(1, TrueDest);
+    return &BI;
+  }
+  return 0;
+}
 
 
 void InstCombiner::removeFromWorkList(Instruction *I) {





More information about the llvm-commits mailing list