From 26271c83849ba05982963bf5e85e54fc0de1389a Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 15 Apr 2020 17:54:46 -0700 Subject: [PATCH] [AArch64InstrInfo] Ignore debug insts in canInstrSubstituteCmpInstr [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 --- llvm/lib/CodeGen/PeepholeOptimizer.cpp | 4 ++++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 7 +++---- llvm/test/CodeGen/AArch64/arm64-arm64-dead-def-elimination-flag.ll | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp index ae309a3..b9e8c69 100644 --- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -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; @@ -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; @@ -1299,6 +1301,7 @@ bool PeepholeOptimizer::optimizeUncoalescableCopy( } // MI is now dead. + LLVM_DEBUG(dbgs() << "Deleting uncoalescable copy: " << MI); MI.eraseFromParent(); ++NumUncoalescableCopies; return true; @@ -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; diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp index 564b7c8..cd52d04 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -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 diff --git a/llvm/test/CodeGen/AArch64/arm64-arm64-dead-def-elimination-flag.ll b/llvm/test/CodeGen/AArch64/arm64-arm64-dead-def-elimination-flag.ll index 85aa9c4..2bf1360 100644 --- a/llvm/test/CodeGen/AArch64/arm64-arm64-dead-def-elimination-flag.ll +++ b/llvm/test/CodeGen/AArch64/arm64-arm64-dead-def-elimination-flag.ll @@ -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" -- 2.7.4