Alexander Potapenko via llvm-dev
2019-Aug-01 14:21 UTC
[llvm-dev] Dead store elimination in the backend for -ftrivial-auto-var-init
Hi folks, When compiling the attached example with -ftrivial-auto-var-init=zero: $ clang -no-integrated-as -mno-sse -m64 -mstack-alignment=8 -O2 -ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -g -o ipt.ll -c ipt.i -w -S -emit-llvm , Clang generates an initialization memset() call for |acpar| in the IR: %0 = bitcast %struct.xt_action_param* %acpar to i8*, !dbg !27 call void @llvm.memset.p0i8.i64(i8* nonnull align 8 %0, i8 0, i64 40, i1 false), !dbg !28 Clang only splits memsets into series of stores under certain conditions, so it's hard to remove redundant stores on the IR level (even with the recent DSE patches: https://reviews.llvm.org/D61879). In the resulting assembly, however, the memset is lowered into a series of MOVQ instructions (see the attached ipt.s file), of which at least the stores to 24(%rsp) and 16(%rsp) are redundant. Given that at MCInst level we already know if a memset is split into a sequence of stores, can we do a better job by making the backend delete these redundant stores for us? Alex -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg -------------- next part -------------- A non-text attachment was scrubbed... Name: ipt.i Type: application/octet-stream Size: 461 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190801/b6398a44/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: ipt.s Type: application/octet-stream Size: 1880 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190801/b6398a44/attachment-0001.obj>
JF Bastien via llvm-dev
2019-Aug-01 16:08 UTC
[llvm-dev] Dead store elimination in the backend for -ftrivial-auto-var-init
Hi Alexander, The code doesn’t compile. Could you send a godbolt.org link that shows the issue? Thanks, JF> On Aug 1, 2019, at 7:21 AM, Alexander Potapenko <glider at google.com> wrote: > > Hi folks, > > When compiling the attached example with -ftrivial-auto-var-init=zero: > > $ clang -no-integrated-as -mno-sse -m64 -mstack-alignment=8 -O2 > -ftrivial-auto-var-init=zero > -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > -g -o ipt.ll -c ipt.i -w -S -emit-llvm > > , Clang generates an initialization memset() call for |acpar| in the IR: > > %0 = bitcast %struct.xt_action_param* %acpar to i8*, !dbg !27 > call void @llvm.memset.p0i8.i64(i8* nonnull align 8 %0, i8 0, i64 > 40, i1 false), !dbg !28 > > Clang only splits memsets into series of stores under certain > conditions, so it's hard to remove redundant stores on the IR level > (even with the recent DSE patches: https://reviews.llvm.org/D61879). > In the resulting assembly, however, the memset is lowered into a > series of MOVQ instructions (see the attached ipt.s file), of which at > least the stores to 24(%rsp) and 16(%rsp) are redundant. > > Given that at MCInst level we already know if a memset is split into a > sequence of stores, can we do a better job by making the backend > delete these redundant stores for us? > > Alex > > -- > Alexander Potapenko > Software Engineer > > Google Germany GmbH > Erika-Mann-Straße, 33 > 80636 München > > Geschäftsführer: Paul Manicle, Halimah DeLaine Prado > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > <ipt.i><ipt.s>
Alexander Potapenko via llvm-dev
2019-Aug-01 16:20 UTC
[llvm-dev] Dead store elimination in the backend for -ftrivial-auto-var-init
On Thu, Aug 1, 2019 at 6:09 PM JF Bastien <jfbastien at apple.com> wrote:> > Hi Alexander, > > The code doesn’t compile. Could you send a godbolt.org link that shows the issue?Sorry about that, here's the link: https://godbolt.org/z/-PinQP Lines 4 to 8 are initializing |acpar|. If I'm understanding correctly, the store to 8(%rsp) at line 7 can be removed because of the store at line 35. Same for store to 24(%rsp), which is later overwritten at lines 11 and 16.> Thanks, > > JF > > > On Aug 1, 2019, at 7:21 AM, Alexander Potapenko <glider at google.com> wrote: > > > > Hi folks, > > > > When compiling the attached example with -ftrivial-auto-var-init=zero: > > > > $ clang -no-integrated-as -mno-sse -m64 -mstack-alignment=8 -O2 > > -ftrivial-auto-var-init=zero > > -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > > -g -o ipt.ll -c ipt.i -w -S -emit-llvm > > > > , Clang generates an initialization memset() call for |acpar| in the IR: > > > > %0 = bitcast %struct.xt_action_param* %acpar to i8*, !dbg !27 > > call void @llvm.memset.p0i8.i64(i8* nonnull align 8 %0, i8 0, i64 > > 40, i1 false), !dbg !28 > > > > Clang only splits memsets into series of stores under certain > > conditions, so it's hard to remove redundant stores on the IR level > > (even with the recent DSE patches: https://reviews.llvm.org/D61879). > > In the resulting assembly, however, the memset is lowered into a > > series of MOVQ instructions (see the attached ipt.s file), of which at > > least the stores to 24(%rsp) and 16(%rsp) are redundant. > > > > Given that at MCInst level we already know if a memset is split into a > > sequence of stores, can we do a better job by making the backend > > delete these redundant stores for us? > > > > Alex > > > > -- > > Alexander Potapenko > > Software Engineer > > > > Google Germany GmbH > > Erika-Mann-Straße, 33 > > 80636 München > > > > Geschäftsführer: Paul Manicle, Halimah DeLaine Prado > > Registergericht und -nummer: Hamburg, HRB 86891 > > Sitz der Gesellschaft: Hamburg > > <ipt.i><ipt.s> >-- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Maybe Matching Threads
- Dead store elimination in the backend for -ftrivial-auto-var-init
- Dead store elimination in the backend for -ftrivial-auto-var-init
- Dead store elimination in the backend for -ftrivial-auto-var-init
- Interprocedural DSE for -ftrivial-auto-var-init
- Interprocedural DSE for -ftrivial-auto-var-init