[all-commits] [llvm/llvm-project] fb2fee: [RISCV][VPlan] Cost vp.merges that are likely to b...

Luke Lau via All-commits all-commits at lists.llvm.org
Thu Jul 16 02:08:00 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fb2feebb64a6975f993791d86f00b085d6cd3bca
      https://github.com/llvm/llvm-project/commit/fb2feebb64a6975f993791d86f00b085d6cd3bca
  Author: Luke Lau <luke at igalia.com>
  Date:   2026-07-16 (Thu, 16 Jul 2026)

  Changed paths:
    M llvm/include/llvm/Analysis/TargetTransformInfo.h
    M llvm/lib/Analysis/TargetTransformInfo.cpp
    M llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
    M llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
    M llvm/test/Transforms/LoopVectorize/RISCV/force-vect-msg.ll
    M llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll

  Log Message:
  -----------
  [RISCV][VPlan] Cost vp.merges that are likely to be folded away as free (#209387)

A vp.merge is lowered to a PseudoVMERGE_VVM on RISC-V, and
RISCVVectorPeehole usually folds away PseudoVMERGE_VVMs when its true
operand is a binary op.

This accounts for this in the cost model and plumbs it through the loop
vectorizer. The following reduction loop was previously considered
unprofitable to vectorize, but after this change is now vectorized, and
folds away all its vp.merges:

    void three_gathers(const long *a, const long *c, const long *d,
                       const long *b, long n, long *out) {
      long s1 = 0, s2 = 0, s3 = 0;
      for (long i = 0; i < n; i++) {
        long j = b[i];
        s1 += a[j];
        s2 += c[j];
        s3 += d[j];
      }
      out[0] = s1;
      out[1] = s2;
      out[2] = s3;
    }

Some vp.merges have only phis for their operands which can't be folded
away, coming from FindLastIV reductions. So this extends and reuses the
VectorInstrContext hint to limit the discount when one of the operands
is a binary op.

Also see the commit message in 9e77f59005917e32f09136fa43018f471267f5bd
which mentions the vp.merge cost should be updated.



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