1 //===-- PredicateSimplifier.cpp - Path Sensitive Simplifier -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Nick Lewycky and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===------------------------------------------------------------------===//
10 // Path-sensitive optimizer. In a branch where x == y, replace uses of
11 // x with y. Permits further optimization, such as the elimination of
12 // the unreachable call:
14 // void test(int *p, int *q)
20 // foo(); // unreachable
23 //===------------------------------------------------------------------===//
25 // This optimization works by substituting %q for %p when protected by a
26 // conditional that assures us of that fact. Properties are stored as
27 // relationships between two values.
29 //===------------------------------------------------------------------===//
31 #define DEBUG_TYPE "predsimplify"
32 #include "llvm/Transforms/Scalar.h"
33 #include "llvm/Constants.h"
34 #include "llvm/Instructions.h"
35 #include "llvm/Pass.h"
36 #include "llvm/ADT/Statistic.h"
37 #include "llvm/ADT/STLExtras.h"
38 #include "llvm/Analysis/Dominators.h"
39 #include "llvm/Support/CFG.h"
40 #include "llvm/Support/Debug.h"
44 typedef DominatorTree::Node DTNodeType;
48 NumVarsReplaced("predsimplify", "Number of argument substitutions");
50 NumInstruction("predsimplify", "Number of instructions removed");
52 NumSwitchCases("predsimplify", "Number of switch cases removed");
54 NumBranches("predsimplify", "Number of branches made unconditional");
56 /// Returns true if V1 is a better choice than V2. Note that it is
57 /// not a total ordering.
59 bool operator()(Value *V1, Value *V2) const {
60 if (isa<Constant>(V1)) {
61 if (!isa<Constant>(V2)) {
64 } else if (isa<Argument>(V1)) {
65 if (!isa<Constant>(V2) && !isa<Argument>(V2)) {
69 if (User *U = dyn_cast<User>(V2)) {
70 for (User::const_op_iterator I = U->op_begin(), E = U->op_end();
81 /// Used for choosing the canonical Value in a synonym set.
82 /// Leaves the better choice in V1.
83 static void order(Value *&V1, Value *&V2) {
89 /// Similar to EquivalenceClasses, this stores the set of equivalent
90 /// types. Beyond EquivalenceClasses, it allows the user to specify
91 /// which element will act as leader through a StrictWeakOrdering
93 template<typename ElemTy, typename StrictWeak>
94 class VISIBILITY_HIDDEN Synonyms {
95 std::map<ElemTy, unsigned> mapping;
96 std::vector<ElemTy> leaders;
100 typedef unsigned iterator;
101 typedef const unsigned const_iterator;
106 return leaders.empty();
109 unsigned countLeaders() const {
110 return leaders.size();
113 iterator findLeader(ElemTy e) {
114 typename std::map<ElemTy, unsigned>::iterator MI = mapping.find(e);
115 if (MI == mapping.end()) return 0;
120 const_iterator findLeader(ElemTy e) const {
121 typename std::map<ElemTy, unsigned>::const_iterator MI =
123 if (MI == mapping.end()) return 0;
128 ElemTy &getLeader(iterator I) {
129 assert(I != 0 && "Element zero is out of range.");
130 assert(I <= leaders.size() && "Invalid iterator.");
134 const ElemTy &getLeader(const_iterator I) const {
135 assert(I != 0 && "Element zero is out of range.");
140 void debug(std::ostream &os) const {
141 std::set<Value *> Unique;
142 for (unsigned i = 1, e = leaders.size()+1; i != e; ++i) {
143 Unique.insert(getLeader(i));
144 os << i << ". " << *getLeader(i) << ": [";
145 for (std::map<Value *, unsigned>::const_iterator
146 I = mapping.begin(), E = mapping.end(); I != E; ++I) {
147 if ((*I).second == i && (*I).first != leaders[i-1]) {
148 os << *(*I).first << " ";
153 assert(Unique.size() == leaders.size() && "Duplicate leaders.");
155 for (typename std::map<ElemTy, unsigned>::const_iterator
156 I = mapping.begin(), E = mapping.end(); I != E; ++I) {
157 assert(I->second != 0 && "Zero iterator in mapping.");
158 assert(I->second <= leaders.size() &&
159 "Invalid iterator found in mapping.");
166 /// Combine two sets referring to the same element, inserting the
167 /// elements as needed. Returns a valid iterator iff two already
168 /// existing disjoint synonym sets were combined. The iterator
169 /// points to the removed element.
170 iterator unionSets(ElemTy E1, ElemTy E2) {
171 if (swo(E2, E1)) std::swap(E1, E2);
173 iterator I1 = findLeader(E1),
176 if (!I1 && !I2) { // neither entry is in yet
177 leaders.push_back(E1);
186 std::swap(getLeader(I2), E1);
195 if (I1 == I2) return 0;
197 // This is the case where we have two sets, [%a1, %a2, %a3] and
198 // [%p1, %p2, %p3] and someone says that %a2 == %p3. We need to
199 // combine the two synsets.
203 for (std::map<Value *, unsigned>::iterator I = mapping.begin(),
204 E = mapping.end(); I != E; ++I) {
205 if (I->second == I2) I->second = I1;
206 else if (I->second > I2) --I->second;
209 leaders.erase(leaders.begin() + I2 - 1);
214 /// Returns an iterator pointing to the synonym set containing
215 /// element e. If none exists, a new one is created and returned.
216 iterator findOrInsert(ElemTy e) {
217 iterator I = findLeader(e);
220 leaders.push_back(e);
227 /// Represents the set of equivalent Value*s and provides insertion
228 /// and fast lookup. Also stores the set of inequality relationships.
232 class Synonyms<Value *, compare> union_find;
234 typedef std::vector<Property>::iterator PropertyIterator;
235 typedef std::vector<Property>::const_iterator ConstPropertyIterator;
236 typedef Synonyms<Value *, compare>::iterator SynonymIterator;
243 Value *canonicalize(Value *V) const {
244 Value *C = lookup(V);
248 Value *lookup(Value *V) const {
249 Synonyms<Value *, compare>::iterator SI = union_find.findLeader(V);
250 if (!SI) return NULL;
251 return union_find.getLeader(SI);
255 return union_find.empty();
258 void addEqual(Value *V1, Value *V2) {
259 // If %x = 0. and %y = -0., seteq %x, %y is true, but
260 // copysign(%x) is not the same as copysign(%y).
261 if (V1->getType()->isFloatingPoint()) return;
264 if (isa<Constant>(V2)) return; // refuse to set false == true.
266 DEBUG(std::cerr << "equal: " << *V1 << " and " << *V2 << "\n");
267 SynonymIterator deleted = union_find.unionSets(V1, V2);
269 SynonymIterator replacement = union_find.findLeader(V1);
271 for (PropertyIterator I = Properties.begin(), E = Properties.end();
273 if (I->I1 == deleted) I->I1 = replacement;
274 else if (I->I1 > deleted) --I->I1;
275 if (I->I2 == deleted) I->I2 = replacement;
276 else if (I->I2 > deleted) --I->I2;
279 addImpliedProperties(EQ, V1, V2);
282 void addNotEqual(Value *V1, Value *V2) {
283 // If %x = NAN then seteq %x, %x is false.
284 if (V1->getType()->isFloatingPoint()) return;
286 // For example, %x = setne int 0, 0 causes "0 != 0".
287 if (isa<Constant>(V1) && isa<Constant>(V2)) return;
289 DEBUG(std::cerr << "not equal: " << *V1 << " and " << *V2 << "\n");
290 if (findProperty(NE, V1, V2) != Properties.end())
294 SynonymIterator I1 = union_find.findOrInsert(V1),
295 I2 = union_find.findOrInsert(V2);
297 // Technically this means that the block is unreachable.
298 if (I1 == I2) return;
300 Properties.push_back(Property(NE, I1, I2));
301 addImpliedProperties(NE, V1, V2);
304 PropertyIterator findProperty(Ops Opcode, Value *V1, Value *V2) {
305 assert(Opcode != EQ && "Can't findProperty on EQ."
306 "Use the lookup method instead.");
308 SynonymIterator I1 = union_find.findLeader(V1),
309 I2 = union_find.findLeader(V2);
310 if (!I1 || !I2) return Properties.end();
313 find(Properties.begin(), Properties.end(), Property(Opcode, I1, I2));
316 ConstPropertyIterator
317 findProperty(Ops Opcode, Value *V1, Value *V2) const {
318 assert(Opcode != EQ && "Can't findProperty on EQ."
319 "Use the lookup method instead.");
321 SynonymIterator I1 = union_find.findLeader(V1),
322 I2 = union_find.findLeader(V2);
323 if (!I1 || !I2) return Properties.end();
326 find(Properties.begin(), Properties.end(), Property(Opcode, I1, I2));
330 // Represents Head OP [Tail1, Tail2, ...]
331 // For example: %x != %a, %x != %b.
332 struct VISIBILITY_HIDDEN Property {
333 typedef Synonyms<Value *, compare>::iterator Iter;
335 Property(Ops opcode, Iter i1, Iter i2)
336 : Opcode(opcode), I1(i1), I2(i2)
337 { assert(opcode != EQ && "Equality belongs in the synonym set, "
338 "not a property."); }
340 bool operator==(const Property &P) const {
341 return (Opcode == P.Opcode) &&
342 ((I1 == P.I1 && I2 == P.I2) ||
343 (I1 == P.I2 && I2 == P.I1));
350 void add(Ops Opcode, Value *V1, Value *V2, bool invert) {
353 if (invert) addNotEqual(V1, V2);
354 else addEqual(V1, V2);
357 if (invert) addEqual(V1, V2);
358 else addNotEqual(V1, V2);
361 assert(0 && "Unknown property opcode.");
365 // Finds the properties implied by an equivalence and adds them too.
366 // Example: ("seteq %a, %b", true, EQ) --> (%a, %b, EQ)
367 // ("seteq %a, %b", false, EQ) --> (%a, %b, NE)
368 void addImpliedProperties(Ops Opcode, Value *V1, Value *V2) {
371 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V2)) {
372 switch (BO->getOpcode()) {
373 case Instruction::SetEQ:
374 if (V1 == ConstantBool::True)
375 add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
376 if (V1 == ConstantBool::False)
377 add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
379 case Instruction::SetNE:
380 if (V1 == ConstantBool::True)
381 add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
382 if (V1 == ConstantBool::False)
383 add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
385 case Instruction::SetLT:
386 case Instruction::SetGT:
387 if (V1 == ConstantBool::True)
388 add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
390 case Instruction::SetLE:
391 case Instruction::SetGE:
392 if (V1 == ConstantBool::False)
393 add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
395 case Instruction::And:
396 if (V1 == ConstantBool::True) {
397 add(Opcode, ConstantBool::True, BO->getOperand(0), false);
398 add(Opcode, ConstantBool::True, BO->getOperand(1), false);
401 case Instruction::Or:
402 if (V1 == ConstantBool::False) {
403 add(Opcode, ConstantBool::False, BO->getOperand(0), false);
404 add(Opcode, ConstantBool::False, BO->getOperand(1), false);
407 case Instruction::Xor:
408 if (V1 == ConstantBool::True) {
409 if (BO->getOperand(0) == ConstantBool::True)
410 add(Opcode, ConstantBool::False, BO->getOperand(1), false);
411 if (BO->getOperand(1) == ConstantBool::True)
412 add(Opcode, ConstantBool::False, BO->getOperand(0), false);
414 if (V1 == ConstantBool::False) {
415 if (BO->getOperand(0) == ConstantBool::True)
416 add(Opcode, ConstantBool::True, BO->getOperand(1), false);
417 if (BO->getOperand(1) == ConstantBool::True)
418 add(Opcode, ConstantBool::True, BO->getOperand(0), false);
424 } else if (SelectInst *SI = dyn_cast<SelectInst>(V2)) {
425 if (Opcode != EQ && Opcode != NE) return;
427 ConstantBool *True = (Opcode==EQ) ? ConstantBool::True
428 : ConstantBool::False,
429 *False = (Opcode==EQ) ? ConstantBool::False
430 : ConstantBool::True;
432 if (V1 == SI->getTrueValue())
433 addEqual(SI->getCondition(), True);
434 else if (V1 == SI->getFalseValue())
435 addEqual(SI->getCondition(), False);
436 else if (Opcode == EQ)
437 assert("Result of select not equal to either value.");
443 void debug(std::ostream &os) const {
444 static const char *OpcodeTable[] = { "EQ", "NE" };
446 unsigned int size = union_find.countLeaders();
448 union_find.debug(os);
449 for (std::vector<Property>::const_iterator I = Properties.begin(),
450 E = Properties.end(); I != E; ++I) {
451 os << (*I).I1 << " " << OpcodeTable[(*I).Opcode] << " "
453 assert((*I).I1 <= size && "Invalid property.");
454 assert((*I).I2 <= size && "Invalid property.");
460 std::vector<Property> Properties;
463 /// PredicateSimplifier - This class is a simplifier that replaces
464 /// one equivalent variable with another. It also tracks what
465 /// can't be equal and will solve setcc instructions when possible.
466 class PredicateSimplifier : public FunctionPass {
468 bool runOnFunction(Function &F);
469 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
472 // Try to replace the Use of the instruction with something simpler.
473 Value *resolve(SetCondInst *SCI, const PropertySet &);
474 Value *resolve(BinaryOperator *BO, const PropertySet &);
475 Value *resolve(SelectInst *SI, const PropertySet &);
476 Value *resolve(Value *V, const PropertySet &);
478 // Used by terminator instructions to proceed from the current basic
479 // block to the next. Verifies that "current" dominates "next",
480 // then calls visitBasicBlock.
481 void proceedToSuccessor(PropertySet &CurrentPS, PropertySet &NextPS,
482 DTNodeType *Current, DTNodeType *Next);
483 void proceedToSuccessor(PropertySet &CurrentPS,
484 DTNodeType *Current, DTNodeType *Next);
486 // Visits each instruction in the basic block.
487 void visitBasicBlock(DTNodeType *DTNode, PropertySet &KnownProperties);
489 // Tries to simplify each Instruction and add new properties to
490 // the PropertySet. Returns true if it erase the instruction.
491 void visitInstruction(Instruction *I, DTNodeType *, PropertySet &);
492 // For each instruction, add the properties to KnownProperties.
494 void visit(TerminatorInst *TI, DTNodeType *, PropertySet &);
495 void visit(BranchInst *BI, DTNodeType *, PropertySet &);
496 void visit(SwitchInst *SI, DTNodeType *, PropertySet);
497 void visit(LoadInst *LI, DTNodeType *, PropertySet &);
498 void visit(StoreInst *SI, DTNodeType *, PropertySet &);
499 void visit(BinaryOperator *BO, DTNodeType *, PropertySet &);
505 RegisterPass<PredicateSimplifier> X("predsimplify",
506 "Predicate Simplifier");
509 FunctionPass *llvm::createPredicateSimplifierPass() {
510 return new PredicateSimplifier();
513 bool PredicateSimplifier::runOnFunction(Function &F) {
514 DT = &getAnalysis<DominatorTree>();
517 PropertySet KnownProperties;
518 visitBasicBlock(DT->getRootNode(), KnownProperties);
522 void PredicateSimplifier::getAnalysisUsage(AnalysisUsage &AU) const {
523 AU.addRequired<DominatorTree>();
526 // resolve catches cases addProperty won't because it wasn't used as a
527 // condition in the branch, and that visit won't, because the instruction
528 // was defined outside of the scope that the properties apply to.
529 Value *PredicateSimplifier::resolve(SetCondInst *SCI,
530 const PropertySet &KP) {
531 // Attempt to resolve the SetCondInst to a boolean.
533 Value *SCI0 = resolve(SCI->getOperand(0), KP),
534 *SCI1 = resolve(SCI->getOperand(1), KP);
536 ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(SCI0),
537 *CI2 = dyn_cast<ConstantIntegral>(SCI1);
540 PropertySet::ConstPropertyIterator NE =
541 KP.findProperty(PropertySet::NE, SCI0, SCI1);
543 if (NE != KP.Properties.end()) {
544 switch (SCI->getOpcode()) {
545 case Instruction::SetEQ:
546 return ConstantBool::False;
547 case Instruction::SetNE:
548 return ConstantBool::True;
549 case Instruction::SetLE:
550 case Instruction::SetGE:
551 case Instruction::SetLT:
552 case Instruction::SetGT:
555 assert(0 && "Unknown opcode in SetCondInst.");
562 switch(SCI->getOpcode()) {
563 case Instruction::SetLE:
564 case Instruction::SetGE:
565 case Instruction::SetEQ:
566 if (CI1->getRawValue() == CI2->getRawValue())
567 return ConstantBool::True;
569 return ConstantBool::False;
570 case Instruction::SetLT:
571 case Instruction::SetGT:
572 case Instruction::SetNE:
573 if (CI1->getRawValue() == CI2->getRawValue())
574 return ConstantBool::False;
576 return ConstantBool::True;
578 assert(0 && "Unknown opcode in SetContInst.");
583 Value *PredicateSimplifier::resolve(BinaryOperator *BO,
584 const PropertySet &KP) {
585 if (SetCondInst *SCI = dyn_cast<SetCondInst>(BO))
586 return resolve(SCI, KP);
588 Value *lhs = resolve(BO->getOperand(0), KP),
589 *rhs = resolve(BO->getOperand(1), KP);
590 ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(lhs);
591 ConstantIntegral *CI2 = dyn_cast<ConstantIntegral>(rhs);
593 if (!CI1 || !CI2) return BO;
595 Value *V = ConstantExpr::get(BO->getOpcode(), CI1, CI2);
600 Value *PredicateSimplifier::resolve(SelectInst *SI, const PropertySet &KP) {
601 Value *Condition = resolve(SI->getCondition(), KP);
602 if (Condition == ConstantBool::True)
603 return resolve(SI->getTrueValue(), KP);
604 else if (Condition == ConstantBool::False)
605 return resolve(SI->getFalseValue(), KP);
609 Value *PredicateSimplifier::resolve(Value *V, const PropertySet &KP) {
610 if (isa<Constant>(V) || isa<BasicBlock>(V) || KP.empty()) return V;
612 V = KP.canonicalize(V);
614 DEBUG(std::cerr << "peering into " << *V << "\n");
616 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V))
617 return resolve(BO, KP);
618 else if (SelectInst *SI = dyn_cast<SelectInst>(V))
619 return resolve(SI, KP);
624 void PredicateSimplifier::visitBasicBlock(DTNodeType *DTNode,
625 PropertySet &KnownProperties) {
626 BasicBlock *BB = DTNode->getBlock();
627 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
628 visitInstruction(I++, DTNode, KnownProperties);
632 void PredicateSimplifier::visitInstruction(Instruction *I,
634 PropertySet &KnownProperties) {
636 DEBUG(std::cerr << "Considering instruction " << *I << "\n");
637 DEBUG(KnownProperties.debug(std::cerr));
639 // Try to replace the whole instruction.
640 Value *V = resolve(I, KnownProperties);
641 assert(V->getType() == I->getType() && "Instruction type mutated!");
645 I->replaceAllUsesWith(V);
646 I->eraseFromParent();
650 // Try to substitute operands.
651 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
652 Value *Oper = I->getOperand(i);
653 Value *V = resolve(Oper, KnownProperties);
654 assert(V->getType() == Oper->getType() && "Operand type mutated!");
658 DEBUG(std::cerr << "resolving " << *I);
660 DEBUG(std::cerr << "into " << *I);
664 if (TerminatorInst *TI = dyn_cast<TerminatorInst>(I))
665 visit(TI, DTNode, KnownProperties);
666 else if (LoadInst *LI = dyn_cast<LoadInst>(I))
667 visit(LI, DTNode, KnownProperties);
668 else if (StoreInst *SI = dyn_cast<StoreInst>(I))
669 visit(SI, DTNode, KnownProperties);
670 else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I))
671 visit(BO, DTNode, KnownProperties);
674 void PredicateSimplifier::proceedToSuccessor(PropertySet &CurrentPS,
678 if (Next->getBlock()->getSinglePredecessor() == Current->getBlock())
679 proceedToSuccessor(NextPS, Current, Next);
681 proceedToSuccessor(CurrentPS, Current, Next);
684 void PredicateSimplifier::proceedToSuccessor(PropertySet &KP,
687 if (Current->properlyDominates(Next))
688 visitBasicBlock(Next, KP);
691 void PredicateSimplifier::visit(TerminatorInst *TI, DTNodeType *Node,
693 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
697 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
702 for (unsigned i = 0, E = TI->getNumSuccessors(); i != E; ++i) {
703 BasicBlock *BB = TI->getSuccessor(i);
704 PropertySet KPcopy(KP);
705 proceedToSuccessor(KPcopy, Node, DT->getNode(TI->getSuccessor(i)));
709 void PredicateSimplifier::visit(BranchInst *BI, DTNodeType *Node,
711 if (BI->isUnconditional()) {
712 proceedToSuccessor(KP, Node, DT->getNode(BI->getSuccessor(0)));
716 Value *Condition = BI->getCondition();
718 BasicBlock *TrueDest = BI->getSuccessor(0),
719 *FalseDest = BI->getSuccessor(1);
721 if (Condition == ConstantBool::True) {
722 FalseDest->removePredecessor(BI->getParent());
723 BI->setUnconditionalDest(TrueDest);
726 proceedToSuccessor(KP, Node, DT->getNode(TrueDest));
728 } else if (Condition == ConstantBool::False) {
729 TrueDest->removePredecessor(BI->getParent());
730 BI->setUnconditionalDest(FalseDest);
733 proceedToSuccessor(KP, Node, DT->getNode(FalseDest));
737 PropertySet TrueProperties(KP), FalseProperties(KP);
738 DEBUG(std::cerr << "true set:\n");
739 TrueProperties.addEqual(ConstantBool::True, Condition);
740 DEBUG(TrueProperties.debug(std::cerr));
741 DEBUG(std::cerr << "false set:\n");
742 FalseProperties.addEqual(ConstantBool::False, Condition);
743 DEBUG(FalseProperties.debug(std::cerr));
745 PropertySet KPcopy(KP);
746 proceedToSuccessor(KP, TrueProperties, Node, DT->getNode(TrueDest));
747 proceedToSuccessor(KPcopy, FalseProperties, Node, DT->getNode(FalseDest));
750 void PredicateSimplifier::visit(SwitchInst *SI, DTNodeType *DTNode,
752 Value *Condition = SI->getCondition();
753 assert(Condition == KP.canonicalize(Condition) &&
754 "Instruction wasn't already canonicalized?");
756 // If there's an NEProperty covering this SwitchInst, we may be able to
757 // eliminate one of the cases.
758 for (PropertySet::ConstPropertyIterator I = KP.Properties.begin(),
759 E = KP.Properties.end(); I != E; ++I) {
760 if (I->Opcode != PropertySet::NE) continue;
761 Value *V1 = KP.union_find.getLeader(I->I1),
762 *V2 = KP.union_find.getLeader(I->I2);
764 // Find a Property with a ConstantInt on one side and our
765 // Condition on the other.
766 ConstantInt *CI = NULL;
768 CI = dyn_cast<ConstantInt>(V2);
769 else if (V2 == Condition)
770 CI = dyn_cast<ConstantInt>(V1);
774 unsigned i = SI->findCaseValue(CI);
775 if (i != 0) { // zero is reserved for the default case.
776 SI->getSuccessor(i)->removePredecessor(SI->getParent());
783 // Set the EQProperty in each of the cases BBs,
784 // and the NEProperties in the default BB.
785 PropertySet DefaultProperties(KP);
787 DTNodeType *Node = DT->getNode(SI->getParent()),
788 *DefaultNode = DT->getNode(SI->getSuccessor(0));
789 if (!Node->dominates(DefaultNode)) DefaultNode = NULL;
791 for (unsigned I = 1, E = SI->getNumCases(); I < E; ++I) {
792 ConstantInt *CI = SI->getCaseValue(I);
794 BasicBlock *SuccBB = SI->getSuccessor(I);
795 PropertySet copy(KP);
796 if (SuccBB->getSinglePredecessor()) {
797 PropertySet NewProperties(KP);
798 NewProperties.addEqual(Condition, CI);
799 proceedToSuccessor(copy, NewProperties, DTNode, DT->getNode(SuccBB));
801 proceedToSuccessor(copy, DTNode, DT->getNode(SuccBB));
804 DefaultProperties.addNotEqual(Condition, CI);
808 proceedToSuccessor(DefaultProperties, DTNode, DefaultNode);
811 void PredicateSimplifier::visit(LoadInst *LI, DTNodeType *,
813 Value *Ptr = LI->getPointerOperand();
814 KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
817 void PredicateSimplifier::visit(StoreInst *SI, DTNodeType *,
819 Value *Ptr = SI->getPointerOperand();
820 KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
823 void PredicateSimplifier::visit(BinaryOperator *BO, DTNodeType *,
825 Instruction::BinaryOps ops = BO->getOpcode();
828 case Instruction::Div:
829 case Instruction::Rem: {
830 Value *Divisor = BO->getOperand(1);
831 KP.addNotEqual(Constant::getNullValue(Divisor->getType()), Divisor);