[InstCombine] Freeze other uses of frozen value
authorNikita Popov <npopov@redhat.com>
Tue, 10 May 2022 15:10:37 +0000 (17:10 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 11 May 2022 14:47:12 +0000 (16:47 +0200)
commit6001bfcedc3102b45878b7883c241b45863d7e2c
tree22d5663441e810c122ab665f3334189163fbeb81
parentcc0283a6358b4a97d8340da8d32ba23300ae9889
[InstCombine] Freeze other uses of frozen value

If there is a freeze %x, we currently replace all other uses of %x
with freeze %x -- as long as they are dominated by the freeze
instruction. This patch extends this behavior to cases where we
did not originally dominate the use by moving the freeze
instruction directly after the definition of the frozen value.

The motivation can be seen in test @combine_and_after_freezing_uses:
Canonicalizing everything to freeze %x allows folds that are based
on value identity (i.e. same operand occurring in two places) to
trigger. This also covers the case from D125248.

Differential Revision: https://reviews.llvm.org/D125321
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/freeze.ll
llvm/test/Transforms/InstCombine/onehot_merge.ll