[llvm] Resolve FIXME: Try SCEV getRange. (PR #80623)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 13:30:09 PST 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/80623
>From 213bb1fef9cb4648042b80a5976d2affe18262e9 Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Sun, 4 Feb 2024 19:01:36 -0500
Subject: [PATCH] Resolve FIXME: Try SCEV getRange.
Using the range to see if it is a single constant value instead of seeing if there is a constant size is more accurate.
---
llvm/lib/CodeGen/SafeStack.cpp | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 0a26247a4d1659..8b4d69e4ad820a 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -263,10 +263,16 @@ bool SafeStack::IsMemIntrinsicSafe(const MemIntrinsic *MI, const Use &U,
return true;
}
- const auto *Len = dyn_cast<ConstantInt>(MI->getLength());
- // Non-constant size => unsafe. FIXME: try SCEV getRange.
- if (!Len) return false;
- return IsAccessSafe(U, Len->getZExtValue(), AllocaPtr, AllocaSize);
+ const SCEV *LenSCEV = SE.getSCEV(MI->getLength());
+ ConstantRange LenRange = SE.getUnsignedRange(LenSCEV);
+ auto element = LenRange.getSingleElement();
+ if (element) {
+ uint64_t Len = element->getZExtValue();
+ return IsAccessSafe(U, Len, AllocaPtr, AllocaSize);
+ } else {
+ // If the length is not a single constant value, it's unsafe.
+ return false;
+ }
}
/// Check whether a given allocation must be put on the safe
More information about the llvm-commits
mailing list