diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1380,7 +1380,9 @@ } SDValue Result(N, 0); - if (VT.isVector()) + if (VT.isScalableVector()) + Result = getSplatVector(VT, DL, Result); + else if (VT.isVector()) Result = getSplatBuildVector(VT, DL, Result); NewSDValueDbgMsg(Result, "Creating fp constant: ", this); return Result; diff --git a/llvm/test/CodeGen/AArch64/sve-vector-splat.ll b/llvm/test/CodeGen/AArch64/sve-vector-splat.ll --- a/llvm/test/CodeGen/AArch64/sve-vector-splat.ll +++ b/llvm/test/CodeGen/AArch64/sve-vector-splat.ll @@ -355,5 +355,22 @@ ret %2 } +define @splat_nxv4i32_fold( %x) { +; CHECK-LABEL: splat_nxv4i32_fold: +; CHECK: mov z0.s, #0 +; CHECK-NEXT: ret + %r = sub %x, %x + ret %r +} + + +define @splat_nxv4f32_fold( %x) { +; CHECK-LABEL: splat_nxv4f32_fold: +; CHECK: mov z0.s, #0 +; CHECK-NEXT: ret + %r = fsub nnan %x, %x + ret %r +} + ; +bf16 is required for the bfloat version. attributes #0 = { "target-features"="+sve,+bf16" }