[llvm] 571e024 - [Sink][NFC] Move all checks for unsafe instructions into one function (#137398)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 01:10:30 PDT 2025


Author: LU-JOHN
Date: 2025-04-26T10:10:27+02:00
New Revision: 571e024d007280b3871d06db7e0bea3172c24c55

URL: https://github.com/llvm/llvm-project/commit/571e024d007280b3871d06db7e0bea3172c24c55
DIFF: https://github.com/llvm/llvm-project/commit/571e024d007280b3871d06db7e0bea3172c24c55.diff

LOG: [Sink][NFC] Move all checks for unsafe instructions into one function (#137398)

Move check for instruction that is unsafe to sink into isSafeToMove
function.

Signed-off-by: John Lu <John.Lu at amd.com>

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/Sink.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp
index 4b63698e5e132..603525b55b9cf 100644
--- a/llvm/lib/Transforms/Scalar/Sink.cpp
+++ b/llvm/lib/Transforms/Scalar/Sink.cpp
@@ -35,6 +35,12 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA,
     return false;
   }
 
+  // Don't sink static alloca instructions.  CodeGen assumes allocas outside the
+  // entry block are dynamically sized stack objects.
+  if (AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
+    if (AI->isStaticAlloca())
+      return false;
+
   if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
     MemoryLocation Loc = MemoryLocation::get(L);
     for (Instruction *S : Stores)
@@ -98,12 +104,6 @@ static bool SinkInstruction(Instruction *Inst,
                             SmallPtrSetImpl<Instruction *> &Stores,
                             DominatorTree &DT, LoopInfo &LI, AAResults &AA) {
 
-  // Don't sink static alloca instructions.  CodeGen assumes allocas outside the
-  // entry block are dynamically sized stack objects.
-  if (AllocaInst *AI = dyn_cast<AllocaInst>(Inst))
-    if (AI->isStaticAlloca())
-      return false;
-
   // Check if it's safe to move the instruction.
   if (!isSafeToMove(Inst, AA, Stores))
     return false;


        


More information about the llvm-commits mailing list