public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: "agentzh at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: systemtap@sourceware.org
Subject: [Bug translator/26392] New: The optimizer would generate inefficient code which always evaluate dwarf ops eagerly
Date: Fri, 14 Aug 2020 19:58:52 +0000	[thread overview]
Message-ID: <bug-26392-6586@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=26392

            Bug ID: 26392
           Summary: The optimizer would generate inefficient code which
                    always evaluate dwarf ops eagerly
           Product: systemtap
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: translator
          Assignee: systemtap at sourceware dot org
          Reporter: agentzh at gmail dot com
  Target Milestone: ---

Created attachment 12773
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12773&action=edit
bad case using the default optimized translator and good case without
optimization

Consider the following example:

```
stap -e 'global a; probe process.begin { if (a == 1) next; println("===== aa")
println(ubacktrace()) }'
```

Regardless the value of the global variable `a`, the generated C code always
evaluates the value of `ubacktrace()` eagerly even before the `if (a == 1)`
check:

```C
    (void)
    ({
      ({
       
c->locals[c->nesting+1].function___global_ubacktrace__overload_0.__retvalue =
&l->__tmp0[0];
       
c->locals[c->nesting+1].function___global_ubacktrace__overload_0.__cur_frame =
          "\011<input>:1:79 in probe process.begin\012";
        function___global_ubacktrace__overload_0 (c);
        if (unlikely(c->last_error || c->aborted)) goto out;
        (void) 0;
      });
      strlcpy (l->l___stable___global_ubacktrace__overload_0_value, l->__tmp0,
MAXSTRINGLEN);
      l->__tmp0;
    });

    if ((((global(s___global_a)) == (((int64_t)1LL))))) {
      goto out;
    }
```

Disabling the optimizations make this issue go away:

```
    if ((((global(s___global_a)) == (((int64_t)1LL))))) {
      c->actionremaining -= 1;
      if (unlikely (c->actionremaining <= 0)) {
        c->last_error = "MAXACTION exceeded";
        c->last_stmt = "keyword at <input>:1:45";
        goto out;
      }
      goto out;
    }

...

    (void)
    ({
      strlcpy (l->__tmp2,
      ({
        function___global_ubacktrace__overload_0 (c);
        if (unlikely(c->last_error || c->aborted)) goto out;
        strlcpy (l->__tmp3,
c->locals[c->nesting+1].function___global_ubacktrace__overload_0.__retvalue,
MAXSTRINGLEN);
        l->__tmp3;
      }), MAXSTRINGLEN);
      #ifndef STP_LEGACY_PRINT
        c->printf_locals.stp_printf_1.arg0 = l->__tmp2;
        stp_printf_1 (c);
      #else // STP_LEGACY_PRINT
        _stp_printf ("%s\n", l->__tmp2);
      #endif // STP_LEGACY_PRINT
      if (unlikely(c->last_error || c->aborted)) goto out;
      ((int64_t)0LL);
    });
```

Seems like an optimization doing code moving is just too aggressive.

I've tested the latest git master version on my side (commit f70d74ef66952).

I've attached the two cases' C files (by -p3) for the reference.

-- 
You are receiving this mail because:
You are the assignee for the bug.

             reply	other threads:[~2020-08-14 19:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 19:58 agentzh at gmail dot com [this message]
2020-08-14 20:59 ` [Bug translator/26392] " agentzh at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-26392-6586@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).