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 +}