From 6e39c7ed1e8b5144ee97f87612d3d3847550aadd Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Thu, 31 Aug 2006 00:39:16 +0000 Subject: [PATCH] Properties where both Values weren't in the union (as being equal to another Value) weren't being found by findProperties. This fixes predsimplify.ll test6, a missed optimization opportunity. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29991 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/PredicateSimplifier.cpp | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index fa195ebb953..7f998dac3ff 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -121,21 +121,8 @@ namespace { void addNotEqual(Value *V1, Value *V2) { DEBUG(std::cerr << "not equal: " << *V1 << " and " << *V2 << "\n"); - V1 = canonicalize(V1); - V2 = canonicalize(V2); - - // Does the property already exist? - for (PropertyIterator I = Properties.begin(), E = Properties.end(); - I != E; ++I) { - if (I->Opcode != NE) continue; - - I->V1 = canonicalize(I->V1); - I->V2 = canonicalize(I->V2); - if ((I->V1 == V1 && I->V2 == V2) || - (I->V1 == V2 && I->V2 == V1)) { - return; // Found. - } - } + if (findProperty(NE, V1, V2) != Properties.end()) + return; // found. // Add the property. Properties.push_back(Property(NE, V1, V2)); @@ -146,9 +133,8 @@ namespace { assert(Opcode != EQ && "Can't findProperty on EQ." "Use the lookup method instead."); - V1 = lookup(V1); - V2 = lookup(V2); - if (!V1 || !V2) return Properties.end(); + V1 = canonicalize(V1); + V2 = canonicalize(V2); // Does the property already exist? for (PropertyIterator I = Properties.begin(), E = Properties.end(); @@ -170,18 +156,16 @@ namespace { assert(Opcode != EQ && "Can't findProperty on EQ." "Use the lookup method instead."); - V1 = lookup(V1); - V2 = lookup(V2); - if (!V1 || !V2) return Properties.end(); + V1 = canonicalize(V1); + V2 = canonicalize(V2); // Does the property already exist? for (ConstPropertyIterator I = Properties.begin(), E = Properties.end(); I != E; ++I) { if (I->Opcode != Opcode) continue; - Value *v1 = lookup(I->V1), - *v2 = lookup(I->V2); - if (!v1 || !v2) continue; + Value *v1 = canonicalize(I->V1), + *v2 = canonicalize(I->V2); if ((v1 == V1 && v2 == V2) || (v1 == V2 && v2 == V1)) { return I; // Found. @@ -291,6 +275,14 @@ namespace { public: void debug(std::ostream &os) const { + for (EquivalenceClasses::iterator I = union_find.begin(), + E = union_find.end(); I != E; ++I) { + if (!I->isLeader()) continue; + for (EquivalenceClasses::member_iterator MI = + union_find.member_begin(I); MI != union_find.member_end(); ++MI) + std::cerr << **MI << " "; + std::cerr << "\n--\n"; + } } std::vector Properties; @@ -571,8 +563,10 @@ void PredicateSimplifier::visit(BranchInst *BI, PropertySet TrueProperties(KP), FalseProperties(KP); DEBUG(std::cerr << "true set:\n"); TrueProperties.addEqual(ConstantBool::True, Condition); + DEBUG(TrueProperties.debug(std::cerr)); DEBUG(std::cerr << "false set:\n"); FalseProperties.addEqual(ConstantBool::False, Condition); + DEBUG(FalseProperties.debug(std::cerr)); PropertySet KPcopy(KP); proceedToSuccessor(KP, TrueProperties, Node, DT->getNode(TrueDest)); -- 2.34.1