[llvm] [AArch64] Do not promote scalable constants to global variables (PR #146926)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 10:16:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Momchil Velikov (momchil-velikov)
<details>
<summary>Changes</summary>
Following https://github.com/llvm/llvm-project/commit/878d3594ed74cd1153bc5cba2cb7a449702cdf34
IREE/MLIR started generating values like
```
[<vscale x 4 x float> zeroinitializer, <vscale x 4 x float> poison]
```
which then LLVM promoted to global variables in `AArch64PromoteConstant` pass.
This patch prevents it by explicitly checking the type of the promotion candidate.
---
Full diff: https://github.com/llvm/llvm-project/pull/146926.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp (+4)
- (added) llvm/test/CodeGen/AArch64/no-promote-scalabale-const-to-global.ll (+20)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp b/llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp
index 8edf1d0f9296b..3f45d55063b50 100644
--- a/llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp
+++ b/llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp
@@ -345,6 +345,10 @@ static bool shouldConvertImpl(const Constant *Cst) {
if (Cst->isZeroValue())
return false;
+ // Globals cannot be or contain scalable vectors.
+ if (Cst->getType()->isScalableTy())
+ return false;
+
if (Stress)
return true;
diff --git a/llvm/test/CodeGen/AArch64/no-promote-scalabale-const-to-global.ll b/llvm/test/CodeGen/AArch64/no-promote-scalabale-const-to-global.ll
new file mode 100644
index 0000000000000..db7d26b6ed139
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/no-promote-scalabale-const-to-global.ll
@@ -0,0 +1,20 @@
+; RUN: llc -mtriple=aarch64 -mattr=+sve -stop-after=aarch64-promote-const < %s | FileCheck %s
+
+; Test that the constant inside the `phi` is not promoted to a global
+; CHECK-NOT: _PromotedConst
+define void @f(i1 %c, ptr %p, ptr %q) {
+entry:
+ br i1 %c, label %if.then, label %if.else
+
+if.then:
+ %u = load [2 x <vscale x 4 x float> ], ptr %p
+ br label %exit
+
+if.else:
+ br label %exit
+
+exit:
+ %v = phi [2 x <vscale x 4 x float> ] [ %u, %if.then], [[<vscale x 4 x float> zeroinitializer, <vscale x 4 x float> poison], %if.else]
+ store [2 x <vscale x 4 x float>] %v, ptr %q
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/146926
More information about the llvm-commits
mailing list