[llvm] [WebAssembly] Define local sp if `llvm.stacksave` is used (PR #68133)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 11:43:58 PDT 2023


================
@@ -147,7 +147,14 @@ bool WebAssemblyFrameLowering::needsPrologForEH(
 /// Unlike a machine stack pointer, the wasm user stack pointer is a global
 /// variable, so it is loaded into a register in the prolog.
 bool WebAssemblyFrameLowering::needsSP(const MachineFunction &MF) const {
-  return needsSPForLocalFrame(MF) || needsPrologForEH(MF);
+  auto &MRI = MF.getRegInfo();
+  // llvm.stacksave can explicitly read SP register and it can appear without
+  // dynamic alloca.
+  bool hasExplicitSPUse =
----------------
dschuff wrote:

Actually, even more than just where related code is located, `needsSPForLocalFrame()` is also used by `needsSPWriteback()`. I guess if the stacksave and stackrestore are properly paired, then in theory an SP writeback at the end of the function wouldn't be needed. But maybe it makes sense to have it anyway, just to be safe.

https://github.com/llvm/llvm-project/pull/68133


More information about the llvm-commits mailing list