diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-11-25 05:22:53 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-11-25 05:22:53 +0000 |
commit | 215aad562cbff81f5b1ce5b570076b88a87998f8 (patch) | |
tree | b0ffce9779a5640d8db33fad5fb143012ad44b96 /lib/Transforms/Scalar | |
parent | f02a188899769cde2315c964f0fbed1d024b7514 (diff) | |
download | external_llvm-215aad562cbff81f5b1ce5b570076b88a87998f8.zip external_llvm-215aad562cbff81f5b1ce5b570076b88a87998f8.tar.gz external_llvm-215aad562cbff81f5b1ce5b570076b88a87998f8.tar.bz2 |
Merging r195492:
------------------------------------------------------------------------
r195492 | arsenm | 2013-11-22 11:24:37 -0800 (Fri, 22 Nov 2013) | 1 line
StructurizeCFG: Fix inverting a branch on an argument
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195605 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/StructurizeCFG.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/StructurizeCFG.cpp b/lib/Transforms/Scalar/StructurizeCFG.cpp index 72fea80..0124dfd 100644 --- a/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -323,21 +323,32 @@ Value *StructurizeCFG::invert(Value *Condition) { if (match(Condition, m_Not(m_Value(Condition)))) return Condition; - // Third: Check all the users for an invert - BasicBlock *Parent = cast<Instruction>(Condition)->getParent(); - for (Value::use_iterator I = Condition->use_begin(), - E = Condition->use_end(); I != E; ++I) { + if (Instruction *Inst = dyn_cast<Instruction>(Condition)) { + // Third: Check all the users for an invert + BasicBlock *Parent = Inst->getParent(); + for (Value::use_iterator I = Condition->use_begin(), + E = Condition->use_end(); I != E; ++I) { + + Instruction *User = dyn_cast<Instruction>(*I); + if (!User || User->getParent() != Parent) + continue; - Instruction *User = dyn_cast<Instruction>(*I); - if (!User || User->getParent() != Parent) - continue; + if (match(*I, m_Not(m_Specific(Condition)))) + return *I; + } + + // Last option: Create a new instruction + return BinaryOperator::CreateNot(Condition, "", Parent->getTerminator()); + } - if (match(*I, m_Not(m_Specific(Condition)))) - return *I; + if (Argument *Arg = dyn_cast<Argument>(Condition)) { + BasicBlock &EntryBlock = Arg->getParent()->getEntryBlock(); + return BinaryOperator::CreateNot(Condition, + Arg->getName() + ".inv", + EntryBlock.getTerminator()); } - // Last option: Create a new instruction - return BinaryOperator::CreateNot(Condition, "", Parent->getTerminator()); + llvm_unreachable("Unhandled condition to invert"); } /// \brief Build the condition for one edge |