[llvm] [AArch64][GlobalISel] Check unmergeSrc is a vector in matchCombineBuildUnmerge (PR #168692)

Ryan Cowan via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 02:52:36 PST 2025


https://github.com/HolyMolyCowMan created https://github.com/llvm/llvm-project/pull/168692

This aims to fix the crash in https://github.com/llvm/llvm-project/issues/168495, my combine rule was missing a check that the source vector was in fact a vector. This then caused the legality check to fail in this example as the concat was trying to concat a non vector.

I have also gated the lowering of the concat to only work on non-scalable vectors as the mutation calls `getNumElements` which crashed when called on a scalable vector.

>From 64fc9075a6e826690ac4e4f77ebc6cd4a04298ee Mon Sep 17 00:00:00 2001
From: Ryan Cowan <ryan.cowan at arm.com>
Date: Wed, 19 Nov 2025 10:48:41 +0000
Subject: [PATCH] [AArch64][GlobalISel] Check unmergeSrc is a vector in
 matchCombineBuildUnmerge

---
 llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp         | 3 +++
 llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 45a08347b1ec2..f0fbe0135353f 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -3499,6 +3499,9 @@ bool CombinerHelper::matchCombineBuildUnmerge(MachineInstr &MI,
   LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
   LLT UnmergeSrcTy = MRI.getType(UnmergeSrc);
 
+  if (!UnmergeSrcTy.isVector())
+    return false;
+
   // Ensure we only generate legal instructions post-legalizer
   if (!IsPreLegalize &&
       !isLegal({TargetOpcode::G_CONCAT_VECTORS, {DstTy, UnmergeSrcTy}}))
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fdf69b04bf676..2ffdae7d51704 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -1243,7 +1243,9 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
       .bitcastIf(
           [=](const LegalityQuery &Query) {
             return Query.Types[0].getSizeInBits() <= 128 &&
-                   Query.Types[1].getSizeInBits() <= 64;
+                   Query.Types[1].getSizeInBits() <= 64 &&
+                   !Query.Types[0].isScalableVector() &&
+                   !Query.Types[1].isScalableVector();
           },
           [=](const LegalityQuery &Query) {
             const LLT DstTy = Query.Types[0];



More information about the llvm-commits mailing list