[llvm] [GlobalISel] avoid G_TRUNC with floating-point G_MERGE_VALUES source (PR #206733)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 00:59:06 PDT 2026
================
@@ -0,0 +1,72 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=aarch64 -run-pass=legalizer %s -o - | FileCheck %s
+
+# Regression test for LegalizationArtifactCombiner::tryCombineTrunc: a G_TRUNC
+# whose G_MERGE_VALUES source operands are floating-point must not fold to a
+# G_TRUNC (or rebuilt G_MERGE_VALUES) with a float source operand. The float
+# source is reinterpreted to an integer of the same size via G_BITCAST first.
+
+---
+# DstSize < MergeSrcSize - trunc folds trought the merge to the first source.
+name: trunc_merge_float_src_smaller
+legalized: true
+body: |
+ bb.0:
+ liveins: $s0, $s1
+ ; CHECK-LABEL: name: trunc_merge_float_src_smaller
+ ; CHECK: liveins: $s0, $s1
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(f32) = COPY $s0
+ ; CHECK-NEXT: [[BITCAST:%[0-9]+]]:_(i32) = G_BITCAST [[COPY]](f32)
+ ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[BITCAST]](i32)
+ ; CHECK-NEXT: $h0 = COPY [[TRUNC]](s16)
+ %0:_(f32) = COPY $s0
+ %1:_(f32) = COPY $s1
+ %2:_(s64) = G_MERGE_VALUES %0(f32), %1(f32)
+ %3:_(s16) = G_TRUNC %2(s64)
----------------
davemgreen wrote:
The IR should have `i` types nowadays not `s` types, it is best not to add new s types to the tests if we can avoid it. Does the real code from llvmir produce similar code to this? I know there are some places that still use scalar types that probably shouldn't.
https://github.com/llvm/llvm-project/pull/206733
More information about the llvm-commits
mailing list