After
r14-673-gc0dd80e4c4c3, there was a check in the match
patterns which was checking the type is unsigned but
instead of using the type, the patch used the expression.
This adds the needed TREE_TYPE so get the correct answer and don't ICE.
Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
PR tree-optimization/109834
gcc/ChangeLog:
* match.pd (popcount(bswap(x))->popcount(x)): Fix up unsigned type checking.
(popcount(rotate(x,y))->popcount(x)): Likewise.
gcc/testsuite/ChangeLog:
* gcc.c-torture/compile/pr109834-1.c: New test.
* gcc.dg/tree-ssa/pr109834-1.c: New test.
&& INTEGRAL_TYPE_P (TREE_TYPE (@1)))
(with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0));
unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); }
- (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1)))
+ (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1))))
(popcount @2)))))))
/* popcount(rotate(X Y)) is popcount(X). */
&& (GIMPLE || !TREE_SIDE_EFFECTS (@3)))
(with { unsigned int prec0 = TYPE_PRECISION (TREE_TYPE (@0));
unsigned int prec1 = TYPE_PRECISION (TREE_TYPE (@1)); }
- (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (@1)))
+ (if (prec0 == prec1 || (prec0 > prec1 && TYPE_UNSIGNED (TREE_TYPE (@1))))
(popcount @2)))))))
/* Canonicalize POPCOUNT(x)&1 as PARITY(X). */
--- /dev/null
+int f (char v)
+{
+ return __builtin_popcount((int)__builtin_bswap16(v));
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f (char v)
+{
+ return __builtin_popcount((int)__builtin_bswap16(v));
+}
+
+/* We should be able to remove the bswap here as it does not matter
+ for the popcount. */
+/* { dg-final { scan-tree-dump-not "bswap" "optimized"} } */