[llvm] [ARM][ConstantIslands] Correct MinNoSplitDisp calculation (PR #114590)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 11:48:47 PDT 2024


https://github.com/pzhengqc created https://github.com/llvm/llvm-project/pull/114590

MinNoSplitDisp was first introduced in D16890 to handle cases where the ConstantIslands pass fails to converge in the presence of big basic blocks. However, the computation of the variable seems to be wrong as it currently computes the offset immediately following UserBB. In other words, it represents the distance from the beginning of the function to the end of UserBB. The distance from the beginning of the function does not seem to be a good indicator of how big the basic block is unless the basic block is close to the beginning of the function. I think MinNoSplitDisp should compute the distance between UserOffset and the end of UserBB instead.

>From 48cf620f81eb047caa0a11634be07852e2567a17 Mon Sep 17 00:00:00 2001
From: Pengxuan Zheng <pzheng at quicinc.com>
Date: Fri, 1 Nov 2024 11:41:18 -0700
Subject: [PATCH] [ARM][ConstantIslands] Correct MinNoSplitDisp calculation

MinNoSplitDisp was first introduced in D16890 to handle cases where the
ConstantIslands pass fails to converge in the presence of big basic
blocks. However, the computation of the variable seems to be wrong as it
currently computes the offset immediately following UserBB. In other words, it
represents the distance from the beginning of the function to the end of
UserBB. The distance from the beginning of the function does not seem to be a
good indicator of how big the basic block is unless the basic block is close to
the beginning of the function. I think MinNoSplitDisp should compute the
distance between UserOffset and the end of UserBB instead.
---
 llvm/lib/Target/ARM/ARMConstantIslandPass.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
index 1312b44b49bdcc..e0575f7c125f67 100644
--- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
+++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
@@ -1324,7 +1324,8 @@ bool ARMConstantIslands::findAvailableWater(CPUser &U, unsigned UserOffset,
   MachineBasicBlock *UserBB = U.MI->getParent();
   BBInfoVector &BBInfo = BBUtils->getBBInfo();
   const Align CPEAlign = getCPEAlign(U.CPEMI);
-  unsigned MinNoSplitDisp = BBInfo[UserBB->getNumber()].postOffset(CPEAlign);
+  unsigned MinNoSplitDisp =
+      BBInfo[UserBB->getNumber()].postOffset(CPEAlign) - UserOffset;
   if (CloserWater && MinNoSplitDisp > U.getMaxDisp() / 2)
     return false;
   for (water_iterator IP = std::prev(WaterList.end()), B = WaterList.begin();;



More information about the llvm-commits mailing list