diff options
| author | Puyan Lotfi <puyan@puyan.org> | 2019-05-31 04:49:58 +0000 |
|---|---|---|
| committer | Puyan Lotfi <puyan@puyan.org> | 2019-05-31 04:49:58 +0000 |
| commit | 2a901401fe453ca5b17048f7e6d74d9c8c91cbf9 (patch) | |
| tree | 60262d0b0c9fcf10e5c86d5fdb3bfb2a3ec3a362 /llvm/lib/CodeGen | |
| parent | fc3ed1ec506714abcc5f779b685d149419e1a207 (diff) | |
| download | bcm5719-llvm-2a901401fe453ca5b17048f7e6d74d9c8c91cbf9.tar.gz bcm5719-llvm-2a901401fe453ca5b17048f7e6d74d9c8c91cbf9.zip | |
[MIR-Canon] Hardening propagateLocalCopies.
This is am almost NFC, it does the following:
- If there is no register class for a COPY's src or dst, bail.
- Fixes uses iterator invalidation bug.
Differential Revision: https://reviews.llvm.org/D62713
llvm-svn: 362191
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/MIRCanonicalizerPass.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp index 650240e60fe..d36c0c89ba0 100644 --- a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp +++ b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp @@ -343,15 +343,23 @@ static bool propagateLocalCopies(MachineBasicBlock *MBB) { continue; if (!TargetRegisterInfo::isVirtualRegister(Src)) continue; + // Not folding COPY instructions if regbankselect has not set the RCs. + // Why are we only considering Register Classes? Because the verifier + // sometimes gets upset if the register classes don't match even if the + // types do. A future patch might add COPY folding for matching types in + // pre-registerbankselect code. + if (!MRI.getRegClassOrNull(Dst)) + continue; if (MRI.getRegClass(Dst) != MRI.getRegClass(Src)) continue; - for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI) { - MachineOperand *MO = &*UI; + std::vector<MachineOperand *> Uses; + for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI) + Uses.push_back(&*UI); + for (auto *MO : Uses) MO->setReg(Src); - Changed = true; - } + Changed = true; MI->eraseFromParent(); } |

