* [patch,avr] PR114975: Better 8-bit popcount detection.
@ 2024-05-07 17:25 Georg-Johann Lay
2024-05-07 20:36 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Georg-Johann Lay @ 2024-05-07 17:25 UTC (permalink / raw)
To: gcc-patches, Jeff Law
[-- 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 } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch,avr] PR114975: Better 8-bit popcount detection.
2024-05-07 17:25 [patch,avr] PR114975: Better 8-bit popcount detection Georg-Johann Lay
@ 2024-05-07 20:36 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2024-05-07 20:36 UTC (permalink / raw)
To: Georg-Johann Lay, gcc-patches
On 5/7/24 11:25 AM, Georg-Johann Lay wrote:
> 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.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-07 20:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-07 17:25 [patch,avr] PR114975: Better 8-bit popcount detection Georg-Johann Lay
2024-05-07 20:36 ` Jeff Law
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).