[llvm] 10d3c6b - [ShrinkWrap] Consider constant pool access as non-stack access (#164393)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 22 04:06:01 PDT 2025
Author: Sushant Gokhale
Date: 2025-10-22T04:05:57-07:00
New Revision: 10d3c6bc11ca919563036aa590440c38502bcd2f
URL: https://github.com/llvm/llvm-project/commit/10d3c6bc11ca919563036aa590440c38502bcd2f
DIFF: https://github.com/llvm/llvm-project/commit/10d3c6bc11ca919563036aa590440c38502bcd2f.diff
LOG: [ShrinkWrap] Consider constant pool access as non-stack access (#164393)
As far as I understand, constant pool access does not access stack and
accesses read-only memory.
This patch considers constant pool access as non-stack access allowing
shrink wrapping to happen in the concerned test.
We should be seeing perf improvement with povray benchmark from
SPEC17(around 12% with -flto -Ofast) after this patch.
An NFC PR #162476 already exists to upload the test before the patch but
approval has got delayed. So, as @davemgreen suggested in that PR, I
have uploaded the test and patch in this single PR to show how test
looks like.
Added:
Modified:
llvm/lib/CodeGen/ShrinkWrap.cpp
llvm/test/CodeGen/AArch64/shrink-wrap-const-pool-access.mir
llvm/test/CodeGen/X86/fp128-select.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/ShrinkWrap.cpp b/llvm/lib/CodeGen/ShrinkWrap.cpp
index 826e4126de44c..83581052560cb 100644
--- a/llvm/lib/CodeGen/ShrinkWrap.cpp
+++ b/llvm/lib/CodeGen/ShrinkWrap.cpp
@@ -319,7 +319,7 @@ bool ShrinkWrapImpl::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
return isa<GlobalValue>(UO);
}
if (const PseudoSourceValue *PSV = Op->getPseudoValue())
- return PSV->isJumpTable();
+ return PSV->isJumpTable() || PSV->isConstantPool();
return false;
};
// Load/store operations may access the stack indirectly when we previously
diff --git a/llvm/test/CodeGen/AArch64/shrink-wrap-const-pool-access.mir b/llvm/test/CodeGen/AArch64/shrink-wrap-const-pool-access.mir
index 80312740607b2..6f33a75ab9fcb 100644
--- a/llvm/test/CodeGen/AArch64/shrink-wrap-const-pool-access.mir
+++ b/llvm/test/CodeGen/AArch64/shrink-wrap-const-pool-access.mir
@@ -21,12 +21,14 @@
br label %common.ret
}
...
-# FIXME: Following code has a load from constant pool. Accessing constant pool
+# Following code has a load from constant pool. Accessing constant pool
# must not be considered as a stack access and hence, shrink wrapping must
# happen.
-# CHECK-LABEL:name: shrink_wrap_load_from_const_pool
-# CHECK-NOT: savePoint
-# CHECK-NOT: restorePoint
+# CHECK-LABEL:name: shrink_wrap_load_from_const_pool
+# CHECK: savePoint:
+# CHECK: - point: '%bb.3'
+# CHECK: restorePoint:
+# CHECK: - point: '%bb.5'
---
name: shrink_wrap_load_from_const_pool
tracksRegLiveness: true
diff --git a/llvm/test/CodeGen/X86/fp128-select.ll b/llvm/test/CodeGen/X86/fp128-select.ll
index 659e4ddedc646..27a651e23f886 100644
--- a/llvm/test/CodeGen/X86/fp128-select.ll
+++ b/llvm/test/CodeGen/X86/fp128-select.ll
@@ -13,8 +13,8 @@ define void @test_select(ptr %p, ptr %q, i1 zeroext %c) nounwind {
; SSE: # %bb.0:
; SSE-NEXT: testl %edx, %edx
; SSE-NEXT: jne .LBB0_1
-; SSE-NEXT: # %bb.3:
-; SSE-NEXT: movaps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SSE-NEXT: # %bb.2:
+; SSE-NEXT: movaps {{.*#+}} xmm0 = [NaN]
; SSE-NEXT: movaps %xmm0, (%rsi)
; SSE-NEXT: retq
; SSE-NEXT: .LBB0_1:
@@ -58,7 +58,7 @@ define fp128 @test_select_cc(fp128, fp128) nounwind {
; SSE-NEXT: xorps %xmm1, %xmm1
; SSE-NEXT: jmp .LBB1_3
; SSE-NEXT: .LBB1_1:
-; SSE-NEXT: movaps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1
+; SSE-NEXT: movaps {{.*#+}} xmm1 = [1.0E+0]
; SSE-NEXT: .LBB1_3: # %BB0
; SSE-NEXT: testl %ebx, %ebx
; SSE-NEXT: movaps (%rsp), %xmm0 # 16-byte Reload
More information about the llvm-commits
mailing list