[all-commits] [llvm/llvm-project] 26049b: [GlobalOpt] Generalize malloc-to-global for any al...
Philip Reames via All-commits
all-commits at lists.llvm.org
Mon Jan 17 15:07:54 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 26049b8ce376a81acbaa0b4b86d7dcef1bc432bd
https://github.com/llvm/llvm-project/commit/26049b8ce376a81acbaa0b4b86d7dcef1bc432bd
Author: Philip Reames <listmail at philipreames.com>
Date: 2022-01-17 (Mon, 17 Jan 2022)
Changed paths:
M llvm/lib/Transforms/IPO/GlobalOpt.cpp
M llvm/test/Transforms/GlobalOpt/calloc-promote.ll
Log Message:
-----------
[GlobalOpt] Generalize malloc-to-global for any allocation function
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.
Differential Revision: https://reviews.llvm.org/D117503
More information about the All-commits
mailing list