[GlobalOpt] Support "stored once" optimization for different types
authorNikita Popov <npopov@redhat.com>
Tue, 11 Jan 2022 17:00:41 +0000 (18:00 +0100)
committerNikita Popov <npopov@redhat.com>
Wed, 12 Jan 2022 08:39:31 +0000 (09:39 +0100)
commitf3e87176e1c58da7b61958eae679adb4bcdb7c41
tree7c3699e7e8ee27d74823bc42472fa4116251f715
parentc4db521cea32fcfb714d1a622e0efce69a564a28
[GlobalOpt] Support "stored once" optimization for different types

GlobalOpt can optimize a global with undef initializer and a single
store to put the stored value into the initializer instead. Currently,
this requires the type of the global and the store to match.

This patch extends support to cases with different types (but same
size), in which case we create a new global to replace the old one.

Differential Revision: https://reviews.llvm.org/D117034
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/stored-once-different-type.ll [new file with mode: 0644]
llvm/test/Transforms/GlobalOpt/stored-once-value-type.ll