[PATCH] D117503: [GlobalOpt] Generalize malloc-to-global for any allocation function
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 17 09:58:25 PST 2022
reames created this revision.
reames added reviewers: nikic, lifted, Bryce-MW, durin42.
Herald added subscribers: ormris, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.
We can generalize the malloc-to-global transform for other allocation functions which are both a) removable, and b) have a known initialization value.
One subtlety that I want to point out - mostly because I hadn't realized it was true until I took a closer look - is that the existing code doesn't prove that initialization/malloc happens only once. The initialization function can be called multiple times. This is correct without special handling for malloc as undef can map to any value previously written, but a non-undef initializing allocation it means we may end up memseting the new global repeatedly. In particular, this means it's not legal to fold the memset into the initializer of the global.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117503
Files:
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/calloc-promote.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117503.400598.patch
Type: text/x-patch
Size: 8031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220117/a6847b51/attachment.bin>
More information about the llvm-commits
mailing list