Neil Henning via llvm-dev
2020-Jan-17 16:22 UTC
[llvm-dev] Help with SROA throwing away no-alias information
I'm having an issue where SROA will throw away no-alias information on some
loads after inlining, because the loads are derived from a store to an
alloca which can be removed after inlining.
The pointers that were originally stored into the alloca do *not *have any
aliasing information - the only context that allowed me to assert aliasing
was that the inlined-function guaranteed it to be so.
I know why SROA has done this - its just removing a store -> load on an
alloca by forwarding the store, but is there anyway I can preserve the
information that these pointers must no-alias?
Here is the pre/post from when SROA is run and you can see the now missing
information of no-alias:
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%var.0 = alloca %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
align 8
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0,
i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to
i64*
store i64 %1, i64* %5, align 8
%.fca.1.gep = getelementptr inbounds
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%6 = bitcast i32** %.fca.1.gep to i64*
store i64 %4, i64* %6, align 8
%7 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to
i8**
%8 = load i8*, i8** %7, align 1, !alias.scope !2, !noalias !5
%9 = getelementptr %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%10 = bitcast i32** %9 to i8**
%11 = load i8*, i8** %10, align 1, !alias.scope !5, !noalias !2
call void @llvm.ubaa.expect.no.alias(i8* %8, i64 -1, i8* %11, i64 -1,
metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
*** IR Dump After SROA ***
; Function Attrs: nounwind
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0,
i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = inttoptr i64 %1 to i8*
%6 = inttoptr i64 %4 to i8*
call void @llvm.ubaa.expect.no.alias(i8* %5, i64 -1, i8* %6, i64 -1,
metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
My only workaround I can dream up locally is to run a pass before SROA to
do the alias.scope and noalias forwarding myself by looking back through
the store...
Cheers,
-Neil.
--
Neil Henning
Senior Software Engineer Compiler
unity.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20200117/d52c58da/attachment-0001.html>
Doerfert, Johannes via llvm-dev
2020-Jan-17 19:02 UTC
[llvm-dev] Help with SROA throwing away no-alias information
Hi Neil,
I don't know what `llvm.ubaa` is but maybe you can use of `llvm.assume`
here if it is just about keeping the load alive without impacting too
many passes. If we make the change described here [0] (we have patches
as well) you can write:
%l = load ... noalias ...
call llvm.assume(i1 true) ['keep_alive'(%l)]
or maybe also something like:
call llvm.assume(i1 true) ['no-alias'(%a, %b)]
I hope this helps,
Johannes
[0] lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html
---------------------------------------
Johannes Doerfert
Researcher
Argonne National Laboratory
Lemont, IL 60439, USA
jdoerfert at anl.gov
________________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Neil
Henning via llvm-dev <llvm-dev at lists.llvm.org>
Sent: Friday, January 17, 2020 10:22
To: llvm-dev
Subject: [llvm-dev] Help with SROA throwing away no-alias information
I'm having an issue where SROA will throw away no-alias information on some
loads after inlining, because the loads are derived from a store to an alloca
which can be removed after inlining.
The pointers that were originally stored into the alloca do not have any
aliasing information - the only context that allowed me to assert aliasing was
that the inlined-function guaranteed it to be so.
I know why SROA has done this - its just removing a store -> load on an
alloca by forwarding the store, but is there anyway I can preserve the
information that these pointers must no-alias?
Here is the pre/post from when SROA is run and you can see the now missing
information of no-alias:
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%var.0 = alloca %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
align 8
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0, i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to i64*
store i64 %1, i64* %5, align 8
%.fca.1.gep = getelementptr inbounds
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%6 = bitcast i32** %.fca.1.gep to i64*
store i64 %4, i64* %6, align 8
%7 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to i8**
%8 = load i8*, i8** %7, align 1, !alias.scope !2, !noalias !5
%9 = getelementptr %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%10 = bitcast i32** %9 to i8**
%11 = load i8*, i8** %10, align 1, !alias.scope !5, !noalias !2
call void @llvm.ubaa.expect.no.alias(i8* %8, i64 -1, i8* %11, i64 -1, metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
*** IR Dump After SROA ***
; Function Attrs: nounwind
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0, i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = inttoptr i64 %1 to i8*
%6 = inttoptr i64 %4 to i8*
call void @llvm.ubaa.expect.no.alias(i8* %5, i64 -1, i8* %6, i64 -1, metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
My only workaround I can dream up locally is to run a pass before SROA to do the
alias.scope and noalias forwarding myself by looking back through the store...
Cheers,
-Neil.
--
[https://unity3d.com/profiles/unity3d/themes/unity/images/ui/other/unity-logo-dark-email.png]
Neil Henning
Senior Software Engineer Compiler
unity.com<http://unity.com>
Jeroen Dobbelaere via llvm-dev
2020-Jan-20 08:09 UTC
[llvm-dev] Help with SROA throwing away no-alias information
Hi Neil,
This should be solved with the 'full restrict patches'
https://reviews.llvm.org/D68484 : it treats %noalias arguments in a different
way so that we keep more accurate information during SROA.
A convenience single patch is available here: https://reviews.llvm.org/D69542
Please let me know, if you happen to try it out, that it indeed solves your
problem.
Thanks,
Jeroen Dobbelaere
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Neil
Henning via llvm-dev
Sent: Friday, January 17, 2020 17:22
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [llvm-dev] Help with SROA throwing away no-alias information
I'm having an issue where SROA will throw away no-alias information on some
loads after inlining, because the loads are derived from a store to an alloca
which can be removed after inlining.
The pointers that were originally stored into the alloca do not have any
aliasing information - the only context that allowed me to assert aliasing was
that the inlined-function guaranteed it to be so.
I know why SROA has done this - its just removing a store -> load on an
alloca by forwarding the store, but is there anyway I can preserve the
information that these pointers must no-alias?
Here is the pre/post from when SROA is run and you can see the now missing
information of no-alias:
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%var.0 = alloca %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
align 8
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0, i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to i64*
store i64 %1, i64* %5, align 8
%.fca.1.gep = getelementptr inbounds
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%6 = bitcast i32** %.fca.1.gep to i64*
store i64 %4, i64* %6, align 8
%7 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"*
%var.0 to i8**
%8 = load i8*, i8** %7, align 1, !alias.scope !2, !noalias !5
%9 = getelementptr %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1
%10 = bitcast i32** %9 to i8**
%11 = load i8*, i8** %10, align 1, !alias.scope !5, !noalias !2
call void @llvm.ubaa.expect.no.alias(i8* %8, i64 -1, i8* %11, i64 -1, metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
*** IR Dump After SROA ***
; Function Attrs: nounwind
define dllexport void
@"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref
Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct
s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"*
nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 {
entry:
%0 = bitcast
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to
i64*
%1 = load i64, i64* %0, align 1
%2 = getelementptr
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct",
%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64
0, i32 1
%3 = bitcast i8** %2 to i64*
%4 = load i64, i64* %3, align 1
%5 = inttoptr i64 %1 to i8*
%6 = inttoptr i64 %4 to i8*
call void @llvm.ubaa.expect.no.alias(i8* %5, i64 -1, i8* %6, i64 -1, metadata
!"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9):
") #0
ret void
}
My only workaround I can dream up locally is to run a pass before SROA to do the
alias.scope and noalias forwarding myself by looking back through the store...
Cheers,
-Neil.
--
[Image removed by sender.]
Neil Henning
Senior Software Engineer Compiler
unity.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__unity.com&d=DwMFaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=ELyOnT0WepII6UnFk-OSzxlGOXXSfAvOLT6E8iPwwJk&m=GSznZd2GUUZ6h5fLXYaTzhCHJwxEUo_GmtRYcMlOqPE&s=LVQA9YOzUMXrvsXSngTfQjveFSvNuRSG_C0S27GAu1w&e=>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20200120/3edae1d1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 380 bytes
Desc: image001.jpg
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20200120/3edae1d1/attachment.jpg>
Neil Henning via llvm-dev
2020-Jan-20 11:01 UTC
[llvm-dev] Help with SROA throwing away no-alias information
Hey Jeroen, Ok cool - once I can work out how to apply that patch successfully without using ARC I'll give it a whirl (sidenote: oh how I lament not just being able to use github to pull the PR!). Cheers, -Neil. On Mon, Jan 20, 2020 at 8:09 AM Jeroen Dobbelaere < Jeroen.Dobbelaere at synopsys.com> wrote:> Hi Neil, > > > > This should be solved with the 'full restrict patches' > https://reviews.llvm.org/D68484 : it treats %noalias arguments in a > different > > way so that we keep more accurate information during SROA. > > A convenience single patch is available here: > https://reviews.llvm.org/D69542 > > > > Please let me know, if you happen to try it out, that it indeed solves > your problem. > > > > Thanks, > > > > Jeroen Dobbelaere > > > > > > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *Neil > Henning via llvm-dev > *Sent:* Friday, January 17, 2020 17:22 > *To:* llvm-dev <llvm-dev at lists.llvm.org> > *Subject:* [llvm-dev] Help with SROA throwing away no-alias information > > > > I'm having an issue where SROA will throw away no-alias information on > some loads after inlining, because the loads are derived from a store to an > alloca which can be removed after inlining. > > > > The pointers that were originally stored into the alloca do * not *have > any aliasing information - the only context that allowed me to assert > aliasing was that the inlined-function guaranteed it to be so. > > > > I know why SROA has done this - its just removing a store -> load on an > alloca by forwarding the store, but is there anyway I can preserve the > information that these pointers must no-alias? > > > > Here is the pre/post from when SROA is run and you can see the now missing > information of no-alias: > > > > define dllexport void > @"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref > Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct > s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* > nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 { > entry: > %var.0 = alloca %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField", align 8 > %0 = bitcast > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to i64* > %1 = load i64, i64* %0, align 1 > %2 = getelementptr > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct", > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64 0, > i32 1 > %3 = bitcast i8** %2 to i64* > %4 = load i64, i64* %3, align 1 > %5 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0 to > i64* > store i64 %1, i64* %5, align 8 > %.fca.1.gep = getelementptr inbounds > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField", > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1 > %6 = bitcast i32** %.fca.1.gep to i64* > store i64 %4, i64* %6, align 8 > %7 = bitcast %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0 to > i8** > %8 = load i8*, i8** %7, align 1, !alias.scope !2, !noalias !5 > %9 = getelementptr %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField", > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasField"* %var.0, i64 0, i32 1 > %10 = bitcast i32** %9 to i8** > %11 = load i8*, i8** %10, align 1, !alias.scope !5, !noalias !2 > call void @llvm.ubaa.expect.no.alias(i8* %8, i64 -1, i8* %11, i64 -1, > metadata > !"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9): > ") #0 > ret void > } > *** IR Dump After SROA *** > ; Function Attrs: nounwind > define dllexport void > @"Burst.Compiler.IL.Tests.Aliasing.CheckInlinedFunctionPreservesAliasing(ref > Burst.Compiler.IL.Tests.Aliasing.NoAliasWithContentsStruct > s)_862A52BC559AC318"(%"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* > nocapture nonnull readonly %s) local_unnamed_addr #0 !ubaa. !1 { > entry: > %0 = bitcast > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s to i64* > %1 = load i64, i64* %0, align 1 > %2 = getelementptr > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct", > %"Burst.Compiler.IL.Tests.Aliasing/NoAliasWithContentsStruct"* %s, i64 0, > i32 1 > %3 = bitcast i8** %2 to i64* > %4 = load i64, i64* %3, align 1 > %5 = inttoptr i64 %1 to i8* > %6 = inttoptr i64 %4 to i8* > call void @llvm.ubaa.expect.no.alias(i8* %5, i64 -1, i8* %6, i64 -1, > metadata > !"C:\\Users\\NeilHenning\\Home\\burst\\src\\Burst.Compiler.IL.Tests\\Shared\\083-Aliasing.cs(229,9): > ") #0 > ret void > } > > > > My only workaround I can dream up locally is to run a pass before SROA to > do the alias.scope and noalias forwarding myself by looking back through > the store... > > > > Cheers, > > -Neil. > > > -- > > [image: Image removed by sender.] > > *Neil Henning* > > Senior Software Engineer Compiler > > unity.com > <https://urldefense.proofpoint.com/v2/url?u=http-3A__unity.com&d=DwMFaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=ELyOnT0WepII6UnFk-OSzxlGOXXSfAvOLT6E8iPwwJk&m=GSznZd2GUUZ6h5fLXYaTzhCHJwxEUo_GmtRYcMlOqPE&s=LVQA9YOzUMXrvsXSngTfQjveFSvNuRSG_C0S27GAu1w&e=> > > >-- Neil Henning Senior Software Engineer Compiler unity.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200120/a9c515db/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 380 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200120/a9c515db/attachment-0001.jpg>
Apparently Analagous Threads
- LLVM 11 and trunk selecting 4 wide instead of 8 wide loop vectorization for AVX-enabled target
- LLVM 11 and trunk selecting 4 wide instead of 8 wide loop vectorization for AVX-enabled target
- LLVM 11 and trunk selecting 4 wide instead of 8 wide loop vectorization for AVX-enabled target
- [LLVMdev] Alias analysis issue with structs on PPC
- RFC: SROA for method argument