diff options
author | Sam Parker <sam.parker@arm.com> | 2020-02-06 13:53:09 +0000 |
---|---|---|
committer | Sam Parker <sam.parker@arm.com> | 2020-02-06 14:06:08 +0000 |
commit | 0a8cae10feb283b7a0886c5b52055de3db8b0e10 (patch) | |
tree | 33737ce70d2ae001d9a9d196e8e01b2b3a414e60 /llvm/lib/CodeGen/ReachingDefAnalysis.cpp | |
parent | 09a88120c9269a9af0d80bc59afb2cb5806140ff (diff) | |
download | llvm-0a8cae10feb283b7a0886c5b52055de3db8b0e10.zip llvm-0a8cae10feb283b7a0886c5b52055de3db8b0e10.tar.gz llvm-0a8cae10feb283b7a0886c5b52055de3db8b0e10.tar.bz2 |
[ReachingDefs] Make isSafeToMove more strict.
Test that we're not moving the instruction through instructions with
side-effects.
Differential Revision: https://reviews.llvm.org/D74058
Diffstat (limited to 'llvm/lib/CodeGen/ReachingDefAnalysis.cpp')
-rw-r--r-- | llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp index 4483a85..62adaaf 100644 --- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -371,6 +371,12 @@ MachineInstr* ReachingDefAnalysis::getLocalLiveOutMIDef(MachineBasicBlock *MBB, return Def < 0 ? nullptr : getInstFromId(MBB, Def); } +static bool mayHaveSideEffects(MachineInstr &MI) { + return MI.mayLoadOrStore() || MI.mayRaiseFPException() || + MI.hasUnmodeledSideEffects() || MI.isTerminator() || + MI.isCall() || MI.isBarrier() || MI.isBranch() || MI.isReturn(); +} + // Can we safely move 'From' to just before 'To'? To satisfy this, 'From' must // not define a register that is used by any instructions, after and including, // 'To'. These instructions also must not redefine any of Froms operands. @@ -392,10 +398,13 @@ bool ReachingDefAnalysis::isSafeToMove(MachineInstr *From, } // Now walk checking that the rest of the instructions will compute the same - // value. + // value and that we're not overwriting anything. Don't move the instruction + // past any memory, control-flow or other ambigious instructions. for (auto I = ++Iterator(From), E = Iterator(To); I != E; ++I) { + if (mayHaveSideEffects(*I)) + return false; for (auto &MO : I->operands()) - if (MO.isReg() && MO.getReg() && MO.isUse() && Defs.count(MO.getReg())) + if (MO.isReg() && MO.getReg() && Defs.count(MO.getReg())) return false; } return true; @@ -430,8 +439,7 @@ ReachingDefAnalysis::isSafeToRemove(MachineInstr *MI, InstSet &Visited, InstSet &ToRemove, InstSet &Ignore) const { if (Visited.count(MI) || Ignore.count(MI)) return true; - else if (MI->mayLoadOrStore() || MI->hasUnmodeledSideEffects() || - MI->isBranch() || MI->isTerminator() || MI->isReturn()) { + else if (mayHaveSideEffects(*MI)) { // Unless told to ignore the instruction, don't remove anything which has // side effects. return false; |