aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-11-28 10:15:52 +0100
committerJakub Jelinek <jakub@redhat.com>2023-11-28 10:15:52 +0100
commitf1b03fa964527678f15e6ef416bfe37e60b3dc54 (patch)
tree9f33aa1bc06230261cf72965956c4a59ecfb3a74 /gcc/match.pd
parent03877e7eccd2734ca93a2d13aa2abf55e0aec923 (diff)
downloadgcc-f1b03fa964527678f15e6ef416bfe37e60b3dc54.zip
gcc-f1b03fa964527678f15e6ef416bfe37e60b3dc54.tar.gz
gcc-f1b03fa964527678f15e6ef416bfe37e60b3dc54.tar.bz2
match.pd: Fix parity (X) ^ parity (Y) simplification [PR112719]
When looking around, I've noticed we have a similar simplification for parity (with ^ rather than +). Note, unlike the popcount one, this one doesn't check for INTEGRAL_TYPE_P (type) (which rules out vector simplification), so I've used the old handling for types_match and otherwise do it only for scalar argument types and handle different precision in there. The testcase ICEs without the previous patch on the first function, but strangely not on the second which tests parity. The reason is that in this case there is no wi::bit_and test like for popcount and for BITINT_TYPEs build_call_internal actually refuses to create it and thus the whole simplification fails. While .{CLZ,CTZ,CLRSB,FFS,POPCOUNT,PARITY} ifns are direct optab ifns for normal integer and vector types (and thus it is desirable to punt if there is no supported optab for them), they have this large/huge _BitInt extension before bitint lowering, so the patch also adjusts build_call_internal to allow that case. 2023-11-28 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/112719 * match.pd (parity(X)^parity(Y) -> parity(X^Y)): Handle case of mismatched types. * gimple-match-exports.cc (build_call_internal): Add special-case for bit query ifns on large/huge BITINT_TYPE before bitint lowering. * gcc.dg/bitint-43.c: New test.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 0382fd5..0170591 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8882,7 +8882,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* parity(X)^parity(Y) is parity(X^Y). */
(simplify
(bit_xor (PARITY:s @0) (PARITY:s @1))
- (PARITY (bit_xor @0 @1)))
+ (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
+ (PARITY (bit_xor @0 @1))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@1)))
+ (with { tree utype = TREE_TYPE (@0);
+ if (TYPE_PRECISION (utype) < TYPE_PRECISION (TREE_TYPE (@1)))
+ utype = TREE_TYPE (@1); }
+ (PARITY (bit_xor (convert:utype @0) (convert:utype @1)))))))
#if GIMPLE
/* parity(zext(X)) == parity(X). */