From f7a9d95d23aa3d3c40d10fd2d98c05dcdfb955c5 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Thu, 3 Jul 2025 17:02:36 +0000 Subject: [PATCH] [AArch64] Do not promote scalable constants to global variables --- .../Target/AArch64/AArch64PromoteConstant.cpp | 4 ++++ .../no-promote-scalabale-const-to-global.ll | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 llvm/test/CodeGen/AArch64/no-promote-scalabale-const-to-global.ll 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 ], ptr %p + br label %exit + +if.else: + br label %exit + +exit: + %v = phi [2 x ] [ %u, %if.then], [[ zeroinitializer, poison], %if.else] + store [2 x ] %v, ptr %q + ret void +}