[MachineSink] Clear kill flags on operands outside loop
If an instruction is sunk into a loop then any kill flags on operands declared outside the loop must be cleared as these will be live for all loop iterations. Fixes #46827 Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D126754
This commit is contained in:
parent
f401dd6f43
commit
874fbe2cbb
@ -1289,6 +1289,12 @@ bool MachineSinking::SinkIntoCycle(MachineCycle *Cycle, MachineInstr &I) {
|
||||
SinkBlock->splice(SinkBlock->SkipPHIsAndLabels(SinkBlock->begin()), Preheader,
|
||||
I);
|
||||
|
||||
// Conservatively clear any kill flags on uses of sunk instruction
|
||||
for (MachineOperand &MO : I.operands()) {
|
||||
if (MO.isReg() && MO.readsReg())
|
||||
RegsToClearKillFlags.insert(MO.getReg());
|
||||
}
|
||||
|
||||
// The instruction is moved from its basic block, so do not retain the
|
||||
// debug information.
|
||||
assert(!I.isDebugInstr() && "Should not sink debug inst");
|
||||
|
||||
75
llvm/test/CodeGen/SystemZ/machinelicm-sunk-kill-flags.mir
Normal file
75
llvm/test/CodeGen/SystemZ/machinelicm-sunk-kill-flags.mir
Normal file
@ -0,0 +1,75 @@
|
||||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
|
||||
# RUN: llc -mtriple=s390x-linux-gnu -sink-insts-to-avoid-spills -verify-machineinstrs -run-pass=machine-sink -o - %s | FileCheck %s
|
||||
|
||||
# Test kill flags are cleared after sinking operations into cycle during MachineLICM.
|
||||
|
||||
--- |
|
||||
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
|
||||
target triple = "s390x-unknown-linux-gnu"
|
||||
|
||||
%0 = type <{ i32, [3 x i8] }>
|
||||
|
||||
@b = external dso_local global [1 x %0], align 2
|
||||
|
||||
define dso_local void @c() local_unnamed_addr {
|
||||
ret void
|
||||
}
|
||||
|
||||
...
|
||||
---
|
||||
name: c
|
||||
tracksRegLiveness: true
|
||||
body: |
|
||||
; CHECK-LABEL: name: c
|
||||
; CHECK: bb.0:
|
||||
; CHECK-NEXT: successors: %bb.1(0x80000000)
|
||||
; CHECK-NEXT: {{ $}}
|
||||
; CHECK-NEXT: [[LARL:%[0-9]+]]:addr64bit = LARL @b
|
||||
; CHECK-NEXT: {{ $}}
|
||||
; CHECK-NEXT: bb.1:
|
||||
; CHECK-NEXT: successors: %bb.1(0x80000000)
|
||||
; CHECK-NEXT: {{ $}}
|
||||
; CHECK-NEXT: [[LA:%[0-9]+]]:gr64bit = LA [[LARL]], 49, $noreg
|
||||
; CHECK-NEXT: [[LGHI:%[0-9]+]]:gr64bit = LGHI 7
|
||||
; CHECK-NEXT: [[DEF:%[0-9]+]]:gr64bit = IMPLICIT_DEF
|
||||
; CHECK-NEXT: [[DEF1:%[0-9]+]]:gr64bit = IMPLICIT_DEF
|
||||
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
|
||||
; CHECK-NEXT: $r2d = COPY [[DEF]]
|
||||
; CHECK-NEXT: $r3d = COPY [[LA]]
|
||||
; CHECK-NEXT: $r4d = COPY [[LGHI]]
|
||||
; CHECK-NEXT: CallBRASL &memcpy, $r2d, $r3d, $r4d, csr_systemz_elf, implicit-def dead $r14d, implicit-def dead $cc, implicit $fpc, implicit-def $r2d
|
||||
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
|
||||
; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0
|
||||
; CHECK-NEXT: $r2d = COPY [[DEF1]]
|
||||
; CHECK-NEXT: $r3d = COPY [[LA]]
|
||||
; CHECK-NEXT: $r4d = COPY [[LGHI]]
|
||||
; CHECK-NEXT: CallBRASL &memcpy, $r2d, $r3d, $r4d, csr_systemz_elf, implicit-def dead $r14d, implicit-def dead $cc, implicit $fpc, implicit-def $r2d
|
||||
; CHECK-NEXT: ADJCALLSTACKUP 0, 0
|
||||
; CHECK-NEXT: J %bb.1
|
||||
bb.0:
|
||||
successors: %bb.1(0x80000000)
|
||||
|
||||
%1:addr64bit = LARL @b
|
||||
%0:gr64bit = LA killed %1, 49, $noreg
|
||||
%2:gr64bit = LGHI 7
|
||||
%3:gr64bit = IMPLICIT_DEF
|
||||
%5:gr64bit = IMPLICIT_DEF
|
||||
|
||||
bb.1:
|
||||
successors: %bb.1(0x80000000)
|
||||
|
||||
ADJCALLSTACKDOWN 0, 0
|
||||
$r2d = COPY %3
|
||||
$r3d = COPY %0
|
||||
$r4d = COPY %2
|
||||
CallBRASL &memcpy, $r2d, $r3d, $r4d, csr_systemz_elf, implicit-def dead $r14d, implicit-def dead $cc, implicit $fpc, implicit-def $r2d
|
||||
ADJCALLSTACKUP 0, 0
|
||||
ADJCALLSTACKDOWN 0, 0
|
||||
$r2d = COPY %5
|
||||
$r3d = COPY %0
|
||||
$r4d = COPY %2
|
||||
CallBRASL &memcpy, $r2d, $r3d, $r4d, csr_systemz_elf, implicit-def dead $r14d, implicit-def dead $cc, implicit $fpc, implicit-def $r2d
|
||||
ADJCALLSTACKUP 0, 0
|
||||
J %bb.1
|
||||
|
||||
...
|
||||
Loading…
x
Reference in New Issue
Block a user