Friedman, Eli via llvm-dev
2018-Apr-23 22:55 UTC
[llvm-dev] [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
Sorry, I was using a modified compiler, which by coincidence made the bug much easier to reproduce. In some rare cases, the compiler will use x30 as a general-purpose register; in that case, outlining breaks because the "ret" branches to the wrong address. Testcase (reproduce with "clang -O3 --target=aarch64-pc-linux-gnu -mllvm -enable-machine-outliner"): extern long g1; extern long g2; void foo() { register long *x asm("x27") = &g1; register long *y asm("x29") = &g1; register long *z asm("x30") = &g2; asm(""::"r"(x),"r"(y),"r"(z)); } void foo2() { register long *x asm("x27") = &g1; register long *y asm("x29") = &g1; register long *z asm("x30") = &g2; asm(""::"r"(x),"r"(y),"r"(z)); } void foo3() { register long *x asm("x27") = &g1; register long *y asm("x29") = &g1; register long *z asm("x30") = &g2; asm(""::"r"(x),"r"(y),"r"(z)); } -Eli On 4/23/2018 2:37 PM, Jessica Paquette wrote:> I just ran SPEC at -O3 with the outliner enabled for AArch64 and > didn’t get any failures on my end. Which flags did you use? I’m > curious about what’s going on here... > > I used -O3 -mllvm -enable-machine-outliner -arch arm64. > > - Jessica > >> On Apr 23, 2018, at 1:41 PM, Jessica Paquette <jpaquette at apple.com >> <mailto:jpaquette at apple.com>> wrote: >> >> Hi Eli, >> >>> I just tried some tests, and I'm seeing a bunch of failures on SPEC >>> at -O3; looks like mostly crashes at runtime. I can try to reduce >>> a testcase if you need it. >> If you could do that, that would be great. Our testing has been >> primarily for -Oz and -O2, so I haven’t looked at -O3 at all. >> >>> I don't think this is really the right approach. With LTO, you can >>> have a mix of functions, some of which are minsize, and some of >>> which are not. Or with profile info, we might want to outline only >>> cold code (I guess this isn't implemented yet, but potentially >>> future work). Tying whether we run the outliner to a command-line >>> flag restricts the possible uses; either the entire module gets >>> outlining, or none of it does. >> I’m worried that walking the entire list of functions in the module >> when nothing has the minsize attribute would incur unnecessary >> compile-time overhead. If that’s a reasonable thing to do though, I’m >> fine with that approach. It’d be a less invasive change, and would >> give us the desired LTO behaviour for free. >> >> - Jessica >> >> >>> On Apr 23, 2018, at 1:24 PM, Friedman, Eli <efriedma at codeaurora.org >>> <mailto:efriedma at codeaurora.org>> wrote: >>> >>> On 4/20/2018 7:06 PM, Jessica Paquette via llvm-dev wrote: >>>> We perform regular testing to ensure the outliner produces correct >>>> AArch64 code at -Oz. Tests include the LLVM test suite and standard >>>> external test suites such as SPEC. All tests compile and >>>> execute. We've also been making sure that the outliner produces >>>> debuggable code. Users are still guaranteed to have sane backtraces >>>> in the presence of outlined functions. >>>> >>>> Added exposure to various programs would help the outlining >>>> algorithm mature further. This, in turn, will help the overall >>>> outlining project. For example, there have been a few discussions >>>> on implementing an IR-level outlining pass [3, 4]. Ultimately, the >>>> goal is to create a shared outlining interface. This interface >>>> would allow the outliner to exist at any level of representation >>>> [4]. The general outlining algorithm will be part of the shared >>>> interface. Thus, in the spirit of incremental improvement, it makes >>>> sense to begin "stress-testing" it sooner than later. >>> >>> I just tried some tests, and I'm seeing a bunch of failures on SPEC >>> at -O3; looks like mostly crashes at runtime. I can try to reduce >>> a testcase if you need it. >>> >>>> >>>> There are a few patches necessary to facilitate this. They are >>>> available in the patches section of this email. I’ll summarize what >>>> they do here for the sake of discussion though. >>>> >>>> The first patch is one that teaches the backend about size >>>> optimization levels. This is comparable to what's done in the >>>> inliner. Today, the only way to tell if something is optimizing for >>>> size is by looking at function attributes. This is fine for >>>> function passes, but insufficient for module passes like the >>>> MachineOutliner. The function attribute approach forces the >>>> outliner to iterate over every function in the module before >>>> deciding to take action. If -Oz isn't passed in, then the outliner >>>> will not find any functions worth outlining from. This would incur >>>> unnecessary compile-time overhead. Thus, we decided the best course >>>> of action is to teach the backend about size options. >>> >>> I don't think this is really the right approach. With LTO, you can >>> have a mix of functions, some of which are minsize, and some of >>> which are not. Or with profile info, we might want to outline only >>> cold code (I guess this isn't implemented yet, but potentially >>> future work). Tying whether we run the outliner to a command-line >>> flag restricts the possible uses; either the entire module gets >>> outlining, or none of it does. >>> >>> In general, we've been moving away from global settings so we can >>> optimize more effectively in this sort of scenario. >>> >>> -Eli >>> -- >>> Employee of Qualcomm Innovation Center, Inc. >>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project >> >-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180423/8d7f7c96/attachment.html>
Jessica Paquette via llvm-dev
2018-Apr-24 20:39 UTC
[llvm-dev] [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
Thanks for reducing that for me! The outliner pulls out the following: OUTLINED_FUNCTION_0: // @OUTLINED_FUNCTION_0 .cfi_sections .debug_frame .cfi_startproc // %bb.0: adrp x29, g1 add x29, x29, :lo12:g1 adrp x30, g2 // This adrp shouldn’t have been outlined. ret It shouldn’t be pulling out that adrp. There’s a special case for arps in the outliner which hinged on the assumption that x30 wouldn’t be used in that way. I just finished writing a fix which I’ll have up shortly. - Jessica> On Apr 23, 2018, at 3:55 PM, Friedman, Eli <efriedma at codeaurora.org> wrote: > > Sorry, I was using a modified compiler, which by coincidence made the bug much easier to reproduce. > > In some rare cases, the compiler will use x30 as a general-purpose register; in that case, outlining breaks because the "ret" branches to the wrong address. Testcase (reproduce with "clang -O3 --target=aarch64-pc-linux-gnu -mllvm -enable-machine-outliner"): > > extern long g1; > extern long g2; > void foo() { > register long *x asm("x27") = &g1; > register long *y asm("x29") = &g1; > register long *z asm("x30") = &g2; > asm(""::"r"(x),"r"(y),"r"(z)); > } > void foo2() { > register long *x asm("x27") = &g1; > register long *y asm("x29") = &g1; > register long *z asm("x30") = &g2; > asm(""::"r"(x),"r"(y),"r"(z)); > } > void foo3() { > register long *x asm("x27") = &g1; > register long *y asm("x29") = &g1; > register long *z asm("x30") = &g2; > asm(""::"r"(x),"r"(y),"r"(z)); > } > > -Eli > > On 4/23/2018 2:37 PM, Jessica Paquette wrote: >> I just ran SPEC at -O3 with the outliner enabled for AArch64 and didn’t get any failures on my end. Which flags did you use? I’m curious about what’s going on here... >> >> I used -O3 -mllvm -enable-machine-outliner -arch arm64. >> >> - Jessica >> >>> On Apr 23, 2018, at 1:41 PM, Jessica Paquette <jpaquette at apple.com <mailto:jpaquette at apple.com>> wrote: >>> >>> Hi Eli, >>> >>>> I just tried some tests, and I'm seeing a bunch of failures on SPEC at -O3; looks like mostly crashes at runtime. I can try to reduce a testcase if you need it. >>> If you could do that, that would be great. Our testing has been primarily for -Oz and -O2, so I haven’t looked at -O3 at all. >>> >>>> I don't think this is really the right approach. With LTO, you can have a mix of functions, some of which are minsize, and some of which are not. Or with profile info, we might want to outline only cold code (I guess this isn't implemented yet, but potentially future work). Tying whether we run the outliner to a command-line flag restricts the possible uses; either the entire module gets outlining, or none of it does. >>> >>> I’m worried that walking the entire list of functions in the module when nothing has the minsize attribute would incur unnecessary compile-time overhead. If that’s a reasonable thing to do though, I’m fine with that approach. It’d be a less invasive change, and would give us the desired LTO behaviour for free. >>> >>> - Jessica >>> >>> >>>> On Apr 23, 2018, at 1:24 PM, Friedman, Eli <efriedma at codeaurora.org <mailto:efriedma at codeaurora.org>> wrote: >>>> >>>> On 4/20/2018 7:06 PM, Jessica Paquette via llvm-dev wrote: >>>>> We perform regular testing to ensure the outliner produces correct AArch64 code at -Oz. Tests include the LLVM test suite and standard external test suites such as SPEC. All tests compile and execute. We've also been making sure that the outliner produces debuggable code. Users are still guaranteed to have sane backtraces in the presence of outlined functions. >>>>> >>>>> Added exposure to various programs would help the outlining algorithm mature further. This, in turn, will help the overall outlining project. For example, there have been a few discussions on implementing an IR-level outlining pass [3, 4]. Ultimately, the goal is to create a shared outlining interface. This interface would allow the outliner to exist at any level of representation [4]. The general outlining algorithm will be part of the shared interface. Thus, in the spirit of incremental improvement, it makes sense to begin "stress-testing" it sooner than later. >>>> >>>> I just tried some tests, and I'm seeing a bunch of failures on SPEC at -O3; looks like mostly crashes at runtime. I can try to reduce a testcase if you need it. >>>> >>>>> >>>>> There are a few patches necessary to facilitate this. They are available in the patches section of this email. I’ll summarize what they do here for the sake of discussion though. >>>>> >>>>> The first patch is one that teaches the backend about size optimization levels. This is comparable to what's done in the inliner. Today, the only way to tell if something is optimizing for size is by looking at function attributes. This is fine for function passes, but insufficient for module passes like the MachineOutliner. The function attribute approach forces the outliner to iterate over every function in the module before deciding to take action. If -Oz isn't passed in, then the outliner will not find any functions worth outlining from. This would incur unnecessary compile-time overhead. Thus, we decided the best course of action is to teach the backend about size options. >>>> >>>> I don't think this is really the right approach. With LTO, you can have a mix of functions, some of which are minsize, and some of which are not. Or with profile info, we might want to outline only cold code (I guess this isn't implemented yet, but potentially future work). Tying whether we run the outliner to a command-line flag restricts the possible uses; either the entire module gets outlining, or none of it does. >>>> >>>> In general, we've been moving away from global settings so we can optimize more effectively in this sort of scenario. >>>> >>>> -Eli >>>> -- >>>> Employee of Qualcomm Innovation Center, Inc. >>>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project >>> >> > > -- > Employee of Qualcomm Innovation Center, Inc. > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180424/4d4bd5e9/attachment.html>
David Green via llvm-dev
2018-Apr-25 12:02 UTC
[llvm-dev] [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
Hello A 4.4% geomean codesize improvement is really impressive. That stuff is hard to come by, you usually have to nibble away at it bit at a time. I ran some codesize benchmarks we have and they were in the same ballpark. Some of these are quite small so had less opportunity for outlining, but the average was still over 3% with some as high as 9-10%. All the tests I ran were fine, although we don't have a lot of -Oz AArch64 testing. Thanks for working on this, we'll have to see about getting it working for Arm code too! Dave
Reasonably Related Threads
- [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
- [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
- [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
- [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz
- [RFC] Turn the MachineOutliner on by default in AArch64 under -Oz