[llvm] [AArch64][CostModel] Consider some nxv1 casts as illegal (PR #230153)
Gaëtan Bossu via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 8 08:16:43 PDT 2026
https://github.com/gbossu created https://github.com/llvm/llvm-project/pull/230153
Codegen does not support all kinds of casts for these types.
This patch adds missing costmodel and codedgen tests.
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
>From cc14daa731b867ec505fb92a0a519df06ebc662c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Bossu?= <gaetan.bossu at arm.com>
Date: Thu, 8 Oct 2026 14:50:13 +0000
Subject: [PATCH] [AArch64][CostModel] Consider some nxv1 casts as illegal
Codegen does not support all kinds of casts for these types.
This patch adds missing costmodel and codedgen tests.
---
.../AArch64/AArch64TargetTransformInfo.cpp | 16 ++
.../Analysis/CostModel/AArch64/sve-bitcast.ll | 16 ++
.../Analysis/CostModel/AArch64/sve-ext.ll | 5 +
.../Analysis/CostModel/AArch64/sve-fptoi.ll | 16 +-
.../Analysis/CostModel/AArch64/sve-itofp.ll | 51 ++++++
.../Analysis/CostModel/AArch64/sve-trunc.ll | 5 +
llvm/test/CodeGen/AArch64/sve-bitcast.ll | 52 ++++++
llvm/test/CodeGen/AArch64/sve-sext-zext.ll | 164 ++++++++++++++++++
8 files changed, 319 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index e7e00cde943a1..8d99a243da222 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -3984,6 +3984,16 @@ InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
const Instruction *I) const {
int ISD = TLI->InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
+
+ // Codegen is not able to select all <vscale x 1 x Ty> casts yet.
+ if (auto *VTy = dyn_cast<ScalableVectorType>(Dst);
+ VTy && VTy->getElementCount() == ElementCount::getScalable(1)) {
+ if (!is_contained({ISD::TRUNCATE, ISD::SIGN_EXTEND, ISD::ZERO_EXTEND,
+ ISD::BITCAST, ISD::ADDRSPACECAST},
+ ISD))
+ return InstructionCost::getInvalid();
+ }
+
// If the cast is observable, and it is used by a widening instruction (e.g.,
// uaddl, saddw, etc.), it may be free.
if (I && !I->users().empty()) {
@@ -4054,6 +4064,12 @@ InstructionCost AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
EVT SrcTy = TLI->getValueType(DL, Src);
EVT DstTy = TLI->getValueType(DL, Dst);
+ // SVE has no elements wider than 64 bits. The generic cost for a bitcast
+ // between unsupported scalable types can otherwise appear to be free.
+ if ((SrcTy.isScalableVector() && SrcTy.getScalarSizeInBits() > 64) ||
+ (DstTy.isScalableVector() && DstTy.getScalarSizeInBits() > 64))
+ return InstructionCost::getInvalid();
+
// From a vector to a scalarized vector will be an series of extract-element
// and extends.
if ((ISD == ISD::ZERO_EXTEND || ISD == ISD::SIGN_EXTEND) &&
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-bitcast.ll b/llvm/test/Analysis/CostModel/AArch64/sve-bitcast.ll
index e96f8098452e1..b389a5e95f52e 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-bitcast.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-bitcast.ll
@@ -61,3 +61,19 @@ define <vscale x 2 x i32> @test_nxv2i32(<vscale x 2 x float> %a) {
%b = bitcast <vscale x 2 x float> %a to <vscale x 2 x i32>
ret <vscale x 2 x i32> %b
}
+
+define void @cast_unsupported_elements(<vscale x 1 x i128> %ints,
+ <vscale x 1 x fp128> %floats,
+ <vscale x 2 x i64> %words) {
+; CHECK-LABEL: 'cast_unsupported_elements'
+; CHECK-NEXT: Cost Model: Invalid cost for instruction: %as_fp128 = bitcast <vscale x 1 x i128> %ints to <vscale x 1 x fp128>
+; CHECK-NEXT: Cost Model: Invalid cost for instruction: %as_i128 = bitcast <vscale x 1 x fp128> %floats to <vscale x 1 x i128>
+; CHECK-NEXT: Cost Model: Invalid cost for instruction: %as_words = bitcast <vscale x 1 x i128> %ints to <vscale x 2 x i64>
+; CHECK-NEXT: Cost Model: Invalid cost for instruction: %as_element = bitcast <vscale x 2 x i64> %words to <vscale x 1 x i128>
+; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
+ %as_fp128 = bitcast <vscale x 1 x i128> %ints to <vscale x 1 x fp128>
+ %as_i128 = bitcast <vscale x 1 x fp128> %floats to <vscale x 1 x i128>
+ %as_words = bitcast <vscale x 1 x i128> %ints to <vscale x 2 x i64>
+ %as_element = bitcast <vscale x 2 x i64> %words to <vscale x 1 x i128>
+ ret void
+}
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-ext.ll b/llvm/test/Analysis/CostModel/AArch64/sve-ext.ll
index d1a44868fbf94..270bb59448905 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-ext.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-ext.ll
@@ -5,6 +5,8 @@ target triple = "aarch64-unknown-linux-gnu"
define void @sve_ext() {
; CHECK-LABEL: 'sve_ext'
+; CHECK-NEXT: Cost Model: Found costs of 1 for: %zext_nxv1_i8_to_i32 = zext <vscale x 1 x i8> poison to <vscale x 1 x i32>
+; CHECK-NEXT: Cost Model: Found costs of 1 for: %sext_nxv1_i8_to_i32 = sext <vscale x 1 x i8> poison to <vscale x 1 x i32>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %zext_nxv16_i8_to_i16 = zext <vscale x 16 x i8> poison to <vscale x 16 x i16>
; CHECK-NEXT: Cost Model: Found costs of 6 for: %zext_nxv16_i8_to_i32 = zext <vscale x 16 x i8> poison to <vscale x 16 x i32>
; CHECK-NEXT: Cost Model: Found costs of 14 for: %zext_nxv16_i8_to_i64 = zext <vscale x 16 x i8> poison to <vscale x 16 x i64>
@@ -27,6 +29,9 @@ define void @sve_ext() {
; CHECK-NEXT: Cost Model: Found costs of 7 for: %sext_nxv8_i8_to_i64 = sext <vscale x 8 x i8> poison to <vscale x 8 x i64>
; CHECK-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret void
;
+ %zext_nxv1_i8_to_i32 = zext <vscale x 1 x i8> poison to <vscale x 1 x i32>
+ %sext_nxv1_i8_to_i32 = sext <vscale x 1 x i8> poison to <vscale x 1 x i32>
+
%zext_nxv16_i8_to_i16 = zext <vscale x 16 x i8> poison to <vscale x 16 x i16>
%zext_nxv16_i8_to_i32 = zext <vscale x 16 x i8> poison to <vscale x 16 x i32>
%zext_nxv16_i8_to_i64 = zext <vscale x 16 x i8> poison to <vscale x 16 x i64>
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-fptoi.ll b/llvm/test/Analysis/CostModel/AArch64/sve-fptoi.ll
index ef2ee6e725030..f303e9b85fa92 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-fptoi.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-fptoi.ll
@@ -16,14 +16,16 @@ define void @sve-fptoi() {
; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_ui8 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i8>
; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_si16 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i16>
; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_ui16 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i16>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_si32 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i32>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_ui32 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i32>
; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_si64 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i64>
; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f32_to_ui64 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i64>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_si8 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i8>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_ui8 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i8>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_si16 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i16>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_ui16 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i16>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_si32 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i32>
-; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv1f64_to_ui32 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i32>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_si8 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i8>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_ui8 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i8>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_si16 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i16>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_ui16 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i16>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_si32 = fptosi <vscale x 1 x double> poison to <vscale x 1 x i32>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1f64_to_ui32 = fptoui <vscale x 1 x double> poison to <vscale x 1 x i32>
; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv2f16_to_si8 = fptosi <vscale x 2 x half> poison to <vscale x 2 x i8>
; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv2f16_to_ui8 = fptoui <vscale x 2 x half> poison to <vscale x 2 x i8>
; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv2f16_to_si32 = fptosi <vscale x 2 x half> poison to <vscale x 2 x i32>
@@ -91,6 +93,8 @@ define void @sve-fptoi() {
%nv1f32_to_ui8 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i8>
%nv1f32_to_si16 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i16>
%nv1f32_to_ui16 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i16>
+ %nv1f32_to_si32 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i32>
+ %nv1f32_to_ui32 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i32>
%nv1f32_to_si64 = fptosi <vscale x 1 x float> poison to <vscale x 1 x i64>
%nv1f32_to_ui64 = fptoui <vscale x 1 x float> poison to <vscale x 1 x i64>
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-itofp.ll b/llvm/test/Analysis/CostModel/AArch64/sve-itofp.ll
index bb7f804a40c6f..33f45e2909d4a 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-itofp.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-itofp.ll
@@ -6,6 +6,30 @@ target triple = "aarch64-unknown-linux-gnu"
define void @sve-itofp() {
; CHECK-LABEL: 'sve-itofp'
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si8_to_f16 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui8_to_f16 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si16_to_f16 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui16_to_f16 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si32_to_f16 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui32_to_f16 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si64_to_f16 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui64_to_f16 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x half>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si8_to_f32 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui8_to_f32 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si16_to_f32 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui16_to_f32 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si32_to_f32 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui32_to_f32 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si64_to_f32 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui64_to_f32 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x float>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si8_to_f64 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui8_to_f64 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si16_to_f64 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui16_to_f64 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si32_to_f64 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui32_to_f64 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1si64_to_f64 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x double>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %nv1ui64_to_f64 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x double>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %nv2si8_to_f16 = sitofp <vscale x 2 x i8> poison to <vscale x 2 x half>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %nv2ui8_to_f16 = uitofp <vscale x 2 x i8> poison to <vscale x 2 x half>
; CHECK-NEXT: Cost Model: Found costs of 1 for: %nv2si16_to_f16 = sitofp <vscale x 2 x i16> poison to <vscale x 2 x half>
@@ -105,6 +129,33 @@ define void @sve-itofp() {
; CHECK-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret void
;
+ %nv1si8_to_f16 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x half>
+ %nv1ui8_to_f16 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x half>
+ %nv1si16_to_f16 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x half>
+ %nv1ui16_to_f16 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x half>
+ %nv1si32_to_f16 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x half>
+ %nv1ui32_to_f16 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x half>
+ %nv1si64_to_f16 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x half>
+ %nv1ui64_to_f16 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x half>
+
+ %nv1si8_to_f32 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x float>
+ %nv1ui8_to_f32 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x float>
+ %nv1si16_to_f32 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x float>
+ %nv1ui16_to_f32 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x float>
+ %nv1si32_to_f32 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x float>
+ %nv1ui32_to_f32 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x float>
+ %nv1si64_to_f32 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x float>
+ %nv1ui64_to_f32 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x float>
+
+ %nv1si8_to_f64 = sitofp <vscale x 1 x i8> poison to <vscale x 1 x double>
+ %nv1ui8_to_f64 = uitofp <vscale x 1 x i8> poison to <vscale x 1 x double>
+ %nv1si16_to_f64 = sitofp <vscale x 1 x i16> poison to <vscale x 1 x double>
+ %nv1ui16_to_f64 = uitofp <vscale x 1 x i16> poison to <vscale x 1 x double>
+ %nv1si32_to_f64 = sitofp <vscale x 1 x i32> poison to <vscale x 1 x double>
+ %nv1ui32_to_f64 = uitofp <vscale x 1 x i32> poison to <vscale x 1 x double>
+ %nv1si64_to_f64 = sitofp <vscale x 1 x i64> poison to <vscale x 1 x double>
+ %nv1ui64_to_f64 = uitofp <vscale x 1 x i64> poison to <vscale x 1 x double>
+
%nv2si8_to_f16 = sitofp <vscale x 2 x i8> poison to <vscale x 2 x half>
%nv2ui8_to_f16 = uitofp <vscale x 2 x i8> poison to <vscale x 2 x half>
%nv2si16_to_f16 = sitofp <vscale x 2 x i16> poison to <vscale x 2 x half>
diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll b/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
index f1f43b198f688..195926007b9d5 100644
--- a/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/sve-trunc.ll
@@ -5,6 +5,8 @@ target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
define void @sve_truncs() {
; CHECK-LABEL: 'sve_truncs'
+; CHECK-NEXT: Cost Model: Found costs of 0 for: %trunc_nxv1i64_to_i32 = trunc <vscale x 1 x i64> poison to <vscale x 1 x i32>
+; CHECK-NEXT: Cost Model: Found costs of Invalid for: %trunc_nxv1i32_to_i1 = trunc <vscale x 1 x i32> poison to <vscale x 1 x i1>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %trunc_nxv2i8_to_i1 = trunc <vscale x 2 x i8> poison to <vscale x 2 x i1>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %trunc_nxv2i16_to_i1 = trunc <vscale x 2 x i16> poison to <vscale x 2 x i1>
; CHECK-NEXT: Cost Model: Found costs of 2 for: %trunc_nxv2i32_to_i1 = trunc <vscale x 2 x i32> poison to <vscale x 2 x i1>
@@ -39,6 +41,9 @@ define void @sve_truncs() {
; CHECK-NEXT: Cost Model: Found costs of 7 for: %trunc_nxv16i64_to_i8 = trunc <vscale x 16 x i64> poison to <vscale x 16 x i8>
; CHECK-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret void
;
+ %trunc_nxv1i64_to_i32 = trunc <vscale x 1 x i64> poison to <vscale x 1 x i32>
+ %trunc_nxv1i32_to_i1 = trunc <vscale x 1 x i32> poison to <vscale x 1 x i1>
+
%trunc_nxv2i8_to_i1 = trunc <vscale x 2 x i8> poison to <vscale x 2 x i1>
%trunc_nxv2i16_to_i1 = trunc <vscale x 2 x i16> poison to <vscale x 2 x i1>
%trunc_nxv2i32_to_i1 = trunc <vscale x 2 x i32> poison to <vscale x 2 x i1>
diff --git a/llvm/test/CodeGen/AArch64/sve-bitcast.ll b/llvm/test/CodeGen/AArch64/sve-bitcast.ll
index d6516a3928db6..60f42114c6684 100644
--- a/llvm/test/CodeGen/AArch64/sve-bitcast.ll
+++ b/llvm/test/CodeGen/AArch64/sve-bitcast.ll
@@ -2513,5 +2513,57 @@ define <vscale x 2 x float> @bitcast_short_half_to_float(<vscale x 4 x half> %v)
ret <vscale x 2 x float> %bitcast
}
+define <vscale x 1 x i32> @ptrtoint_nxv1(<vscale x 1 x ptr> %a) #0 {
+; CHECK-LABEL: ptrtoint_nxv1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
+; CHECK-NEXT: ret
+;
+; CHECK_BE-LABEL: ptrtoint_nxv1:
+; CHECK_BE: // %bb.0:
+; CHECK_BE-NEXT: uzp1 z0.s, z0.s, z0.s
+; CHECK_BE-NEXT: ret
+ %r = ptrtoint <vscale x 1 x ptr> %a to <vscale x 1 x i32>
+ ret <vscale x 1 x i32> %r
+}
+
+define <vscale x 1 x ptr> @inttoptr_nxv1(<vscale x 1 x i32> %a) #0 {
+; CHECK-LABEL: inttoptr_nxv1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+;
+; CHECK_BE-LABEL: inttoptr_nxv1:
+; CHECK_BE: // %bb.0:
+; CHECK_BE-NEXT: uunpklo z0.d, z0.s
+; CHECK_BE-NEXT: ret
+ %r = inttoptr <vscale x 1 x i32> %a to <vscale x 1 x ptr>
+ ret <vscale x 1 x ptr> %r
+}
+
+define <vscale x 1 x i64> @ptrtoaddr_nxv1(<vscale x 1 x ptr> %a) #0 {
+; CHECK-LABEL: ptrtoaddr_nxv1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: ret
+;
+; CHECK_BE-LABEL: ptrtoaddr_nxv1:
+; CHECK_BE: // %bb.0:
+; CHECK_BE-NEXT: ret
+ %r = ptrtoaddr <vscale x 1 x ptr> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x ptr> @addrspacecast_nxv1(<vscale x 1 x ptr addrspace(1)> %a) #0 {
+; CHECK-LABEL: addrspacecast_nxv1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: ret
+;
+; CHECK_BE-LABEL: addrspacecast_nxv1:
+; CHECK_BE: // %bb.0:
+; CHECK_BE-NEXT: ret
+ %r = addrspacecast <vscale x 1 x ptr addrspace(1)> %a to <vscale x 1 x ptr>
+ ret <vscale x 1 x ptr> %r
+}
+
; +bf16 is required for the bfloat version.
attributes #0 = { nounwind "target-features"="+sve,+bf16" }
diff --git a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
index c69fa0d22d638..2d88a7a3d87ed 100644
--- a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
+++ b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
@@ -187,6 +187,170 @@ define <vscale x 2 x i64> @zext_i32_i64(<vscale x 2 x i32> %a) {
ret <vscale x 2 x i64> %r
}
+; Extensions of single-element scalable vectors
+
+define <vscale x 1 x i16> @sext_nxv1i8_i16(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: sext_nxv1i8_i16:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.h, z0.b
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i8> %a to <vscale x 1 x i16>
+ ret <vscale x 1 x i16> %r
+}
+
+define <vscale x 1 x i32> @sext_nxv1i8_i32(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: sext_nxv1i8_i32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.h, z0.b
+; CHECK-NEXT: sunpklo z0.s, z0.h
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i8> %a to <vscale x 1 x i32>
+ ret <vscale x 1 x i32> %r
+}
+
+define <vscale x 1 x i64> @sext_nxv1i8_i64(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: sext_nxv1i8_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.h, z0.b
+; CHECK-NEXT: sunpklo z0.s, z0.h
+; CHECK-NEXT: sunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i8> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i32> @sext_nxv1i16_i32(<vscale x 1 x i16> %a) {
+; CHECK-LABEL: sext_nxv1i16_i32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.s, z0.h
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i16> %a to <vscale x 1 x i32>
+ ret <vscale x 1 x i32> %r
+}
+
+define <vscale x 1 x i64> @sext_nxv1i16_i64(<vscale x 1 x i16> %a) {
+; CHECK-LABEL: sext_nxv1i16_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.s, z0.h
+; CHECK-NEXT: sunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i16> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i64> @sext_nxv1i32_i64(<vscale x 1 x i32> %a) {
+; CHECK-LABEL: sext_nxv1i32_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: sunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i32> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i16> @zext_nxv1i8_i16(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: zext_nxv1i8_i16:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.h, z0.b
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i8> %a to <vscale x 1 x i16>
+ ret <vscale x 1 x i16> %r
+}
+
+define <vscale x 1 x i32> @zext_nxv1i8_i32(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: zext_nxv1i8_i32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.h, z0.b
+; CHECK-NEXT: uunpklo z0.s, z0.h
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i8> %a to <vscale x 1 x i32>
+ ret <vscale x 1 x i32> %r
+}
+
+define <vscale x 1 x i64> @zext_nxv1i8_i64(<vscale x 1 x i8> %a) {
+; CHECK-LABEL: zext_nxv1i8_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.h, z0.b
+; CHECK-NEXT: uunpklo z0.s, z0.h
+; CHECK-NEXT: uunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i8> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i32> @zext_nxv1i16_i32(<vscale x 1 x i16> %a) {
+; CHECK-LABEL: zext_nxv1i16_i32:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.s, z0.h
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i16> %a to <vscale x 1 x i32>
+ ret <vscale x 1 x i32> %r
+}
+
+define <vscale x 1 x i64> @zext_nxv1i16_i64(<vscale x 1 x i16> %a) {
+; CHECK-LABEL: zext_nxv1i16_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.s, z0.h
+; CHECK-NEXT: uunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i16> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i64> @zext_nxv1i32_i64(<vscale x 1 x i32> %a) {
+; CHECK-LABEL: zext_nxv1i32_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uunpklo z0.d, z0.s
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i32> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i8> @sext_nxv1i1_i8(<vscale x 1 x i1> %a) {
+; CHECK-LABEL: sext_nxv1i1_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uzp1 p0.d, p0.d, p0.d
+; CHECK-NEXT: uzp1 p0.s, p0.s, p0.s
+; CHECK-NEXT: uzp1 p0.h, p0.h, p0.h
+; CHECK-NEXT: uzp1 p0.b, p0.b, p0.b
+; CHECK-NEXT: mov z0.b, p0/z, #-1 // =0xffffffffffffffff
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i1> %a to <vscale x 1 x i8>
+ ret <vscale x 1 x i8> %r
+}
+
+define <vscale x 1 x i64> @sext_nxv1i1_i64(<vscale x 1 x i1> %a) {
+; CHECK-LABEL: sext_nxv1i1_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uzp1 p0.d, p0.d, p0.d
+; CHECK-NEXT: mov z0.d, p0/z, #-1 // =0xffffffffffffffff
+; CHECK-NEXT: ret
+ %r = sext <vscale x 1 x i1> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
+define <vscale x 1 x i8> @zext_nxv1i1_i8(<vscale x 1 x i1> %a) {
+; CHECK-LABEL: zext_nxv1i1_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uzp1 p0.d, p0.d, p0.d
+; CHECK-NEXT: uzp1 p0.s, p0.s, p0.s
+; CHECK-NEXT: uzp1 p0.h, p0.h, p0.h
+; CHECK-NEXT: uzp1 p0.b, p0.b, p0.b
+; CHECK-NEXT: mov z0.b, p0/z, #1 // =0x1
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i1> %a to <vscale x 1 x i8>
+ ret <vscale x 1 x i8> %r
+}
+
+define <vscale x 1 x i64> @zext_nxv1i1_i64(<vscale x 1 x i1> %a) {
+; CHECK-LABEL: zext_nxv1i1_i64:
+; CHECK: // %bb.0:
+; CHECK-NEXT: uzp1 p0.d, p0.d, p0.d
+; CHECK-NEXT: mov z0.d, p0/z, #1 // =0x1
+; CHECK-NEXT: ret
+ %r = zext <vscale x 1 x i1> %a to <vscale x 1 x i64>
+ ret <vscale x 1 x i64> %r
+}
+
; Extending to illegal types
define <vscale x 16 x i16> @sext_b_to_h(<vscale x 16 x i8> %a) {
More information about the llvm-commits
mailing list