From: Kris Van Hees <kris.van.hees@oracle.com>
To: Eugene Loh <eugene.loh@oracle.com>
Cc: Kris Van Hees <kris.van.hees@oracle.com>,
dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [DTrace-devel] [PATCH 3/3] cg: optimize ternary expressions for strings
Date: Wed, 16 Jul 2025 01:32:10 -0400 [thread overview]
Message-ID: <aHc5WlAd3YLe4x6Y@oracle.com> (raw)
In-Reply-To: <57838fc8-1e04-2f10-4d4c-e4416aea10bd@oracle.com>
On Wed, Jul 16, 2025 at 01:00:43AM -0400, Eugene Loh wrote:
> Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
> subject to a few comments below.
>
> On 7/15/25 15:50, Kris Van Hees via DTrace-devel wrote:
>
> > If either size of a ternary expression has a tstring value, it can be
>
> s/size/side/
Thanks.
> > re-used to store the value of the ternary expression, reducing the
> > need for tstring allocation, especially in nested ternaries.
> >
> > diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> > @@ -222,7 +222,7 @@ typedef struct dt_kern_path {
> > * - cleanpath() holds a prepended '/' char, a string, an appended '/' char,
> > * and a terminating NUL char, or STRSZ + 3 chars altogether
> > */
> > -#define DT_TSTRING_SLOTS 4
> > +#define DT_TSTRING_SLOTS 6
>
> Same comment as I had for Alan's patch. The comment block before this goes
> into excruciating detail about why the value should be 4. Whether its logic
> is right or wrong, we cannot leave those old comments with a new value. Why
> is the value now 6?
Ah yes, I should have updated the explanation. It has become a little bit more
complicated but I can certainly explain it based on the example we have in the
testsuite.
>
> I assume 6 is not a "sufficient for all purposes" value. E.g., if I kick up
> the complexity on tst.tstring_ternary_nested.d, I get:
Correct - I hope to do a later patch that makes this something that adjusts
dynamically. But that is quite a bit more work.
>
> $ git diff
> diff --git a/test/unittest/codegen/tst.tstring_ternary_nested.d
> b/test/unittest/codegen/tst.tstring_ternary_nested.d
> @@ -16,6 +16,8 @@ BEGIN {
> trace(x > 1 ? strjoin(strjoin("a", "bc"), strjoin("de", "f")) :
> x > 2 ? strjoin(strjoin("A", "BC"), strjoin("DE", "F")) :
> x > 3 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
> + x > 4 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
> + x > 5 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
> strjoin(strjoin("U", "VW"), strjoin("XY", "Z")));
>
> exit(0);
> $ sudo ./runtest.sh test/unittest/codegen/tst.tstring_ternary_nested.d
> test/unittest/codegen/tst.tstring_ternary_nested.d: FAIL: core dumped.
> 1 cases (0 PASS, 1 FAIL, 0 XPASS, 0 XFAIL, 0 SKIP)
> $ cat test/log/current/runtest.log
> [...]
> dtrace: libdtrace/dt_cg.c:1472: dt_cg_tstring_xalloc: Assertion `i <
> DT_TSTRING_SLOTS' failed.
>
> > diff --git a/test/unittest/codegen/tst.tstring_ternary_nested.d b/test/unittest/codegen/tst.tstring_ternary_nested.d
> > @@ -0,0 +1,26 @@
> > +BEGIN {
> > + x = 42;
> > + trace(x > 1 ? strjoin(strjoin("a", "bc"), strjoin("de", "f")) :
> > + x > 2 ? strjoin(strjoin("A", "BC"), strjoin("DE", "F")) :
> > + x > 3 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
> > + strjoin(strjoin("U", "VW"), strjoin("XY", "Z")));
> > +
> > + exit(0);
> > +}
>
> I guess that's fine for cg, but the skeptic in me notices that the three
> tests all evaluate to true. I would think one could run through all 2x2x2=8
> cases in a single test for a little bit more rigor.
Since this is a codegen test, we only really care about the tstring allocation
aspect. There are already other tests that exercise the ternary itself.
prev parent reply other threads:[~2025-07-16 5:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 19:50 [PATCH 3/3] cg: optimize ternary expressions for strings Kris Van Hees
2025-07-16 5:00 ` [DTrace-devel] " Eugene Loh
2025-07-16 5:32 ` Kris Van Hees [this message]
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=aHc5WlAd3YLe4x6Y@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=eugene.loh@oracle.com \
/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