The SCMPU instruction doesn't change the C and Z flags when the
incoming length is zero, which means the insn will produce a
value based upon the existing flag values.

As a quick kludge, adjust these flags to ensure a zero result in this
case.

Signed-off-by: Keith Packard <kei...@keithp.com>
---
 gcc/config/rx/rx.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rx/rx.md b/gcc/config/rx/rx.md
index 89211585c9c..edb2c96603f 100644
--- a/gcc/config/rx/rx.md
+++ b/gcc/config/rx/rx.md
@@ -2590,7 +2590,9 @@ (define_insn "rx_cmpstrn"
    (clobber (reg:SI 3))
    (clobber (reg:CC CC_REG))]
   "rx_allow_string_insns"
-  "scmpu               ; Perform the string comparison
+  "setpsw  z           ; Set flags in case len is zero
+   setpsw  c
+   scmpu               ; Perform the string comparison
    mov     #-1, %0      ; Set up -1 result (which cannot be created
                         ; by the SC insn)
    bnc    ?+           ; If Carry is not set skip over
-- 
2.47.2

Reply via email to