[llvm] [AArch64][SVE] - Fix crash Possible incorrect use of EVT::getVectorNumElements(). (PR #218733)

Pawan Nirpal via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 03:48:44 PDT 2026


https://github.com/pawan-nirpal-031 updated https://github.com/llvm/llvm-project/pull/218733

>From 3907d167f1116294fc51d685d7ec70222c331d65 Mon Sep 17 00:00:00 2001
From: Pawan Nirpal <pnirpal at qti.qualcomm.com>
Date: Tue, 25 Aug 2026 10:27:37 -0700
Subject: [PATCH] [AArch64][SVE] - Fix crash  Possible incorrect use of
 EVT::getVectorNumElements()

---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp |  4 +++-
 .../AArch64/sve-usubsat-dag-combine.ll        | 24 +++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/sve-usubsat-dag-combine.ll

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 28a8cb9409648..36a07de7acf35 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4712,7 +4712,9 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) {
   // Narrow a vXiN USUBSAT to a smaller type when both operands are known
   // to fit in fewer bits. This allows targets with native narrow USUBSAT
   // (e.g. vpsubusb/vpsubusw) to avoid emulation with vpmaxu + vsub.
-  if (!IsSigned && VT.isVector() && VT.isSimple()) {
+  // TODO: Evaluate if this is feasible for scalable types, restricting this
+  // change for fixed types for now due to crash for scalable type.
+  if (!IsSigned && VT.isFixedLengthVector() && VT.isSimple()) {
     unsigned ScalarBits = VT.getScalarSizeInBits();
     if (ScalarBits > 8 && isPowerOf2_32(ScalarBits) &&
         !TLI.isOperationLegal(ISD::USUBSAT, VT)) {
diff --git a/llvm/test/CodeGen/AArch64/sve-usubsat-dag-combine.ll b/llvm/test/CodeGen/AArch64/sve-usubsat-dag-combine.ll
new file mode 100644
index 0000000000000..d5ddac2fb9462
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/sve-usubsat-dag-combine.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
+target triple = "aarch64-unknown-linux-gnu"
+
+define <vscale x 8 x i32> @blend_heat_16bit(<vscale x 8 x i32> %0) #0 {
+; CHECK-LABEL: blend_heat_16bit:
+; CHECK:       // %bb.0: // %.lr.ph
+; CHECK-NEXT:    mov z2.s, #1 // =0x1
+; CHECK-NEXT:    uqsub z0.s, z2.s, z0.s
+; CHECK-NEXT:    uqsub z1.s, z2.s, z1.s
+; CHECK-NEXT:    ret
+.lr.ph:
+  %1 = call <vscale x 8 x i32> @llvm.usub.sat.nxv8i32(<vscale x 8 x i32> splat (i32 1), <vscale x 8 x i32> %0)
+  ret <vscale x 8 x i32> %1
+}
+
+declare <vscale x 8 x i32> @llvm.usub.sat.nxv8i32(<vscale x 8 x i32>, <vscale x 8 x i32>) #1
+
+attributes #0 = { "target-features"="+sve" }
+attributes #1 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
+



More information about the llvm-commits mailing list