From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 63CD63857C5C; Fri, 14 Aug 2020 19:58:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63CD63857C5C From: "agentzh at gmail dot com" 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 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: systemtap X-Bugzilla-Component: translator X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: agentzh at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: systemtap at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: systemtap@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Systemtap mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Aug 2020 19:58:52 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D26392 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=3D12773&action=3Ded= it 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 =3D=3D 1) next; println("=3D= =3D=3D=3D=3D 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 =3D=3D= 1)` check: ```C (void) ({ ({ =20=20=20=20=20=20=20 c->locals[c->nesting+1].function___global_ubacktrace__overload_0.__retvalue= =3D &l->__tmp0[0]; =20=20=20=20=20=20=20 c->locals[c->nesting+1].function___global_ubacktrace__overload_0.__cur_fram= e =3D "\011: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->__tm= p0, MAXSTRINGLEN); l->__tmp0; }); if ((((global(s___global_a)) =3D=3D (((int64_t)1LL))))) { goto out; } ``` Disabling the optimizations make this issue go away: ``` if ((((global(s___global_a)) =3D=3D (((int64_t)1LL))))) { c->actionremaining -=3D 1; if (unlikely (c->actionremaining <=3D 0)) { c->last_error =3D "MAXACTION exceeded"; c->last_stmt =3D "keyword at :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 =3D 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. --=20 You are receiving this mail because: You are the assignee for the bug.=