diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-22 19:24:37 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-22 19:24:37 +0000 |
commit | 9fb6e0ba58b03a642576268db2c6a7b8a64aa32b (patch) | |
tree | d64ffe0e0bb545c148cc0533b3564bb549a6bd84 /llvm/lib/Transforms | |
parent | d89125a5d8827b3f427a14ad5fe7e190b7cee3cd (diff) | |
download | bcm5719-llvm-9fb6e0ba58b03a642576268db2c6a7b8a64aa32b.tar.gz bcm5719-llvm-9fb6e0ba58b03a642576268db2c6a7b8a64aa32b.zip |
StructurizeCFG: Fix inverting a branch on an argument
llvm-svn: 195492
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/StructurizeCFG.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp index 72fea80e65a..0124dfdbeb1 100644 --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/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 |