[PATCH] D140192: [InstCombine] Preserve instruction name in replaceInstUsesWith()

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 00:49:28 PST 2022


nikic created this revision.
nikic added reviewers: spatel, craig.topper, RKSimon.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D140192

Files:
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/test/Transforms/InstCombine/minmax-fold.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140192.483451.patch
Type: text/x-patch
Size: 39297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221216/810dfdf7/attachment.bin>


More information about the llvm-commits mailing list