[llvm] [NFC] Move all checks for unsafe instructions into one function (PR #137398)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 14:17:06 PDT 2025


https://github.com/LU-JOHN created https://github.com/llvm/llvm-project/pull/137398

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

>From 9cfbd46c907c13ef75ebb83a4f38f085b29adf24 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Fri, 25 Apr 2025 16:15:02 -0500
Subject: [PATCH] Move all checks for unsafe instructions info one function

Signed-off-by: John Lu <John.Lu at amd.com>
---
 llvm/lib/Transforms/Scalar/Sink.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/Sink.cpp b/llvm/lib/Transforms/Scalar/Sink.cpp
index 1a48a59c4189e..0865d20f9d990 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)
@@ -103,12 +109,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