[llvm] [GlobalISel] Exclude scalar to ptr unmerges from unmerge_dead_to_trunc combiner (PR #206707)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 30 04:08:23 PDT 2026
https://github.com/KRM7 created https://github.com/llvm/llvm-project/pull/206707
This combiner is supposed to replace a G_UNMERGE_VALUES with a truncate if only the first element is used. Vector types are excluded because the combiner will not insert bitcasts before/after the truncate, but the case where either the src/dst type is a scalar and the other type is a pointer is not handled even though this case would also need bitcasts.
>From 156b97d47f652cc19ea97ba15ffcc33c32a6882f Mon Sep 17 00:00:00 2001
From: Krisztian Rugasi <Krisztian.Rugasi at hightec-rt.com>
Date: Tue, 30 Jun 2026 12:58:49 +0200
Subject: [PATCH] [GlobalISel] Exclude scalar to ptr unmerges from
unmerge_dead_to_trunc combiner
This combiner is supposed to replace a G_UNMERGE_VALUES with a truncate
if only the first element is used. Vector types are excluded because the
combiner will not insert bitcasts before/after the truncate, but the
case where either the src/dst type is a scalar and the other type is a
pointer is not handled even though this case would also need bitcasts.
---
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 4 ++--
.../CodeGen/AArch64/GlobalISel/combine-unmerge.mir | 13 +++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index ab0003cab6c2a..072f194b36d5a 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -2469,8 +2469,8 @@ bool CombinerHelper::matchCombineUnmergeWithDeadLanesToTrunc(
MachineInstr &MI) const {
assert(MI.getOpcode() == TargetOpcode::G_UNMERGE_VALUES &&
"Expected an unmerge");
- if (MRI.getType(MI.getOperand(0).getReg()).isVector() ||
- MRI.getType(MI.getOperand(MI.getNumDefs()).getReg()).isVector())
+ if (!MRI.getType(MI.getOperand(0).getReg()).isScalar() ||
+ !MRI.getType(MI.getOperand(MI.getNumDefs()).getReg()).isScalar())
return false;
// Check that all the lanes are dead except the first one.
for (unsigned Idx = 1, EndIdx = MI.getNumDefs(); Idx != EndIdx; ++Idx) {
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/combine-unmerge.mir b/llvm/test/CodeGen/AArch64/GlobalISel/combine-unmerge.mir
index f427f8648a301..9695a2bd34ed3 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/combine-unmerge.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/combine-unmerge.mir
@@ -340,6 +340,19 @@ body: |
$h0 = COPY %1(s16)
...
+---
+name: test_combine_unmerge_dead_to_trunc_ptr_out
+body: |
+ bb.1:
+ ; CHECK-LABEL: name: test_combine_unmerge_dead_to_trunc_ptr_out
+ ; CHECK: [[COPY:%[0-9]+]]:_(s128) = COPY $q0
+ ; CHECK-NEXT: [[UV:%[0-9]+]]:_(p0), [[UV1:%[0-9]+]]:_(p0) = G_UNMERGE_VALUES [[COPY]](s128)
+ ; CHECK-NEXT: $x0 = COPY [[UV]](p0)
+ %0:_(s128) = COPY $q0
+ %1:_(p0), %2:_(p0) = G_UNMERGE_VALUES %0(s128)
+ $x0 = COPY %1(p0)
+...
+
# Transform unmerge(zext) into zext.
# In that test, the source of the zext is same size as the first definition
# of the unmerge. Therefore a we can just reuse the input of the zext for
More information about the llvm-commits
mailing list