]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Committed] Update xstormy16's neghi2 pattern to not clobber the carry flag.
authorRoger Sayle <roger@nextmovesoftware.com>
Sun, 30 Apr 2023 22:47:13 +0000 (23:47 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Sun, 30 Apr 2023 22:47:13 +0000 (23:47 +0100)
When I converted xstormy's neghi2 pattern from a define_expand to a
define_insn, I forgot that define_expand implicitly produces a
sequence of instructions, but a define_insn is an implicit parallel,
thereby messing up the clobber (reg:BI CARRY_REG), which can then cause
an ICE in the auto-generated added_clobbers_hard_reg_p.  Whilst stripping
the superfluous PARALLEL resolves this issue, an even better fix is to
use xstormy16's INC instruction, that (like NOT) doesn't affect the carry
flag, resulting in a neghi2 implementation that can more easily be CSE'd
and scheduled.

Many thanks (again) to Jeff Law for testing/reporting this issue.

2024-04-30  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/stormy16/stormy16.md (neghi2): Rewrite pattern using
inc to avoid clobbering the carry flag.

gcc/testsuite/ChangeLog
* gcc.target/xstormy16/neghi2.c: Update expected implementation.

gcc/config/stormy16/stormy16.md
gcc/testsuite/gcc.target/xstormy16/neghi2.c

index be1ee04e5b58041def336d41960e78d6bf0e6434..91e4bb1cff7fdc94edb3941348a66d20ffecfc23 100644 (file)
 ;; Negation
 
 (define_insn "neghi2"
-  [(parallel [(set (match_operand:HI 0 "register_operand" "=r")
-                  (neg:HI (match_operand:HI 1 "register_operand" "0")))
-             (clobber (reg:BI CARRY_REG))])]
+  [(set (match_operand:HI 0 "register_operand" "=r")
+       (neg:HI (match_operand:HI 1 "register_operand" "0")))]
   ""
-  "not %0 | add %0,#1"
+  "not %0 | inc %0"
   [(set_attr "length" "4")])
 \f
 ;; ::::::::::::::::::::
index dd3dd1e60fb9be80df44e994a6f5a57188f69e03..101c6da279f898fb049cda7cc5ab6e9c7c784724 100644 (file)
@@ -5,4 +5,4 @@ short neg(short x)
 {
   return -x;
 }
-/* { dg-final { scan-assembler "not r2 | add r2,#1" } } */
+/* { dg-final { scan-assembler "not r2 | inc r2" } } */