[PATCH] D99240: [ConstantFolding] Look through local aliases when simplify GEPs
Reid Kleckner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 12 19:32:48 PDT 2021
rnk added a comment.
To add some specificity, we wouldn't want to go around ripping out all of our ??_7 vtable aliases and replacing them with references to the underlying private global. Consider:
@"??_7Foo@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @0, i32 0, i32 0, i32 1)
define dso_local nonnull %struct.Foo* @"??0Foo@@QEAA at XZ"(%struct.Foo* nonnull returned align 8 dereferenceable(8) %this) unnamed_addr #0 align 2 {
entry:
%0 = getelementptr inbounds %struct.Foo, %struct.Foo* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** @"??_7Foo@@6B@" to i32 (...)**), i32 (...)*** %0, align 8, !tbaa !3
ret %struct.Foo* %this
}
This compiles to:
"??0Foo@@QEAA at XZ": # @"??0Foo@@QEAA at XZ"
# %bb.0: # %entry
movq %rcx, %rax
leaq "??_7Foo@@6B@"(%rip), %rcx
movq %rcx, (%rax)
retq
If you do the replacement here:
define dso_local nonnull %struct.Foo* @"??0Foo@@QEAA at XZ"(%struct.Foo* nonnull returned align 8 dereferenceable(8) %this) unnamed_addr #0 align 2 {
entry:
%0 = getelementptr inbounds %struct.Foo, %struct.Foo* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @0, i32 0, i32 0, i32 1) to i32 (...)**), i32 (...)*** %0, align 8, !tbaa !3
ret %struct.Foo* %this
}
You get this code, which is less good:
"??0Foo@@QEAA at XZ": # @"??0Foo@@QEAA at XZ"
# %bb.0: # %entry
movq %rcx, %rax
leaq .L__unnamed_1+8(%rip), %rcx
movq %rcx, (%rax)
retq
That creates a relocation to the section instead of the symbol.
This alias happens to be external, so it wouldn't be stripped by this change, but even if it were internal, it's nicer to refer to the internal alias than the private symbol.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99240/new/
https://reviews.llvm.org/D99240
More information about the llvm-commits
mailing list