Skip to content

Commit

Permalink
[AArch64InstrInfo] Ignore debug insts in canInstrSubstituteCmpInstr […
Browse files Browse the repository at this point in the history
…6/14]

Summary:
Fix an issue where the presence of debug info could disable a peephole
optimization in optimizeCompareInstr due to canInstrSubstituteCmpInstr
returning the wrong result.

Depends on D78137.

Reviewers: t.p.northover, eastig, paquette

Subscribers: kristof.beyls, hiraditya, danielkiss, aprantl, llvm-commits, dsanders

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78151
  • Loading branch information
vedantk committed Apr 23, 2020
1 parent f1a71b5 commit 26271c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/PeepholeOptimizer.cpp
Expand Up @@ -614,6 +614,7 @@ bool PeepholeOptimizer::optimizeCmpInstr(MachineInstr &MI) {
return false;

// Attempt to optimize the comparison instruction.
LLVM_DEBUG(dbgs() << "Attempting to optimize compare: " << MI);
if (TII->optimizeCompareInstr(MI, SrcReg, SrcReg2, CmpMask, CmpValue, MRI)) {
++NumCmps;
return true;
Expand All @@ -635,6 +636,7 @@ bool PeepholeOptimizer::optimizeSelect(MachineInstr &MI,
return false;
if (!TII->optimizeSelect(MI, LocalMIs))
return false;
LLVM_DEBUG(dbgs() << "Deleting select: " << MI);
MI.eraseFromParent();
++NumSelects;
return true;
Expand Down Expand Up @@ -1299,6 +1301,7 @@ bool PeepholeOptimizer::optimizeUncoalescableCopy(
}

// MI is now dead.
LLVM_DEBUG(dbgs() << "Deleting uncoalescable copy: " << MI);
MI.eraseFromParent();
++NumUncoalescableCopies;
return true;
Expand Down Expand Up @@ -1723,6 +1726,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
(foldRedundantCopy(*MI, CopySrcRegs, CopySrcMIs) ||
foldRedundantNAPhysCopy(*MI, NAPhysToVirtMIs))) {
LocalMIs.erase(MI);
LLVM_DEBUG(dbgs() << "Deleting redundant copy: " << *MI << "\n");
MI->eraseFromParent();
Changed = true;
continue;
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
Expand Up @@ -1443,10 +1443,9 @@ static bool canInstrSubstituteCmpInstr(MachineInstr *MI, MachineInstr *CmpInstr,
return false;

UsedNZCV NZCVUsedAfterCmp;
for (auto I = std::next(CmpInstr->getIterator()),
E = CmpInstr->getParent()->instr_end();
I != E; ++I) {
const MachineInstr &Instr = *I;
for (const MachineInstr &Instr :
instructionsWithoutDebug(std::next(CmpInstr->getIterator()),
CmpInstr->getParent()->instr_end())) {
if (Instr.readsRegister(AArch64::NZCV, TRI)) {
AArch64CC::CondCode CC = findCondCodeUsedByInstr(Instr);
if (CC == AArch64CC::Invalid) // Unsupported conditional instruction
Expand Down
@@ -1,4 +1,4 @@
; RUN: llc -mtriple=arm64-apple-ios7.0.0 -aarch64-enable-dead-defs=false < %s | FileCheck %s
; RUN: llc -debugify-and-strip-all-safe -mtriple=arm64-apple-ios7.0.0 -aarch64-enable-dead-defs=false < %s | FileCheck %s

target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"

Expand Down

0 comments on commit 26271c8

Please sign in to comment.