[all-commits] [llvm/llvm-project] 684498: [GlobalISel] emit G_BITCAST in widenScalarMergeVal...

Kacper Doga via All-commits all-commits at lists.llvm.org
Mon Aug 3 05:16:39 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 68449895e267174801d3b11afd957548f5796a41
      https://github.com/llvm/llvm-project/commit/68449895e267174801d3b11afd957548f5796a41
  Author: Kacper Doga <kacper.doga at intel.com>
  Date:   2026-08-03 (Mon, 03 Aug 2026)

  Changed paths:
    M llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
    M llvm/test/CodeGen/AMDGPU/GlobalISel/fp-int-conversions.ll
    M llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-merge-values.mir

  Log Message:
  -----------
  [GlobalISel] emit G_BITCAST in widenScalarMergeValues when DstTy does not match WideTy (#203014)

**Problem:**
`LegalizerHelper::widenScalarMergeValues` does not handle the case where
the destination register type is a floating-point type but the widen
operation produces an integer type of the same size.

For example, given:
```
%0:_(i8) = G_CONSTANT i8 0
%1:_(i8) = G_CONSTANT i8 1
%2:_(f16) = G_MERGE_VALUES %0:_(i8), %1_:(i8)
```
With a `minScalarOrElt` rule widening the source type to I16,
`widenScalarMergeValues` enters the `WideSize >= DstSize` path and
assigns the result to a new virtual register. The condition used to
assign directly to DstReg uses type equality (WideTy == DstTy), which
fails when DstTy = f16. As a result, DstReg is left without a
definition.

**Fix:**
After the OR-reduction loop, add a check for the case where DstTy and
WideTy have equal sizes but different types, and emit a G_BITCAST.

**Testing:**
No currently upstream target exercises `G_MERGE_VALUES` with a
floating-point destination type through this widen path, as most targets
promote f16 to s16 before legalization. The fix is therefore covered by
a unit test in `LegalizerHelperTest.cpp`, modeled after the existing
`WidenScalarMergeValuesPointer` test, which directly invokes widenScalar
on a manually constructed `f16 = G_MERGE_VALUES i8, i8` instruction and
verifies that a `G_BITCAST` is emitted as the final instruction.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list