From d8f7c68e28bd0b8eb49f752bd7d26aa767c0b078 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolai=20H=C3=A4hnle?= Date: Wed, 9 Oct 2019 12:53:17 +0200 Subject: [PATCH] AMDGPU/SILoadStoreOptimizer: fix a likely bug introduced recently Summary: We should check for same instruction class before checking whether they have the same base address, else we might iterate out of bounds of a MachineInstr operands list. The InstClass check is also cheaper. This was introduced in SVN r373630. Reviewers: tstellar Subscribers: arsenm, kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68690 --- llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp b/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp index e7d4aab03..53c8ff1 100644 --- a/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp +++ b/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp @@ -1665,8 +1665,8 @@ bool SILoadStoreOptimizer::promoteConstantOffsetToImm( void SILoadStoreOptimizer::addInstToMergeableList(const CombineInfo &CI, std::list > &MergeableInsts) const { for (std::list &AddrList : MergeableInsts) { - if (AddrList.front().hasSameBaseAddress(*CI.I) && - AddrList.front().InstClass == CI.InstClass) { + if (AddrList.front().InstClass == CI.InstClass && + AddrList.front().hasSameBaseAddress(*CI.I)) { AddrList.emplace_back(CI); return; } -- 2.7.4