[PATCH] D117092: [GlobalOpt] Use generic type when converting malloc to global

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 01:18:49 PST 2022


nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added subscribers: ormris, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The malloc to global transform currently determines the type of the global by looking at bitcasts of the malloc. This is limited (the transform fails if there are multiple different types) and incompatible with opaque pointers.

My initial approach was to construct an appropriate struct type based on usage in loads/stores (and I can go back to that if desired). What this patch does instead is to always create an `[i8 x AllocSize]` global, without trying to guess types at all.

This does mean that other transforms that require a certain global type may break. I fixed one such case in D117034 <https://reviews.llvm.org/D117034>, which is the only one that came up in tests. From a philosophical perspective, I think that fixing transforms to not depend on global type is generally preferable.


https://reviews.llvm.org/D117092

Files:
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/test/Transforms/GlobalOpt/2021-08-03-StoreOnceLoadMultiCasts.ll
  llvm/test/Transforms/GlobalOpt/malloc-promote-opaque-ptr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117092.399244.patch
Type: text/x-patch
Size: 11740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/5136b844/attachment.bin>


More information about the llvm-commits mailing list