[all-commits] [llvm/llvm-project] a897dc: PeepholeOpt: Fix looking for def of current copy t...

Matt Arsenault via All-commits all-commits at lists.llvm.org
Mon Feb 3 09:14:08 PST 2025


  Branch: refs/heads/users/arsenm/peephole-opt/fix-looking-for-def-of-current-instruction
  Home:   https://github.com/llvm/llvm-project
  Commit: a897dcf826c891f161b44efbf44ee376adf263bc
      https://github.com/llvm/llvm-project/commit/a897dcf826c891f161b44efbf44ee376adf263bc
  Author: Matt Arsenault <Matthew.Arsenault at amd.com>
  Date:   2025-02-04 (Tue, 04 Feb 2025)

  Changed paths:
    M llvm/lib/CodeGen/PeepholeOptimizer.cpp
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64_be-atomicrmw-lse2.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64_be-atomicrmw-rcpc.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64_be-atomicrmw-rcpc3.ll
    M llvm/test/CodeGen/AArch64/Atomics/aarch64_be-atomicrmw-v8a.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/arm64-atomic.ll
    M llvm/test/CodeGen/AArch64/GlobalISel/arm64-pcsections.ll
    M llvm/test/CodeGen/AArch64/addsub_ext.ll
    M llvm/test/CodeGen/AArch64/and-mask-removal.ll
    M llvm/test/CodeGen/AArch64/arm64-ldxr-stxr.ll
    M llvm/test/CodeGen/AArch64/arm64-vaddv.ll
    M llvm/test/CodeGen/AArch64/arm64_32-addrs.ll
    M llvm/test/CodeGen/AArch64/atomic-ops-msvc.ll
    M llvm/test/CodeGen/AArch64/atomic-ops.ll
    M llvm/test/CodeGen/AArch64/atomicrmw-fadd.ll
    M llvm/test/CodeGen/AArch64/atomicrmw-fmax.ll
    M llvm/test/CodeGen/AArch64/atomicrmw-fmin.ll
    M llvm/test/CodeGen/AArch64/atomicrmw-fsub.ll
    M llvm/test/CodeGen/AArch64/atomicrmw-xchg-fp.ll
    M llvm/test/CodeGen/AArch64/cmp-to-cmn.ll
    M llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll
    M llvm/test/CodeGen/AArch64/extract-bits.ll
    M llvm/test/CodeGen/AArch64/fold-int-pow2-with-fmul-or-fdiv.ll
    M llvm/test/CodeGen/AArch64/fsh.ll
    M llvm/test/CodeGen/AArch64/funnel-shift.ll
    M llvm/test/CodeGen/AArch64/hoist-and-by-const-from-lshr-in-eqcmp-zero.ll
    M llvm/test/CodeGen/AArch64/hoist-and-by-const-from-shl-in-eqcmp-zero.ll
    M llvm/test/CodeGen/AArch64/logic-shift.ll
    M llvm/test/CodeGen/AArch64/neon-insextbitcast.ll
    M llvm/test/CodeGen/AArch64/shift-by-signext.ll
    M llvm/test/CodeGen/AArch64/shift.ll
    M llvm/test/CodeGen/AArch64/sink-and-fold.ll
    M llvm/test/CodeGen/AArch64/sve-fixed-length-subvector.ll
    M llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-fp-to-int.ll
    M llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-permute-zip-uzp-trn.ll
    M llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll
    M llvm/test/CodeGen/AMDGPU/llvm.amdgcn.init.whole.wave-w32.ll
    M llvm/test/CodeGen/AMDGPU/mul_int24.ll
    A llvm/test/CodeGen/AMDGPU/peephole-opt-fold-reg-sequence-subreg.mir
    M llvm/test/CodeGen/ARM/aes-erratum-fix.ll
    M llvm/test/CodeGen/ARM/arm-bf16-dotprod-intrinsics.ll
    M llvm/test/CodeGen/ARM/armv8.2a-fp16-vector-intrinsics.ll
    M llvm/test/CodeGen/ARM/bf16-create-get-set-dup.ll
    M llvm/test/CodeGen/ARM/bf16-shuffle.ll
    M llvm/test/CodeGen/ARM/minnum-maxnum-intrinsics.ll
    M llvm/test/CodeGen/ARM/neon-copy.ll
    M llvm/test/CodeGen/ARM/neon-v8.1a.ll
    M llvm/test/CodeGen/ARM/vdup.ll
    M llvm/test/CodeGen/ARM/vext.ll
    M llvm/test/CodeGen/ARM/vmul.ll
    M llvm/test/CodeGen/ARM/vpadd.ll
    M llvm/test/CodeGen/ARM/vuzp.ll
    M llvm/test/CodeGen/ARM/vzip.ll
    M llvm/test/CodeGen/AVR/return.ll
    M llvm/test/CodeGen/BPF/is_trunc_free.ll
    M llvm/test/CodeGen/PowerPC/aggressive-anti-dep-breaker-subreg.ll
    M llvm/test/CodeGen/PowerPC/mma-acc-copy-hints.ll
    M llvm/test/CodeGen/PowerPC/mma-acc-memops.ll
    M llvm/test/CodeGen/PowerPC/paired-vector-intrinsics.ll
    M llvm/test/CodeGen/PowerPC/peephole-subreg-def.mir
    M llvm/test/CodeGen/RISCV/rvv/fixed-vectors-cttz-vp.ll
    M llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll
    M llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-scatter.ll
    M llvm/test/CodeGen/RISCV/rvv/vector-interleave.ll
    M llvm/test/CodeGen/SPARC/fmuladd-soft-float.ll
    M llvm/test/CodeGen/SPARC/fp128.ll
    M llvm/test/CodeGen/SPARC/fp16-promote.ll
    M llvm/test/CodeGen/SystemZ/int-uadd-01.ll
    M llvm/test/CodeGen/SystemZ/int-uadd-02.ll
    M llvm/test/CodeGen/SystemZ/pr60413.ll
    M llvm/test/CodeGen/Thumb2/mve-complex-deinterleaving-uniform-cases.ll
    M llvm/test/CodeGen/Thumb2/mve-float32regloops.ll
    M llvm/test/CodeGen/Thumb2/mve-masked-ldst.ll
    M llvm/test/CodeGen/Thumb2/mve-shuffle.ll
    M llvm/test/CodeGen/Thumb2/mve-vcvt16.ll
    M llvm/test/CodeGen/Thumb2/mve-vld2.ll
    M llvm/test/CodeGen/Thumb2/mve-vld3.ll
    M llvm/test/CodeGen/Thumb2/mve-vld4.ll
    M llvm/test/CodeGen/Thumb2/mve-vldst4.ll
    M llvm/test/CodeGen/Thumb2/mve-vst2.ll
    M llvm/test/CodeGen/Thumb2/mve-vst3.ll
    M llvm/test/CodeGen/Thumb2/mve-vst4.ll
    M llvm/test/CodeGen/VE/Scalar/select.ll
    M llvm/test/CodeGen/VE/Scalar/va_caller.ll
    M llvm/test/CodeGen/X86/AMX/amx-ldtilecfg-insert.ll
    M llvm/test/CodeGen/X86/avx512-calling-conv.ll
    M llvm/test/CodeGen/X86/avx512-ext.ll
    M llvm/test/CodeGen/X86/div-rem-pair-recomposition-signed.ll
    M llvm/test/CodeGen/X86/fminimum-fmaximum.ll
    M llvm/test/CodeGen/X86/fminimumnum-fmaximumnum.ll
    M llvm/test/CodeGen/X86/half.ll
    M llvm/test/CodeGen/X86/smax.ll
    M llvm/test/CodeGen/X86/smin.ll
    M llvm/test/CodeGen/X86/test-shrink.ll
    M llvm/test/CodeGen/X86/umax.ll
    M llvm/test/CodeGen/X86/umin.ll
    M llvm/test/CodeGen/X86/vector-compress.ll
    M llvm/test/CodeGen/X86/vector-fshl-256.ll
    M llvm/test/CodeGen/X86/wide-scalar-shift-legalization.ll
    M llvm/test/CodeGen/X86/widen-load-of-small-alloca-with-zero-upper-half.ll
    M llvm/test/CodeGen/X86/widen-load-of-small-alloca.ll

  Log Message:
  -----------
  PeepholeOpt: Fix looking for def of current copy to coalesce

