diff --git a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h --- a/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h @@ -82,7 +82,7 @@ /// Returns true if \p DefMI precedes \p UseMI or they are the same /// instruction. Both must be in the same basic block. - bool isPredecessor(MachineInstr &DefMI, MachineInstr &UseMI); + bool isPredecessor(const MachineInstr &DefMI, const MachineInstr &UseMI); /// Returns true if \p DefMI dominates \p UseMI. By definition an /// instruction dominates itself. @@ -90,7 +90,7 @@ /// If we haven't been provided with a MachineDominatorTree during /// construction, this function returns a conservative result that tracks just /// a single basic block. - bool dominates(MachineInstr &DefMI, MachineInstr &UseMI); + bool dominates(const MachineInstr &DefMI, const MachineInstr &UseMI); /// If \p MI is extend that consumes the result of a load, try to combine it. /// Returns true if MI changed. diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -402,7 +402,7 @@ ? TargetOpcode::G_SEXT : TargetOpcode::G_ZEXT; Preferred = {LLT(), PreferredOpcode, nullptr}; - for (auto &UseMI : MRI.use_instructions(LoadValue.getReg())) { + for (auto &UseMI : MRI.use_nodbg_instructions(LoadValue.getReg())) { if (UseMI.getOpcode() == TargetOpcode::G_SEXT || UseMI.getOpcode() == TargetOpcode::G_ZEXT || UseMI.getOpcode() == TargetOpcode::G_ANYEXT) { @@ -533,7 +533,10 @@ Observer.changedInstr(MI); } -bool CombinerHelper::isPredecessor(MachineInstr &DefMI, MachineInstr &UseMI) { +bool CombinerHelper::isPredecessor(const MachineInstr &DefMI, + const MachineInstr &UseMI) { + assert(!DefMI.isDebugInstr() && !UseMI.isDebugInstr() && + "shouldn't consider debug uses"); assert(DefMI.getParent() == UseMI.getParent()); if (&DefMI == &UseMI) return false; @@ -546,7 +549,10 @@ llvm_unreachable("Block must contain instructions"); } -bool CombinerHelper::dominates(MachineInstr &DefMI, MachineInstr &UseMI) { +bool CombinerHelper::dominates(const MachineInstr &DefMI, + const MachineInstr &UseMI) { + assert(!DefMI.isDebugInstr() && !UseMI.isDebugInstr() && + "shouldn't consider debug uses"); if (MDT) return MDT->dominates(&DefMI, &UseMI); else if (DefMI.getParent() != UseMI.getParent()) @@ -573,7 +579,7 @@ LLVM_DEBUG(dbgs() << "Searching for post-indexing opportunity for: " << MI); - for (auto &Use : MRI.use_instructions(Base)) { + for (auto &Use : MRI.use_nodbg_instructions(Base)) { if (Use.getOpcode() != TargetOpcode::G_PTR_ADD) continue; @@ -600,7 +606,8 @@ // forming an indexed one. bool MemOpDominatesAddrUses = true; - for (auto &PtrAddUse : MRI.use_instructions(Use.getOperand(0).getReg())) { + for (auto &PtrAddUse : + MRI.use_nodbg_instructions(Use.getOperand(0).getReg())) { if (!dominates(MI, PtrAddUse)) { MemOpDominatesAddrUses = false; break; @@ -673,7 +680,7 @@ // FIXME: check whether all uses of the base pointer are constant PtrAdds. // That might allow us to end base's liveness here by adjusting the constant. - for (auto &UseMI : MRI.use_instructions(Addr)) { + for (auto &UseMI : MRI.use_nodbg_instructions(Addr)) { if (!dominates(MI, UseMI)) { LLVM_DEBUG(dbgs() << " Skipping, does not dominate all addr uses."); return false; diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/combiner-load-store-indexing.ll b/llvm/test/CodeGen/AArch64/GlobalISel/combiner-load-store-indexing.ll --- a/llvm/test/CodeGen/AArch64/GlobalISel/combiner-load-store-indexing.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/combiner-load-store-indexing.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=arm64-apple-ios -global-isel -global-isel-abort=1 -verify-machineinstrs -stop-after=aarch64-prelegalizer-combiner -force-legal-indexing %s -o - | FileCheck %s +; RUN: llc -debugify-and-strip-all-safe -mtriple=arm64-apple-ios -global-isel -global-isel-abort=1 -verify-machineinstrs -stop-after=aarch64-prelegalizer-combiner -force-legal-indexing %s -o - | FileCheck %s define i8* @test_simple_load_pre(i8* %ptr) { ; CHECK-LABEL: name: test_simple_load_pre