AMDGPU/SILoadStoreOptimizer: fix a likely bug introduced recently
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 9 Oct 2019 10:53:17 +0000 (12:53 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Sat, 16 Nov 2019 10:35:34 +0000 (11:35 +0100)
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

index e7d4aab..53c8ff1 100644 (file)
@@ -1665,8 +1665,8 @@ bool SILoadStoreOptimizer::promoteConstantOffsetToImm(
 void SILoadStoreOptimizer::addInstToMergeableList(const CombineInfo &CI,
                  std::list<std::list<CombineInfo> > &MergeableInsts) const {
   for (std::list<CombineInfo> &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;
     }