public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Roger Sayle" <roger@nextmovesoftware.com>
To: "'GCC Patches'" <gcc-patches@gcc.gnu.org>
Cc: "'Jeff Law'" <jeffreyalaw@gmail.com>
Subject: [Committed] Update xstormy16's neghi2 pattern to not clobber the carry flag.
Date: Sun, 30 Apr 2023 23:53:46 +0100	[thread overview]
Message-ID: <001901d97bb6$a001ff10$e005fd30$@nextmovesoftware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1113 bytes --]


When I converted xstormy16'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.
This patch has been tested by building a cross compiler to xstormy16-elf
from x86_64-pc-linux-gnu.  Committed as obvious (in hindsight).


2023-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.

Sorry for any inconvenience.
Roger
--


[-- Attachment #2: patchxs.txt --]
[-- Type: text/plain, Size: 1064 bytes --]

diff --git a/gcc/config/stormy16/stormy16.md b/gcc/config/stormy16/stormy16.md
index be1ee04..91e4bb1 100644
--- a/gcc/config/stormy16/stormy16.md
+++ b/gcc/config/stormy16/stormy16.md
@@ -519,11 +519,10 @@
 ;; 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
 ;; ::::::::::::::::::::
diff --git a/gcc/testsuite/gcc.target/xstormy16/neghi2.c b/gcc/testsuite/gcc.target/xstormy16/neghi2.c
index dd3dd1e..101c6da 100644
--- a/gcc/testsuite/gcc.target/xstormy16/neghi2.c
+++ b/gcc/testsuite/gcc.target/xstormy16/neghi2.c
@@ -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" } } */

                 reply	other threads:[~2023-04-30 22:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='001901d97bb6$a001ff10$e005fd30$@nextmovesoftware.com' \
    --to=roger@nextmovesoftware.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).