public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Jeff Law <jeffreyalaw@gmail.com>
Subject: [patch,avr] PR114975: Better 8-bit popcount detection.
Date: Tue, 7 May 2024 19:25:05 +0200	[thread overview]
Message-ID: <2676a5d7-678c-4879-a296-c9ce13c830d9@gjlay.de> (raw)

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

Add a pattern for better popcount detection.

Ok for master?

Johann

--

AVR: target/114975 - Add combine-pattern for __popcountqi2.

	PR target/114975
gcc/
	* config/avr/avr.md: Add combine pattern for
	8-bit popcount detection.

gcc/testsuite/
	* gcc.target/avr/pr114975-popcount.c: New test.

[-- Attachment #2: pr114975-popcount.diff --]
[-- Type: text/x-patch, Size: 1312 bytes --]

diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md
index 97f42be7729..d4fcff46123 100644
--- a/gcc/config/avr/avr.md
+++ b/gcc/config/avr/avr.md
@@ -8527,6 +8542,19 @@ (define_expand "popcountsi2"
     operands[2] = gen_reg_rtx (HImode);
   })
 
+(define_insn_and_split "*popcounthi2.split8"
+  [(set (reg:HI 24)
+        (zero_extend:HI (popcount:QI (match_operand:QI 0 "register_operand"))))]
+  "! reload_completed"
+  { gcc_unreachable(); }
+  "&& 1"
+  [(set (reg:QI 24)
+        (match_dup 0))
+   (set (reg:QI 24)
+        (popcount:QI (reg:QI 24)))
+   (set (reg:QI 25)
+        (const_int 0))])
+
 (define_insn_and_split "*popcounthi2.libgcc_split"
   [(set (reg:HI 24)
         (popcount:HI (reg:HI 24)))]
diff --git a/gcc/testsuite/gcc.target/avr/pr114975-popcount.c b/gcc/testsuite/gcc.target/avr/pr114975-popcount.c
new file mode 100644
index 00000000000..87eb56b56c5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/pr114975-popcount.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Os" } */
+
+typedef __UINT8_TYPE__ uint8_t;
+
+uint8_t use_pop1 (int y, uint8_t x)
+{
+    return 1 + __builtin_popcount (x);
+}
+
+uint8_t use_pop2 (uint8_t x)
+{
+	x += 1;
+    return 1 - __builtin_popcount (x);
+}
+
+/* { dg-final { scan-assembler-times "__popcountqi2" 2 } } */

             reply	other threads:[~2024-05-07 17:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07 17:25 Georg-Johann Lay [this message]
2024-05-07 20:36 ` Jeff Law

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=2676a5d7-678c-4879-a296-c9ce13c830d9@gjlay.de \
    --to=avr@gjlay.de \
    --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).