Skip to content

Commit d3fdafa

Browse files
[InlineSpiller] simplify insertReload() NFC
Summary: The repeated use of std::next() on a MachineBasicBlock::iterator was clever, but we only need to reconstruct the iterator post creation of the spill instruction. This helps simplifying where we plan to place the spill, as discussed in D77849. From here, we can simplify the code a little by flipping the return code of a helper. Reviewers: efriedma Reviewed By: efriedma Subscribers: qcolombet, hiraditya, llvm-commits, srhines Tags: #llvm Differential Revision: https://reviews.llvm.org/D78520
1 parent 658f33d commit d3fdafa

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -931,15 +931,15 @@ void InlineSpiller::insertReload(unsigned NewVReg,
931931
/// Check if \p Def fully defines a VReg with an undefined value.
932932
/// If that's the case, that means the value of VReg is actually
933933
/// not relevant.
934-
static bool isFullUndefDef(const MachineInstr &Def) {
934+
static bool isRealSpill(const MachineInstr &Def) {
935935
if (!Def.isImplicitDef())
936-
return false;
936+
return true;
937937
assert(Def.getNumOperands() == 1 &&
938938
"Implicit def with more than one definition");
939939
// We can say that the VReg defined by Def is undef, only if it is
940940
// fully defined by Def. Otherwise, some of the lanes may not be
941941
// undef and the value of the VReg matters.
942-
return !Def.getOperand(0).getSubReg();
942+
return Def.getOperand(0).getSubReg();
943943
}
944944

945945
/// insertSpill - Insert a spill of NewVReg after MI.
@@ -948,26 +948,27 @@ void InlineSpiller::insertSpill(unsigned NewVReg, bool isKill,
948948
MachineBasicBlock &MBB = *MI->getParent();
949949

950950
MachineInstrSpan MIS(MI, &MBB);
951-
bool IsRealSpill = true;
952-
if (isFullUndefDef(*MI)) {
951+
MachineBasicBlock::iterator SpillBefore = std::next(MI);
952+
bool IsRealSpill = isRealSpill(*MI);
953+
if (IsRealSpill)
954+
TII.storeRegToStackSlot(MBB, SpillBefore, NewVReg, isKill, StackSlot,
955+
MRI.getRegClass(NewVReg), &TRI);
956+
else
953957
// Don't spill undef value.
954958
// Anything works for undef, in particular keeping the memory
955959
// uninitialized is a viable option and it saves code size and
956960
// run time.
957-
BuildMI(MBB, std::next(MI), MI->getDebugLoc(), TII.get(TargetOpcode::KILL))
961+
BuildMI(MBB, SpillBefore, MI->getDebugLoc(), TII.get(TargetOpcode::KILL))
958962
.addReg(NewVReg, getKillRegState(isKill));
959-
IsRealSpill = false;
960-
} else
961-
TII.storeRegToStackSlot(MBB, std::next(MI), NewVReg, isKill, StackSlot,
962-
MRI.getRegClass(NewVReg), &TRI);
963963

964-
LIS.InsertMachineInstrRangeInMaps(std::next(MI), MIS.end());
964+
MachineBasicBlock::iterator Spill = std::next(MI);
965+
LIS.InsertMachineInstrRangeInMaps(Spill, MIS.end());
965966

966-
LLVM_DEBUG(dumpMachineInstrRangeWithSlotIndex(std::next(MI), MIS.end(), LIS,
967-
"spill"));
967+
LLVM_DEBUG(
968+
dumpMachineInstrRangeWithSlotIndex(Spill, MIS.end(), LIS, "spill"));
968969
++NumSpills;
969970
if (IsRealSpill)
970-
HSpiller.addToMergeableSpills(*std::next(MI), StackSlot, Original);
971+
HSpiller.addToMergeableSpills(*Spill, StackSlot, Original);
971972
}
972973

973974
/// spillAroundUses - insert spill code around each use of Reg.

0 commit comments

Comments
 (0)