From bc420a0cc1f86b56d9987bbbc225f21669ae0f5d Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Fri, 29 Aug 2014 23:48:03 +0000 Subject: [PATCH] [MachineSinking] Clear kill flag of all operands at all their uses. When sinking an instruction it might be moved past the original last use of one of its operands. This last use has the kill flag set and the verifier will obviously complain about this. Before Machine Sinking (AArch64): %vreg3 = ASRVXr %vreg1, %vreg2 %XZR = SUBSXrs %vreg4, %vreg1, 160, %NZCV ... After Machine Sinking: %XZR = SUBSXrs %vreg4, %vreg1, 160, %NZCV ... %vreg3 = ASRVXr %vreg1, %vreg2 This fix clears all the kill flags in all instruction that use the same operands as the instruction that is being sunk. This fixes rdar://problem/18180996. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216803 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineSink.cpp | 16 ++++++++--- .../CodeGen/AArch64/fast-isel-machine-sink.ll | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/AArch64/fast-isel-machine-sink.ll diff --git a/lib/CodeGen/MachineSink.cpp b/lib/CodeGen/MachineSink.cpp index 81aaca02a4d..0c29c76309e 100644 --- a/lib/CodeGen/MachineSink.cpp +++ b/lib/CodeGen/MachineSink.cpp @@ -736,9 +736,19 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { ++MachineBasicBlock::iterator(DbgMI)); } - // Conservatively, clear any kill flags, since it's possible that they are no - // longer correct. - MI->clearKillInfo(); + // When sinking the instruction the live time of its operands can be extended + // bejond their original last use (marked with a kill flag). Conservatively + // clear the kill flag in all instructions that use the same operand + // registers. + for (auto &MO : MI->uses()) + if (MO.isReg() && MO.isUse()) { + // Preserve the kill flag for this instruction. + bool IsKill = MO.isKill(); + // Clear the kill flag in all instruction that use this operand. + MRI->clearKillFlags(MO.getReg()); + // Restore the kill flag for only this instruction. + MO.setIsKill(IsKill); + } return true; } diff --git a/test/CodeGen/AArch64/fast-isel-machine-sink.ll b/test/CodeGen/AArch64/fast-isel-machine-sink.ll new file mode 100644 index 00000000000..74d3e8dbad0 --- /dev/null +++ b/test/CodeGen/AArch64/fast-isel-machine-sink.ll @@ -0,0 +1,27 @@ +; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -verify-machineinstrs < %s + +define void @test() { + %sext = shl i64 undef, 32 + %1 = ashr exact i64 %sext, 32 + %2 = icmp sgt i64 undef, %1 + br i1 %2, label %3, label %.critedge1 + +;