[llvm] [StackSlotColoring] Check for zero stack slot size in RemoveDeadStores (PR #82331)

Karl-Johan Karlsson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 01:46:24 PST 2024


https://github.com/karka228 created https://github.com/llvm/llvm-project/pull/82331

The default implementations of the methods isLoadFromStackSlot() and isStoreToStackSlot() used in StackSlotColoring::RemoveDeadStores() set the number of bytes loaded from the stack (MemBytes) to zero to indicate that the value is unknown. This means that StackSlotColoring::RemoveDeadStores() must abort if the size is zero otherwise the stack slot size check doesn't mean anything.

As backends that use this are required to override the default implementations this should not impose any degradation of the code.

As the registers also must match in StackSlotColoring::RemoveDeadStores() for the store to be optimized away there is small risk of this being a real bug. This makes it probably impossible to make a testcase to verify this.

>From 6972c82c18a6d32ee78372880c82e2ce6f573894 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson <karl-johan.karlsson at ericsson.com>
Date: Tue, 20 Feb 2024 10:24:06 +0100
Subject: [PATCH] [StackSlotColoring] Check for zero stack slot size in
 RemoveDeadStores

The default implementations of the methods isLoadFromStackSlot() and
isStoreToStackSlot() used in StackSlotColoring::RemoveDeadStores() set the
number of bytes loaded from the stack (MemBytes) to zero to indicate that the
value is unknown. This means that StackSlotColoring::RemoveDeadStores() must
abort if the size is zero otherwise the stack slot size check doesn't mean
anything.

As backends that use this are required to override the default implementations
this should not impose any degradation of the code.

As the registers also must match in StackSlotColoring::RemoveDeadStores() for
the store to be optimized away there is small risk of this being a real
bug. This makes it probably impossible to make a testcase to verify this.
---
 llvm/lib/CodeGen/StackSlotColoring.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp
index 6d3fc740b292a8..f10a192f35f719 100644
--- a/llvm/lib/CodeGen/StackSlotColoring.cpp
+++ b/llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -480,7 +480,8 @@ bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
     if (!(StoreReg = TII->isStoreToStackSlot(*NextMI, SecondSS, StoreSize)))
       continue;
     if (FirstSS != SecondSS || LoadReg != StoreReg || FirstSS == -1 ||
-        LoadSize != StoreSize || !MFI->isSpillSlotObjectIndex(FirstSS))
+        !LoadSize || LoadSize != StoreSize ||
+        !MFI->isSpillSlotObjectIndex(FirstSS))
       continue;
 
     ++NumDead;



More information about the llvm-commits mailing list