diff options
| author | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-10-03 15:43:39 +0000 |
|---|---|---|
| committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-10-03 15:43:39 +0000 |
| commit | fb9b99b26e984f0f03b8535dae9116fbc549c035 (patch) | |
| tree | 4a5e2ffa5768183eca9771ea8da7655b36e8f5d9 /llvm/lib | |
| parent | 79dceb2903f8b6ad049b763922843dca26c6aa05 (diff) | |
| download | bcm5719-llvm-fb9b99b26e984f0f03b8535dae9116fbc549c035.tar.gz bcm5719-llvm-fb9b99b26e984f0f03b8535dae9116fbc549c035.zip | |
[globalisel][combines] Don't sink G_TRUNC down to use if that use is a G_PHI
This fixes a problem where the register allocator fails to eliminate a PHI
because there's a non-PHI in the middle of the PHI instructions at the start
of a BB.
This G_TRUNC can be better placed but this at least fixes the correctness issue
quickly. I'll follow up with a patch to the verifier to catch this kind of bug
in future.
llvm-svn: 343693
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index 98114d295a1..30e0da319e8 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -154,12 +154,18 @@ bool CombinerHelper::tryCombineExtendingLoads(MachineInstr &MI) { assert(Preferred.Ty != LoadValueTy && "Extending to same type?"); // Rewrite the load and schedule the canonical use for erasure. - const auto TruncateUse = [](MachineIRBuilder &Builder, MachineOperand &UseMO, - unsigned DstReg, unsigned SrcReg) { + const auto TruncateUse = [&MI](MachineIRBuilder &Builder, + MachineOperand &UseMO, unsigned DstReg, + unsigned SrcReg) { MachineInstr &UseMI = *UseMO.getParent(); MachineBasicBlock &UseMBB = *UseMI.getParent(); Builder.setInsertPt(UseMBB, MachineBasicBlock::iterator(UseMI)); + + if (UseMI.isPHI()) + Builder.setInsertPt(*MI.getParent(), + std::next(MachineBasicBlock::iterator(MI))); + Builder.buildTrunc(DstReg, SrcReg); }; |

