[llvm] [GlobalISel] Fix vector.deinterleave2 with <1 x float> results (PR #214718)

Mészáros Gergely via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 04:27:00 PDT 2026


https://github.com/Maetveis updated https://github.com/llvm/llvm-project/pull/214718

>From a0bea5418c23b652a65a579fa68f2cf716f7d4a5 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Fri, 7 Aug 2026 12:37:35 +0000
Subject: [PATCH 1/4] [GlobalISel] Pre-commit test for GH Issue #214713

GlobalIsel is crashing on a `@llvm.vector.deinterleave2` with `<1 x float>`
results.
---
 .../CodeGen/Generic/GlobalISel/GH-214713.ll   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll

diff --git a/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll b/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
new file mode 100644
index 0000000000000..32547649e6f88
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
@@ -0,0 +1,19 @@
+; REQUIRES: asserts, aarch64-registered-target
+; RUN: not --crash llc -global-isel -stop-after=irtranslator <%s 2>&1 | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; CHECK: Assertion {{.*}}ResTy.isVector() && "Expected vector result type"
+
+define float @test(<2 x float> %w) {
+  %1 = call { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float> %w)
+  %2 = extractvalue { <1 x float>, <1 x float> } %1, 0
+  %3 = extractvalue { <1 x float>, <1 x float> } %1, 1
+  %4 = extractelement <1 x float> %2, i32 0
+  %5 = extractelement <1 x float> %3, i32 0
+  %6 = fadd float %4, %5
+  ret float %6
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float>) #1

>From 7ec5489245a02584e67d406eb3182e93044b61c5 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Fri, 7 Aug 2026 12:39:03 +0000
Subject: [PATCH 2/4] [GlobalISel] Fix vector.deinterleave2 with <1 x float>
 results

`translateVectorDeinterleave2Intrinsic` used to try to build `G_SHUFFLE_VECTOR`
with a scalar result type, which is not valid.
This is because the LLT for <1 x float> is a scalar type, not a vector type.

Add a special case for scalar result types to build `G_EXTRACT_VECTOR_ELT`
instead.

Fixes: #214713
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  8 +++++++
 .../CodeGen/Generic/GlobalISel/GH-214713.ll   | 22 ++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index a212604502673..d4734212e8584 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1900,6 +1900,14 @@ bool IRTranslator::translateVectorDeinterleave2Intrinsic(
   ArrayRef<Register> Res = getOrCreateVRegs(CI);
 
   LLT ResTy = MRI->getType(Res[0]);
+  if (ResTy.isScalar()) {
+    MIRBuilder.buildExtractVectorElementConstant(Res[0], Op, 0);
+    MIRBuilder.buildExtractVectorElementConstant(Res[1], Op, 1);
+
+    return true;
+  }
+  
+  assert(ResTy.isVector() && "Expected vector result type");
   MIRBuilder.buildShuffleVector(Res[0], Op, Undef,
                                 createStrideMask(0, 2, ResTy.getNumElements()));
   MIRBuilder.buildShuffleVector(Res[1], Op, Undef,
diff --git a/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll b/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
index 32547649e6f88..338275e7f102b 100644
--- a/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
+++ b/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
@@ -1,11 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts, aarch64-registered-target
-; RUN: not --crash llc -global-isel -stop-after=irtranslator <%s 2>&1 | FileCheck %s
+; RUN: llc -global-isel -stop-after=irtranslator < %s 2>&1 | FileCheck %s
 
-target triple = "aarch64-unknown-linux-gnu"
+; Check that vector.deinterleave2 with <1 x float> results does not crash in GlobalISel.
+; We used to try to build G_SHUFFLE_VECTOR with a scalar result type, which is not valid.
 
-; CHECK: Assertion {{.*}}ResTy.isVector() && "Expected vector result type"
+target triple = "aarch64-unknown-linux-gnu"
 
 define float @test(<2 x float> %w) {
+  ; CHECK-LABEL: name: test
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK-NEXT:   liveins: $d0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(<2 x i32>) = COPY $d0
+  ; CHECK-NEXT:   [[BITCAST:%[0-9]+]]:_(<2 x f32>) = G_BITCAST [[COPY]](<2 x i32>)
+  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<2 x f32>) = G_IMPLICIT_DEF
+  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(i64) = G_CONSTANT i64 0
+  ; CHECK-NEXT:   [[EVEC:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C]](i64)
+  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(i64) = G_CONSTANT i64 1
+  ; CHECK-NEXT:   [[EVEC1:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C1]](i64)
+  ; CHECK-NEXT:   [[FADD:%[0-9]+]]:_(f32) = G_FADD [[EVEC]], [[EVEC1]]
+  ; CHECK-NEXT:   $s0 = COPY [[FADD]](f32)
+  ; CHECK-NEXT:   RET_ReallyLR implicit $s0
   %1 = call { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float> %w)
   %2 = extractvalue { <1 x float>, <1 x float> } %1, 0
   %3 = extractvalue { <1 x float>, <1 x float> } %1, 1

>From 4f7e0ede9aa875441caebd298392a224a33d1497 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Fri, 7 Aug 2026 16:27:11 +0000
Subject: [PATCH 3/4] Move the test

---
 .../irtranslator-vector-deinterleave2.ll      | 19 ++++++++++
 .../CodeGen/Generic/GlobalISel/GH-214713.ll   | 35 -------------------
 2 files changed, 19 insertions(+), 35 deletions(-)
 delete mode 100644 llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll

diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-vector-deinterleave2.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-vector-deinterleave2.ll
index d818bcb17e1a8..235137273f851 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-vector-deinterleave2.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-vector-deinterleave2.ll
@@ -1,6 +1,25 @@
 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
 ; RUN: llc -O0 -mtriple=aarch64-- --global-isel --verify-machineinstrs --stop-after=irtranslator %s -o - | FileCheck %s
 
+; Check that vector.deinterleave2 with <1 x float> results does not crash in GlobalISel.
+; We used to try to build G_SHUFFLE_VECTOR with a scalar result type, which is not valid.
+define void @vector_deinterleave2_v2f32(<2 x float> %a) {
+  ; CHECK-LABEL: name: vector_deinterleave2_v2f32
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK-NEXT:   liveins: $d0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(<2 x i32>) = COPY $d0
+  ; CHECK-NEXT:   [[BITCAST:%[0-9]+]]:_(<2 x f32>) = G_BITCAST [[COPY]](<2 x i32>)
+  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<2 x f32>) = G_IMPLICIT_DEF
+  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(i64) = G_CONSTANT i64 0
+  ; CHECK-NEXT:   [[EVEC:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C]](i64)
+  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(i64) = G_CONSTANT i64 1
+  ; CHECK-NEXT:   [[EVEC1:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C1]](i64)
+  ; CHECK-NEXT:   RET_ReallyLR
+  %res = call { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float> %a)
+  ret void
+}
+
 define void @vector_deinterleave2_v4i32(<4 x i32> %a) {
   ; CHECK-LABEL: name: vector_deinterleave2_v4i32
   ; CHECK: bb.1 (%ir-block.0):
diff --git a/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll b/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
deleted file mode 100644
index 338275e7f102b..0000000000000
--- a/llvm/test/CodeGen/Generic/GlobalISel/GH-214713.ll
+++ /dev/null
@@ -1,35 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
-; REQUIRES: asserts, aarch64-registered-target
-; RUN: llc -global-isel -stop-after=irtranslator < %s 2>&1 | FileCheck %s
-
-; Check that vector.deinterleave2 with <1 x float> results does not crash in GlobalISel.
-; We used to try to build G_SHUFFLE_VECTOR with a scalar result type, which is not valid.
-
-target triple = "aarch64-unknown-linux-gnu"
-
-define float @test(<2 x float> %w) {
-  ; CHECK-LABEL: name: test
-  ; CHECK: bb.1 (%ir-block.0):
-  ; CHECK-NEXT:   liveins: $d0
-  ; CHECK-NEXT: {{  $}}
-  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(<2 x i32>) = COPY $d0
-  ; CHECK-NEXT:   [[BITCAST:%[0-9]+]]:_(<2 x f32>) = G_BITCAST [[COPY]](<2 x i32>)
-  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<2 x f32>) = G_IMPLICIT_DEF
-  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(i64) = G_CONSTANT i64 0
-  ; CHECK-NEXT:   [[EVEC:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C]](i64)
-  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(i64) = G_CONSTANT i64 1
-  ; CHECK-NEXT:   [[EVEC1:%[0-9]+]]:_(f32) = G_EXTRACT_VECTOR_ELT [[BITCAST]](<2 x f32>), [[C1]](i64)
-  ; CHECK-NEXT:   [[FADD:%[0-9]+]]:_(f32) = G_FADD [[EVEC]], [[EVEC1]]
-  ; CHECK-NEXT:   $s0 = COPY [[FADD]](f32)
-  ; CHECK-NEXT:   RET_ReallyLR implicit $s0
-  %1 = call { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float> %w)
-  %2 = extractvalue { <1 x float>, <1 x float> } %1, 0
-  %3 = extractvalue { <1 x float>, <1 x float> } %1, 1
-  %4 = extractelement <1 x float> %2, i32 0
-  %5 = extractelement <1 x float> %3, i32 0
-  %6 = fadd float %4, %5
-  ret float %6
-}
-
-; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
-declare { <1 x float>, <1 x float> } @llvm.vector.deinterleave2.v2f32(<2 x float>) #1

>From 6fbdfe9fed717f4384ea2b229cd0d9478f944b34 Mon Sep 17 00:00:00 2001
From: "Meszaros, Gergely" <gergely.meszaros at intel.com>
Date: Fri, 7 Aug 2026 16:27:51 +0000
Subject: [PATCH 4/4] Apply clang-format

---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d4734212e8584..59da464bb25cc 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -1906,7 +1906,7 @@ bool IRTranslator::translateVectorDeinterleave2Intrinsic(
 
     return true;
   }
-  
+
   assert(ResTy.isVector() && "Expected vector result type");
   MIRBuilder.buildShuffleVector(Res[0], Op, Undef,
                                 createStrideMask(0, 2, ResTy.getNumElements()));



More information about the llvm-commits mailing list