Skip to content

Commit c50415b

Browse files
[AArch64] Do not promote scalable constants to global variables (#146926)
Following 878d359 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.
1 parent e430581 commit c50415b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Target/AArch64/AArch64PromoteConstant.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ static bool shouldConvertImpl(const Constant *Cst) {
345345
if (Cst->isZeroValue())
346346
return false;
347347

348+
// Globals cannot be or contain scalable vectors.
349+
if (Cst->getType()->isScalableTy())
350+
return false;
351+
348352
if (Stress)
349353
return true;
350354

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -mtriple=aarch64 -mattr=+sve -stop-after=aarch64-promote-const < %s | FileCheck %s
2+
3+
; Test that the constant inside the `phi` is not promoted to a global
4+
; CHECK-NOT: _PromotedConst
5+
define void @f(i1 %c, ptr %p, ptr %q) {
6+
entry:
7+
br i1 %c, label %if.then, label %if.else
8+
9+
if.then:
10+
%u = load [2 x <vscale x 4 x float> ], ptr %p
11+
br label %exit
12+
13+
if.else:
14+
br label %exit
15+
16+
exit:
17+
%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]
18+
store [2 x <vscale x 4 x float>] %v, ptr %q
19+
ret void
20+
}

0 commit comments

Comments
 (0)