[all-commits] [llvm/llvm-project] 074391: [TwoAddressInstruction] Iterate through tied regs ...

Anton Sidorenko via All-commits all-commits at lists.llvm.org
Mon Feb 16 00:54:47 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 074391e6a1a273fac68b705f15812465126dd83a
      https://github.com/llvm/llvm-project/commit/074391e6a1a273fac68b705f15812465126dd83a
  Author: Anton Sidorenko <anton.sidorenko at mail.com>
  Date:   2026-02-16 (Mon, 16 Feb 2026)

  Changed paths:
    M llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
    A llvm/test/CodeGen/RISCV/twoaddr-tied.mir
    M llvm/test/CodeGen/X86/pmulh.ll

  Log Message:
  -----------
  [TwoAddressInstruction] Iterate through tied regs when analyzing revcopy (#179940)

Reversed copy is the following chain from FromReg to ToReg:
    %Tmp1 = copy %Tmp2;
    %FromReg = copy %Tmp1;
    %ToReg = add %FromReg ...
    %Tmp2 = copy %ToReg;

TwoAddressInstruction pass tries to preserve or create (by commuting)
such chains. Otherwise, there will be unavoidable copy.

This patch considers operations with tied operand a copy-like ones (in
terms of reversed copy chain), e.g.:
    %Tmp1 = copy %Tmp2;
    %Tmp1 = fma %Tmp1 (tied-def 0), ...
    %FromReg = copy %Tmp1;
    %ToReg = add %FromReg ...
    %Tmp2 = copy %ToReg;

This helps at least for RISC-V RVV where two forms of FMA exists:
1. vfmadd.vv vd, vs1, vs2, where vd is a dst and src multiplicand: vd[i]
= +(vs1[i] * vd[i]) + vs2[i]
2. vfmacc.vv vd, vs1, vs2, where vd is a dst and src addend: vd[i] =
+(vs1[i] * vs2[i]) + vd[i]

For the example above, vfmacc is a more preferable form of FMA than
vfmadd. However, without this patch twoaddress instruction pass does not
see the difference between these two instructions and might commute
vfmacc to vfmadd for the example above. This will lead to the extra
copy.

The patch also changes the default value of dataflow-edge-limit. This
option controls the depth of reverved copy search algorithm. With the
introduction of tied operands analysis I consider such a change
reasonable since the old default value = 3 effectively stops the
analysis earlier than any chain is found.



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