diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-06-24 19:34:46 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-06-24 19:34:46 +0000 |
commit | 3b3e954ea2a48d0d466dec383f6bfa40a90dd0e1 (patch) | |
tree | 1aa8c2d5969c527ac4bafc5c71fe4dfd39fa9ae2 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | f15064871ad933370532f068eca70fb5134ba69f (diff) | |
download | llvm-3b3e954ea2a48d0d466dec383f6bfa40a90dd0e1.zip llvm-3b3e954ea2a48d0d466dec383f6bfa40a90dd0e1.tar.gz llvm-3b3e954ea2a48d0d466dec383f6bfa40a90dd0e1.tar.bz2 |
SimplifyInstruction does not imply DCE
We cannot remove an instruction with no uses just because
SimplifyInstruction succeeds. It may have side effects.
llvm-svn: 273711
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 4f8935d..4d76aae 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -456,14 +456,23 @@ simplifyAndDCEInstruction(Instruction *I, if (Value *SimpleV = SimplifyInstruction(I, DL)) { // Add the users to the worklist. CAREFUL: an instruction can use itself, // in the case of a phi node. - for (User *U : I->users()) - if (U != I) + for (User *U : I->users()) { + if (U != I) { WorkList.insert(cast<Instruction>(U)); + } + } // Replace the instruction with its simplified value. - I->replaceAllUsesWith(SimpleV); - I->eraseFromParent(); - return true; + bool Changed = false; + if (!I->use_empty()) { + I->replaceAllUsesWith(SimpleV); + Changed = true; + } + if (isInstructionTriviallyDead(I, TLI)) { + I->eraseFromParent(); + Changed = true; + } + return Changed; } return false; } |