public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Is it a bug allowing to copy GIMPLE_ASM with labels?
@ 2018-12-29  7:22 Bin.Cheng
  2018-12-29  7:42 ` Alexander Monakov
  0 siblings, 1 reply; 4+ messages in thread
From: Bin.Cheng @ 2018-12-29  7:22 UTC (permalink / raw)
  To: GCC Development

Hi,
Give below test:

volatile int a, b, c;
__attribute__((noinline)) int foo ()
{
  int i;
  for (i = 0; i < 1000; i++)
    {
      if (i % 17)
        a++;
      else
        b++;
      asm volatile(
          "foo_label:\n"
          "pushq %%rbx\n"
          "popq %%rbx\n" :"=m"(c) :"r"(i)
      );
      c++;
    }
  return 0;
}
compiled with:
gcc -O2 -fno-crossjumping -ftracer tracer-1.c -o tracer-1.o -c
will end up with following assembler error message:
tracer-1.c: Assembler messages:
tracer-1.c:16: Error: symbol `foo_label' is already defined

Root cause is in tracer.c which duplicates basic block without
checking if any GIMPLE_ASM defines labels.
Is this a bug or invalid code?

Thanks,
bin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is it a bug allowing to copy GIMPLE_ASM with labels?
  2018-12-29  7:22 Is it a bug allowing to copy GIMPLE_ASM with labels? Bin.Cheng
@ 2018-12-29  7:42 ` Alexander Monakov
  2018-12-29  7:52   ` Bin.Cheng
  2018-12-29 14:41   ` Segher Boessenkool
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Monakov @ 2018-12-29  7:42 UTC (permalink / raw)
  To: Bin.Cheng; +Cc: GCC Development

On Sat, 29 Dec 2018, Bin.Cheng wrote:
> tracer-1.c: Assembler messages:
> tracer-1.c:16: Error: symbol `foo_label' is already defined
> 
> Root cause is in tracer.c which duplicates basic block without
> checking if any GIMPLE_ASM defines labels.
> Is this a bug or invalid code?

This is invalid code, GCC documentation is clear that the compiler
may duplicate inline asm statements (passes other than tracer can do
that too, loop unswitching just to give one example).

We don't provide a way to write an asm that wouldn't be duplicated.

Alexander

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is it a bug allowing to copy GIMPLE_ASM with labels?
  2018-12-29  7:42 ` Alexander Monakov
@ 2018-12-29  7:52   ` Bin.Cheng
  2018-12-29 14:41   ` Segher Boessenkool
  1 sibling, 0 replies; 4+ messages in thread
From: Bin.Cheng @ 2018-12-29  7:52 UTC (permalink / raw)
  To: amonakov; +Cc: GCC Development

On Sat, Dec 29, 2018 at 3:42 PM Alexander Monakov <amonakov@ispras.ru> wrote:
>
> On Sat, 29 Dec 2018, Bin.Cheng wrote:
> > tracer-1.c: Assembler messages:
> > tracer-1.c:16: Error: symbol `foo_label' is already defined
> >
> > Root cause is in tracer.c which duplicates basic block without
> > checking if any GIMPLE_ASM defines labels.
> > Is this a bug or invalid code?
>
> This is invalid code, GCC documentation is clear that the compiler
> may duplicate inline asm statements (passes other than tracer can do
> that too, loop unswitching just to give one example).
>
> We don't provide a way to write an asm that wouldn't be duplicated.
I see, thanks for elaboration.

Thanks,
bin
>
> Alexander

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Is it a bug allowing to copy GIMPLE_ASM with labels?
  2018-12-29  7:42 ` Alexander Monakov
  2018-12-29  7:52   ` Bin.Cheng
@ 2018-12-29 14:41   ` Segher Boessenkool
  1 sibling, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2018-12-29 14:41 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: Bin.Cheng, GCC Development

Hi!

On Sat, Dec 29, 2018 at 10:41:54AM +0300, Alexander Monakov wrote:
> On Sat, 29 Dec 2018, Bin.Cheng wrote:
> > tracer-1.c: Assembler messages:
> > tracer-1.c:16: Error: symbol `foo_label' is already defined
> > 
> > Root cause is in tracer.c which duplicates basic block without
> > checking if any GIMPLE_ASM defines labels.
> > Is this a bug or invalid code?
> 
> This is invalid code, GCC documentation is clear that the compiler
> may duplicate inline asm statements (passes other than tracer can do
> that too, loop unswitching just to give one example).
> 
> We don't provide a way to write an asm that wouldn't be duplicated.

But should there be?  Is there (valid!) code for which it would be more
convenient?

We already have a hook targetm.cannot_copy_insn_p with which targets can
say not to copy certain insns.  It will be trivial to do something like
that for "asm restrict" (or whatever is a better name :-) ) (so make some
cannot_copy_insn_p that for asm checks that flag, and for everything else
uses the hook...  something like that).


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-29 14:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-29  7:22 Is it a bug allowing to copy GIMPLE_ASM with labels? Bin.Cheng
2018-12-29  7:42 ` Alexander Monakov
2018-12-29  7:52   ` Bin.Cheng
2018-12-29 14:41   ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).