[all-commits] [llvm/llvm-project] 379de1: [InstCombine] Preserve instruction name in replace...

Nikita Popov via All-commits all-commits at lists.llvm.org
Fri Dec 16 07:02:12 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 379de1239ee3eb17ca37035c069afcc1d5e04d27
      https://github.com/llvm/llvm-project/commit/379de1239ee3eb17ca37035c069afcc1d5e04d27
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2022-12-16 (Fri, 16 Dec 2022)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineInternal.h
    M llvm/test/Transforms/InstCombine/minmax-fold.ll

  Log Message:
  -----------
  [InstCombine] Preserve instruction name in replaceInstUsesWith()

Currently InstCombine folds using the
`return replaceInstUsesWith(V, Builder.CreateFoo())`
pattern do not preserve the original name of the instruction.
To preserve the name, you either have to use something like
`return FooInst::Create(...)` which is usually less nice, or go
out of the way to preserve the name with takeName(). We often
don't do that.

This patch instead preserves the name in replaceInstUsesWith()
when replacing a named instruction with an unnamed instruction.
To be conservative, I also added a zero-use check, which is a
proxy for the case where the instruction was just created, rather
than an existing one reused. Possibly we could drop that part.

As InstCombine tests are robust against renames this does not
cause any test diffs, so I regenerated a random test to show the
effects.

Differential Revision: https://reviews.llvm.org/D140192




More information about the All-commits mailing list