* [COMMITTED] tree-optimization: [PR109702] MATCH: Fix a ? func(a) : N patterns
@ 2023-05-02 21:45 Andrew Pinski
0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-05-02 21:45 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
I accidently messed up these patterns so the comparison
against 0 and the arguments was not matching up when they
need to be.
I committed this as obvious after a bootstrap/test on x86_64-linux-gnu
PR tree-optimization/109702
gcc/ChangeLog:
* match.pd: Fix "a != 0 ? FUNC(a) : CST" patterns
for FUNC of POPCOUNT BSWAP FFS PARITY CLZ and CTZ.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/phi-opt-25b.c: New test.
---
gcc/match.pd | 16 ++---
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c | 70 +++++++++++++++++++++
2 files changed, 78 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 0e782cde71d..b14b7017c9a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7784,14 +7784,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* a != 0 ? FUN(a) : 0 -> Fun(a) for some builtin functions. */
(for func (POPCOUNT BSWAP FFS PARITY)
(simplify
- (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3)
- @4))
+ (cond (ne @0 integer_zerop@1) (func@3 (convert? @0)) integer_zerop@2)
+ @3))
#if GIMPLE
/* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */
(for func (CLZ)
(simplify
- (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3)
+ (cond (ne @0 integer_zerop@1) (func (convert?@3 @0)) INTEGER_CST@2)
(with { int val;
internal_fn ifn = IFN_LAST;
if (direct_internal_fn_supported_p (IFN_CLZ, type, OPTIMIZE_FOR_BOTH)
@@ -7799,13 +7799,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
val) == 2)
ifn = IFN_CLZ;
}
- (if (ifn == IFN_CLZ && wi::to_widest (@3) == val)
- (IFN_CLZ @4)))))
+ (if (ifn == IFN_CLZ && wi::to_widest (@2) == val)
+ (IFN_CLZ @3)))))
/* a != 0 ? CTZ(a) : CST -> .CTZ(a) where CST is the result of the internal function for 0. */
(for func (CTZ)
(simplify
- (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3)
+ (cond (ne @0 integer_zerop@1) (func (convert?@3 @0)) INTEGER_CST@2)
(with { int val;
internal_fn ifn = IFN_LAST;
if (direct_internal_fn_supported_p (IFN_CTZ, type, OPTIMIZE_FOR_BOTH)
@@ -7813,8 +7813,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
val) == 2)
ifn = IFN_CTZ;
}
- (if (ifn == IFN_CTZ && wi::to_widest (@3) == val)
- (IFN_CTZ @4)))))
+ (if (ifn == IFN_CTZ && wi::to_widest (@2) == val)
+ (IFN_CTZ @3)))))
#endif
/* Common POPCOUNT/PARITY simplifications. */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c
new file mode 100644
index 00000000000..698a20f7a56
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25b.c
@@ -0,0 +1,70 @@
+/* PR tree-optimization/109702 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+/* Test to make sure unrelated arguments and comparisons
+ don't get optimized incorrectly. */
+
+unsigned short test_bswap16(unsigned short x, unsigned short y)
+{
+ return x ? __builtin_bswap16(y) : 0;
+}
+
+unsigned int test_bswap32(unsigned int x, unsigned int y)
+{
+ return x ? __builtin_bswap32(y) : 0;
+}
+
+unsigned long long test_bswap64(unsigned long long x, unsigned long long y)
+{
+ return x ? __builtin_bswap64(y) : 0;
+}
+
+int test_clrsb(int x, int y)
+{
+ return x ? __builtin_clrsb(y) : (__SIZEOF_INT__*8-1);
+}
+
+int test_clrsbl(long x, long y)
+{
+ return x ? __builtin_clrsbl(y) : (__SIZEOF_LONG__*8-1);
+}
+
+int test_clrsbll(long long x, long long y)
+{
+ return x ? __builtin_clrsbll(y) : (__SIZEOF_LONG_LONG__*8-1);
+}
+
+int test_parity(unsigned int x, unsigned int y)
+{
+ return x ? __builtin_parity(y) : 0;
+}
+
+int test_parityl(unsigned long x, unsigned long y)
+{
+ return x ? __builtin_parityl(y) : 0;
+}
+
+int test_parityll(unsigned long long x, unsigned long long y)
+{
+ return x ? __builtin_parityll(y) : 0;
+}
+
+int test_popcount(unsigned int x, unsigned int y)
+{
+ return x ? __builtin_popcount(y) : 0;
+}
+
+int test_popcountl(unsigned long x, unsigned long y)
+{
+ return x ? __builtin_popcountl(y) : 0;
+}
+
+int test_popcountll(unsigned long long x, unsigned long long y)
+{
+ return x ? __builtin_popcountll(y) : 0;
+}
+
+/* 4 types of functions, each with 3 types and there are 2 goto each */
+/* { dg-final { scan-tree-dump-times "goto " 24 "optimized" } } */
+
--
2.31.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-02 21:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 21:45 [COMMITTED] tree-optimization: [PR109702] MATCH: Fix a ? func(a) : N patterns Andrew Pinski
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).