[PATCH] D145854: [GlobalDCE] Don't add dependency via icmp against inbouds pointer
Ayke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 11 10:31:16 PST 2023
aykevl created this revision.
aykevl added reviewers: jdoerfert, sanjoy, hfinkel.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
aykevl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch optimizes the following case:
static int x;
bool foo(int *n) {
return &x == n;
}
To remove the static global that isn't otherwise used:
bool foo(int *n) {
return false;
}
This is not a valid optimization in C. However, there are cases where
this can be valid in other language if the pointer parameter n is known
to point into a valid object (either via the dereferenceable_or_null
attribute or an inbouds gep). The logic here is the same as for
https://reviews.llvm.org/D60047.
The motivator for this is runtime type information in TinyGo. There are
two ways type information globals are referenced: either by storing it
in an interface value, or by comparing the interface type against the
type information global. It is this second use (the comparison) that
leads to a significant code size increase of double digit percents in
some cases.
We currently work around this using a hack, but I'd like this to be
supported natively in LLVM so we can simplify the compiler and make use
of a normal LTO pipeline instead of our homegrown LTO variant.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145854
Files:
llvm/include/llvm/Analysis/TypeMetadataUtils.h
llvm/lib/Analysis/TypeMetadataUtils.cpp
llvm/lib/Transforms/IPO/GlobalDCE.cpp
llvm/test/Transforms/GlobalDCE/icmp.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145854.504385.patch
Type: text/x-patch
Size: 7840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230311/3421feb1/attachment.bin>
More information about the llvm-commits
mailing list