mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-20 10:24:12 +00:00
This patch fixes the bug in peephole optimization that folds a load which defines one vreg into the one and only use of that vreg. With debug info, a DBG_VALUE that referenced the vreg considered to be a use, preventing the optimization. The fix is to ignore DBG_VALUE's during the optimization, and undef a DBG_VALUE that references a vreg that gets removed. Patch by Trevor Smigiel! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203829 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -505,12 +505,12 @@ bool PeepholeOptimizer::isLoadFoldable(MachineInstr *MI,
|
||||
return false;
|
||||
|
||||
unsigned Reg = MI->getOperand(0).getReg();
|
||||
// To reduce compilation time, we check MRI->hasOneUse when inserting
|
||||
// To reduce compilation time, we check MRI->hasOneNonDBGUse when inserting
|
||||
// loads. It should be checked when processing uses of the load, since
|
||||
// uses can be removed during peephole.
|
||||
if (!MI->getOperand(0).getSubReg() &&
|
||||
TargetRegisterInfo::isVirtualRegister(Reg) &&
|
||||
MRI->hasOneUse(Reg)) {
|
||||
MRI->hasOneNonDBGUse(Reg)) {
|
||||
FoldAsLoadDefReg = Reg;
|
||||
return true;
|
||||
}
|
||||
@ -594,10 +594,14 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
++MII;
|
||||
LocalMIs.insert(MI);
|
||||
|
||||
// Skip debug values. They should not affect this peephole optimization.
|
||||
if (MI->isDebugValue())
|
||||
continue;
|
||||
|
||||
// If there exists an instruction which belongs to the following
|
||||
// categories, we will discard the load candidate.
|
||||
if (MI->isPosition() || MI->isPHI() || MI->isImplicitDef() ||
|
||||
MI->isKill() || MI->isInlineAsm() || MI->isDebugValue() ||
|
||||
MI->isKill() || MI->isInlineAsm() ||
|
||||
MI->hasUnmodeledSideEffects()) {
|
||||
FoldAsLoadDefReg = 0;
|
||||
continue;
|
||||
@ -633,6 +637,9 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
if (!isLoadFoldable(MI, FoldAsLoadDefReg) && FoldAsLoadDefReg) {
|
||||
// We need to fold load after optimizeCmpInstr, since optimizeCmpInstr
|
||||
// can enable folding by converting SUB to CMP.
|
||||
// Save FoldAsLoadDefReg because optimizeLoadInstr() resets it and we
|
||||
// need it for markUsesInDebugValueAsUndef().
|
||||
unsigned FoldedReg = FoldAsLoadDefReg;
|
||||
MachineInstr *DefMI = 0;
|
||||
MachineInstr *FoldMI = TII->optimizeLoadInstr(MI, MRI,
|
||||
FoldAsLoadDefReg, DefMI);
|
||||
@ -645,6 +652,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
LocalMIs.insert(FoldMI);
|
||||
MI->eraseFromParent();
|
||||
DefMI->eraseFromParent();
|
||||
MRI->markUsesInDebugValueAsUndef(FoldedReg);
|
||||
++NumLoadFold;
|
||||
|
||||
// MI is replaced with FoldMI.
|
||||
|
Reference in New Issue
Block a user