Skip to content

Commit ad44519

Browse files
committed
rx: avoid adding setpsw for rx_cmpstrn when len is const
The only pattern for which the len may be zero is cmpstrsni. The other pattern using rx_cmpstrn is cmpstrsi for which len is a constant -1, so we'll be moving the setpsw instructions from rx_cmpstrn to cmpstrnsi as follows: 1. Adjust the predicate on the length operand from "register_operand" to "nonmemory_operand". This will allow constants to appear here, instead of having them already transferred into a register. 2. Check to see if the len value is constant, and then check if it is actually zero. In that case, short-circuit the rest of the pattern and set the result register to 0. 3. Emit 'setpsw c' and 'setpsw z' instructions when the len is not a constant, in case it turns out to be zero at runtime. 4. Remove the two 'setpsw' instructions from rx_cmpstrn. Signed-off-by: Keith Packard <[email protected]>
1 parent 64dece3 commit ad44519

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

gcc/config/rx/rx.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,10 +2541,20 @@
25412541
(unspec_volatile:SI [(match_operand:BLK 1 "memory_operand") ;; String1
25422542
(match_operand:BLK 2 "memory_operand")] ;; String2
25432543
UNSPEC_CMPSTRN))
2544-
(use (match_operand:SI 3 "register_operand")) ;; Max Length
2544+
(use (match_operand:SI 3 "nonmemory_operand")) ;; Max Length
25452545
(match_operand:SI 4 "immediate_operand")] ;; Known Align
25462546
"rx_allow_string_insns"
25472547
{
2548+
bool const_len = CONST_INT_P(operands[3]);
2549+
if (const_len)
2550+
{
2551+
if (INTVAL(operands[3]) == 0)
2552+
{
2553+
emit_move_insn (operands[0], GEN_INT(0));
2554+
DONE;
2555+
}
2556+
}
2557+
25482558
rtx str1 = gen_rtx_REG (SImode, 1);
25492559
rtx str2 = gen_rtx_REG (SImode, 2);
25502560
rtx len = gen_rtx_REG (SImode, 3);
@@ -2553,6 +2563,11 @@
25532563
emit_move_insn (str2, force_operand (XEXP (operands[2], 0), NULL_RTX));
25542564
emit_move_insn (len, operands[3]);
25552565

2566+
/* Set flags in case len is zero */
2567+
if (!const_len) {
2568+
emit_insn (gen_setpsw (GEN_INT('C')));
2569+
emit_insn (gen_setpsw (GEN_INT('Z')));
2570+
}
25562571
emit_insn (gen_rx_cmpstrn (operands[0], operands[1], operands[2]));
25572572
DONE;
25582573
}
@@ -2590,9 +2605,7 @@
25902605
(clobber (reg:SI 3))
25912606
(clobber (reg:CC CC_REG))]
25922607
"rx_allow_string_insns"
2593-
"setpsw z ; Set flags in case len is zero
2594-
setpsw c
2595-
scmpu ; Perform the string comparison
2608+
"scmpu ; Perform the string comparison
25962609
mov #-1, %0 ; Set up -1 result (which cannot be created
25972610
; by the SC insn)
25982611
bnc ?+ ; If Carry is not set skip over

0 commit comments

Comments
 (0)