[llvm] [AArch64] Fix sign-extend-inreg combine for i1 types (PR #177976)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 26 07:16:28 PST 2026
https://github.com/sdesmalen-arm created https://github.com/llvm/llvm-project/pull/177976
This fixes https://github.com/llvm/llvm-project/issues/177925
>From 796806f3bab80d258d74afe2773f62d537d27005 Mon Sep 17 00:00:00 2001
From: Sander de Smalen <sander.desmalen at arm.com>
Date: Mon, 26 Jan 2026 15:11:14 +0000
Subject: [PATCH] [AArch64] Fix Sign-extend-inreg combine for i1 types
This fixes https://github.com/llvm/llvm-project/issues/177925
---
.../Target/AArch64/AArch64ISelLowering.cpp | 5 ++--
llvm/test/CodeGen/AArch64/sve-sext-zext.ll | 28 +++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 6d7aa0d677862..0253cb826372c 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -27775,8 +27775,9 @@ performSignExtendInRegCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
EVT EltTy = VT.getVectorElementType();
(void)EltTy;
- assert((EltTy == MVT::i8 || EltTy == MVT::i16 || EltTy == MVT::i32) &&
- "Sign extending from an invalid type");
+ if (EltTy.getSizeInBits() >
+ ExtOp.getValueType().getScalarType().getSizeInBits())
+ return SDValue();
EVT ExtVT = VT.getDoubleNumVectorElementsVT(*DAG.getContext());
diff --git a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
index 845628a91498b..54dd83eaec507 100644
--- a/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
+++ b/llvm/test/CodeGen/AArch64/sve-sext-zext.ll
@@ -584,3 +584,31 @@ define <vscale x 2 x i64> @zext_inreg_i64_from_i32(<vscale x 4 x i32> %a) {
%zext = zext <vscale x 2 x i32> %subvec to <vscale x 2 x i64>
ret <vscale x 2 x i64> %zext
}
+
+; Sign-extend-inreg from i8 -> i1 -> i16
+define <vscale x 16 x i16> @sext_inreg_i1_to_i16_from_i8(<vscale x 16 x i8> %a) {
+; CHECK-LABEL: sext_inreg_i1_to_i16_from_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: lsl z0.b, z0.b, #7
+; CHECK-NEXT: asr z1.b, z0.b, #7
+; CHECK-NEXT: sunpklo z0.h, z1.b
+; CHECK-NEXT: sunpkhi z1.h, z1.b
+; CHECK-NEXT: ret
+ %a.trunc = trunc <vscale x 16 x i8> %a to <vscale x 16 x i1>
+ %a.sextinreg = sext <vscale x 16 x i1> %a.trunc to <vscale x 16 x i16>
+ ret <vscale x 16 x i16> %a.sextinreg
+}
+
+; Sign-extend-inreg from i8 -> i2 -> i16
+define <vscale x 16 x i16> @sext_inreg_i2_to_i16_from_i8(<vscale x 16 x i8> %a) {
+; CHECK-LABEL: sext_inreg_i2_to_i16_from_i8:
+; CHECK: // %bb.0:
+; CHECK-NEXT: lsl z0.b, z0.b, #6
+; CHECK-NEXT: asr z1.b, z0.b, #6
+; CHECK-NEXT: sunpklo z0.h, z1.b
+; CHECK-NEXT: sunpkhi z1.h, z1.b
+; CHECK-NEXT: ret
+ %a.trunc = trunc <vscale x 16 x i8> %a to <vscale x 16 x i2>
+ %a.sextinreg = sext <vscale x 16 x i2> %a.trunc to <vscale x 16 x i16>
+ ret <vscale x 16 x i16> %a.sextinreg
+}
More information about the llvm-commits
mailing list