[cfe-dev] (not) initializing assembly outputs with -ftrivial-auto-var-init

Alexander Potapenko via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 21 07:02:11 PDT 2019


On Thu, Mar 21, 2019 at 2:42 PM JF Bastien <jfbastien at apple.com> wrote:
>
> Do the assembly routines set the constraints to indicate that they write to the input register? If so, we can do a simple dead store elimination change to notice that the assembly “call” changes the input.
The constraints allow us to figure out which variables are used as
outputs, but that doesn't necessarily mean these variables are
actually written to.

>From LLVM's point of view the statements:
  asm("mov %%rdi, %0" : "=m"(out));
and
  asm("" : "=m"(out));
don't differ much.

Therefore we can't let any analysis depend on the assembly
constraints, we can only use it as a signal (maybe under a flag).

> I think this will do what you want.
>
>
> > On Mar 21, 2019, at 5:35 AM, Alexander Potapenko <glider at google.com> wrote:
> >
> > Hi JF et al.,
> >
> > In the Linux kernel we often encounter the following pattern:
> >
> > type op(...) {
> >  type retval;
> >  inline asm(... retval ...);
> >  return retval;
> > }
> >
> > , which is used to implement low-level platform-dependent memory operations.
> >
> > Some of these operations turn out to be very hot, so we probably don't
> > want to initialize |retval| given that it's always initialized in the
> > assembly.
> >
> > However it's practically impossible to tell that a variable is being
> > written to by the inline assembly, or figure out the size of that
> > write.
> > Perhaps we could speculatively treat every scalar output of an inline
> > assembly routine as an initialized value (which is true for the Linux
> > kernel, but I'm not sure about other users of inline assembly, e.g.
> > video codecs).
> >
> > WDYT?
> >
> >
> > --
> > 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



-- 
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



More information about the cfe-dev mailing list