aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg-Johann Lay <avr@gjlay.de>2024-05-07 19:39:55 +0200
committerGeorg-Johann Lay <avr@gjlay.de>2024-05-08 10:40:41 +0200
commitc8f4bbb824fafecf021a802324cd79e64b03b947 (patch)
tree5b88099000c333f5900942998025d384f293b3e4
parent245a6d478aba6499d1f649e4d35df1e858c5967c (diff)
downloadgcc-c8f4bbb824fafecf021a802324cd79e64b03b947.zip
gcc-c8f4bbb824fafecf021a802324cd79e64b03b947.tar.gz
gcc-c8f4bbb824fafecf021a802324cd79e64b03b947.tar.bz2
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.
-rw-r--r--gcc/config/avr/avr.md13
-rw-r--r--gcc/testsuite/gcc.target/avr/pr114975-popcount.c17
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md
index 97f42be..36fe384 100644
--- a/gcc/config/avr/avr.md
+++ b/gcc/config/avr/avr.md
@@ -8527,6 +8527,19 @@
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 0000000..87eb56b
--- /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 } } */