This fixes the handling of subregister extract copies. This
will allow AMDGPU to remove its implementation of
shouldRewriteCopySrc, which exists as a 10 year old workaround
to this bug. peephole-opt-fold-reg-sequence-subreg.mir will
show the expected improvement once the custom implementation
is removed.

The copy coalescing processing here is overly abstracted
from what's actually happening. Previously when visiting
coalescable copy-like instructions, we would parse the
sources one at a time and then pass the def of the root
instruction into findNextSource. This means that the
first thing the new ValueTracker constructed would do
is getVRegDef to find the instruction we are currently
processing. This adds an unnecessary step, placing
a useless entry in the RewriteMap, and required skipping
the no-op case where getNewSource would return the original
source operand. This was a problem since in the case
of a subregister extract, shouldRewriteCopySource would always
say that it is useful to rewrite and the use-def chain walk
would abort, returning the original operand. Move the process
to start looking at the source operand to begin with.

This does not fix the confused handling in the uncoalescable
copy case which is proving to be more difficult. Some currently
handled cases have multiple defs from a single source, and other
handled cases have 0 input operands. It would be simpler if
this was implemented with isCopyLikeInstr, rather than guessing
at the operand structure as it does now.

There are some improvements and some regressions. The
regressions appear to be downstream issues for the most part. One
of the uglier regressions is in PPC, where a sequence of insert_subrgs
is used to build registers. I opened #125502 to use reg_sequence instead,
which may help.

The worst regression is an absurd SPARC testcase using a <251 x fp128>,
which uses a very long chain of insert_subregs.

We need improved subregister handling locally in PeepholeOptimizer,
and other pasess like MachineCSE to fix some of the other regressions.
We should handle subregister composes and folding more indexes
into insert_subreg and reg_sequence.



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