On 2/15/25 12:32 PM, Keith Packard wrote:
It's as reasonable as other methods such as turning it into a
define_expand and emitting a conditional branch around the sequence when
the count is zero.
Thanks much. I suspect the cost of the PSW setting instructions is far
less than a branch, so how about this version which emits them only when
the length is unknown and skips the instruction entirely when the length
is known to be zero?
I don't know anything about the micro-arch of the RX chip, so no clue
which is likely faster. Things like an explicit PSW write may be
pipeline flushes on some designs -- which could be insanely painful.
This replaces the previous patch because it is easier to understand; if
this looks correct, I'll submit it as a patch on top of the previous
one. This also passes my picolibc CI tests.
diff --git a/gcc/config/rx/rx.md b/gcc/config/rx/rx.md
index 89211585c9c..d2424ca395e 100644
--- a/gcc/config/rx/rx.md
+++ b/gcc/config/rx/rx.md
@@ -2545,6 +2545,16 @@ (define_expand "cmpstrnsi"
(match_operand:SI 4 "immediate_operand")] ;;
Known Align
"rx_allow_string_insns"
{
+ bool const_len = CONST_INT_P(operands[3]);
+ if (const_len)
+ {
+ if (INTVAL(operands[3]) == 0)
Note that operand 3's predict is "register_operand", so I would be
surprised to see a CONST_INT node show up in that operand. There are
some cases where we bypass those checks, so I'm not saying it can't
happen, just that I'd be surprised if it does. Seems like it'd be worth
double checking.
If you are indeed able to get a CONST_INT node, then something like your
patch is basically sensible. For comparisons against zero and a few
other special nodes we use CONST0_RTX (mode).
operands[3] != CONST0_RTX (mode)
Looking at the expander it copies operands[3] into "len" where "len" is
always an SImode register. So the test should be:
operands[3] != CONST0_RTX (SImode);
It's a nit in this context but in others that form will work better.
BUt I'd really like to get a confirmation that we can get a CONST_INT
node in here before installing.
If you can't trigger it, you could always change the predicate from
"register_operand" to something that also allows constants. Then you
just need to be sure that you can directly copy an arbitrary constant
into a physical register. I don't know the RX well enough to know if
that's possible or not.
Jeff