public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms
@ 2024-01-17 19:14 Philipp Tomsich
0 siblings, 0 replies; 5+ messages in thread
From: Philipp Tomsich @ 2024-01-17 19:14 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:89a6e3d55d5b4422f6be334cfd8ea4127917068f
commit 89a6e3d55d5b4422f6be334cfd8ea4127917068f
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date: Wed Nov 1 12:27:28 2023 +0100
match.pd: Look through view_convert when folding vec_perms
The match.pd patterns to merge two vector permutes into one fail to
match when a (potentially no-op) view convert expressions is
separating the two permutes. This is observable in the SLP tree for
the first loop of x264's satd and inhibits optimization.
This change adds a check whether a view_convert will be a no-op
(comparing the element precision) and rewrites the permute sequence
for those cases.
Ref #343
Diff:
---
gcc/match.pd | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 7b4b15acc41..59a664293ea 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9929,7 +9929,7 @@ and,
d = VEC_PERM_EXPR <a, b, NEW_VCST>; */
(simplify
- (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
+ (vec_perm (view_convert?@0 (vec_perm @1 @2 VECTOR_CST@3)) @0 VECTOR_CST@4)
(if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
(with
{
@@ -9941,7 +9941,8 @@ and,
vec_perm_builder builder2 (nelts, nelts, 1);
}
(if (tree_to_vec_perm_builder (&builder0, @3)
- && tree_to_vec_perm_builder (&builder1, @4))
+ && tree_to_vec_perm_builder (&builder1, @4)
+ && element_precision (type) == element_precision (TREE_TYPE (@0)))
(with
{
vec_perm_indices sel0 (builder0, 2, nelts);
@@ -9966,7 +9967,7 @@ and,
op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
}
(if (op0)
- (vec_perm @1 @2 { op0; })))))))
+ (view_convert (vec_perm @1 @2 { op0; }))))))))
/* Merge
c = VEC_PERM_EXPR <a, b, VCST0>;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms
@ 2024-02-27 13:37 Philipp Tomsich
0 siblings, 0 replies; 5+ messages in thread
From: Philipp Tomsich @ 2024-02-27 13:37 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e8a30f2e241d213a9761a473eb63f1c32e2c182e
commit e8a30f2e241d213a9761a473eb63f1c32e2c182e
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date: Wed Nov 1 12:27:28 2023 +0100
match.pd: Look through view_convert when folding vec_perms
The match.pd patterns to merge two vector permutes into one fail to
match when a (potentially no-op) view convert expressions is
separating the two permutes. This is observable in the SLP tree for
the first loop of x264's satd and inhibits optimization.
This change adds a check whether a view_convert will be a no-op
(comparing the element precision) and rewrites the permute sequence
for those cases.
Ref #343
Diff:
---
gcc/match.pd | 14 ++++++++------
gcc/testsuite/gcc.dg/fold-perm-2.c | 16 ++++++++++++++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index f3fffd8dec2..ae8c981b306 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9978,19 +9978,21 @@ and,
d = VEC_PERM_EXPR <a, b, NEW_VCST>; */
(simplify
- (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
+ (vec_perm (view_convert?@0 (vec_perm@1 @2 @3 VECTOR_CST@4)) @0 VECTOR_CST@5)
(if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
(with
{
machine_mode result_mode = TYPE_MODE (type);
- machine_mode op_mode = TYPE_MODE (TREE_TYPE (@1));
+ machine_mode op_mode = TYPE_MODE (TREE_TYPE (@2));
int nelts = TYPE_VECTOR_SUBPARTS (type).to_constant ();
vec_perm_builder builder0;
vec_perm_builder builder1;
vec_perm_builder builder2 (nelts, nelts, 1);
}
- (if (tree_to_vec_perm_builder (&builder0, @3)
- && tree_to_vec_perm_builder (&builder1, @4))
+ (if (tree_to_vec_perm_builder (&builder0, @4)
+ && tree_to_vec_perm_builder (&builder1, @5)
+ && element_precision (TREE_TYPE (@0))
+ == element_precision (TREE_TYPE (@1)))
(with
{
vec_perm_indices sel0 (builder0, 2, nelts);
@@ -10012,10 +10014,10 @@ and,
? (!can_vec_perm_const_p (result_mode, op_mode, sel0, false)
|| !can_vec_perm_const_p (result_mode, op_mode, sel1, false))
: !can_vec_perm_const_p (result_mode, op_mode, sel1, false)))
- op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
+ op0 = vec_perm_indices_to_tree (TREE_TYPE (@5), sel2);
}
(if (op0)
- (vec_perm @1 @2 { op0; })))))))
+ (view_convert (vec_perm @2 @3 { op0; }))))))))
/* Merge
c = VEC_PERM_EXPR <a, b, VCST0>;
diff --git a/gcc/testsuite/gcc.dg/fold-perm-2.c b/gcc/testsuite/gcc.dg/fold-perm-2.c
new file mode 100644
index 00000000000..1a4ab4065de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-perm-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1" } */
+
+typedef int veci __attribute__ ((vector_size (4 * sizeof (int))));
+typedef unsigned int vecu __attribute__ ((vector_size (4 * sizeof (unsigned int))));
+
+void fun (veci *a, veci *b, veci *c)
+{
+ veci r1 = __builtin_shufflevector (*a, *b, 0, 5, 2, 7);
+ vecu r2 = __builtin_convertvector (r1, vecu);
+ vecu r3 = __builtin_shufflevector (r2, r2, 2, 3, 1, 0);
+ *c = __builtin_convertvector (r3, veci);
+}
+
+/* { dg-final { scan-tree-dump "VEC_PERM_EXPR.*{ 2, 7, 5, 0 }" "fre1" } } */
+/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "fre1" } } */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms
@ 2024-01-23 20:57 Philipp Tomsich
2024-01-23 23:49 ` Andrew Pinski
0 siblings, 1 reply; 5+ messages in thread
From: Philipp Tomsich @ 2024-01-23 20:57 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b896c82f141211437b5b5b83a3537d6bd2d243dc
commit b896c82f141211437b5b5b83a3537d6bd2d243dc
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date: Wed Nov 1 12:27:28 2023 +0100
match.pd: Look through view_convert when folding vec_perms
The match.pd patterns to merge two vector permutes into one fail to
match when a (potentially no-op) view convert expressions is
separating the two permutes. This is observable in the SLP tree for
the first loop of x264's satd and inhibits optimization.
This change adds a check whether a view_convert will be a no-op
(comparing the element precision) and rewrites the permute sequence
for those cases.
Ref #343
Diff:
---
gcc/match.pd | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index e42ecaf9ec7..be623d9773c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9965,7 +9965,7 @@ and,
d = VEC_PERM_EXPR <a, b, NEW_VCST>; */
(simplify
- (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
+ (vec_perm (view_convert?@0 (vec_perm @1 @2 VECTOR_CST@3)) @0 VECTOR_CST@4)
(if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
(with
{
@@ -9977,7 +9977,8 @@ and,
vec_perm_builder builder2 (nelts, nelts, 1);
}
(if (tree_to_vec_perm_builder (&builder0, @3)
- && tree_to_vec_perm_builder (&builder1, @4))
+ && tree_to_vec_perm_builder (&builder1, @4)
+ && element_precision (type) == element_precision (TREE_TYPE (@0)))
(with
{
vec_perm_indices sel0 (builder0, 2, nelts);
@@ -10002,7 +10003,7 @@ and,
op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
}
(if (op0)
- (vec_perm @1 @2 { op0; })))))))
+ (view_convert (vec_perm @1 @2 { op0; }))))))))
/* Merge
c = VEC_PERM_EXPR <a, b, VCST0>;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms
2024-01-23 20:57 Philipp Tomsich
@ 2024-01-23 23:49 ` Andrew Pinski
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2024-01-23 23:49 UTC (permalink / raw)
To: Philipp Tomsich, Andrew Pinski (QUIC); +Cc: gcc-cvs
On Tue, Jan 23, 2024 at 12:57 PM Philipp Tomsich via Gcc-cvs
<gcc-cvs@gcc.gnu.org> wrote:
>
> https://gcc.gnu.org/g:b896c82f141211437b5b5b83a3537d6bd2d243dc
>
> commit b896c82f141211437b5b5b83a3537d6bd2d243dc
> Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
> Date: Wed Nov 1 12:27:28 2023 +0100
>
> match.pd: Look through view_convert when folding vec_perms
>
> The match.pd patterns to merge two vector permutes into one fail to
> match when a (potentially no-op) view convert expressions is
> separating the two permutes. This is observable in the SLP tree for
> the first loop of x264's satd and inhibits optimization.
>
> This change adds a check whether a view_convert will be a no-op
> (comparing the element precision) and rewrites the permute sequence
> for those cases.
My suggestion is just use nop_convert instead and which does the
correct thing for a vector conversion between signed and unsigned
types.
Or do you need one between integer and floating point types too?
Thanks,
Andrew
>
> Ref #343
>
> Diff:
> ---
> gcc/match.pd | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index e42ecaf9ec7..be623d9773c 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -9965,7 +9965,7 @@ and,
> d = VEC_PERM_EXPR <a, b, NEW_VCST>; */
>
> (simplify
> - (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
> + (vec_perm (view_convert?@0 (vec_perm @1 @2 VECTOR_CST@3)) @0 VECTOR_CST@4)
> (if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
> (with
> {
> @@ -9977,7 +9977,8 @@ and,
> vec_perm_builder builder2 (nelts, nelts, 1);
> }
> (if (tree_to_vec_perm_builder (&builder0, @3)
> - && tree_to_vec_perm_builder (&builder1, @4))
> + && tree_to_vec_perm_builder (&builder1, @4)
> + && element_precision (type) == element_precision (TREE_TYPE (@0)))
> (with
> {
> vec_perm_indices sel0 (builder0, 2, nelts);
> @@ -10002,7 +10003,7 @@ and,
> op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
> }
> (if (op0)
> - (vec_perm @1 @2 { op0; })))))))
> + (view_convert (vec_perm @1 @2 { op0; }))))))))
>
> /* Merge
> c = VEC_PERM_EXPR <a, b, VCST0>;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms
@ 2023-11-28 13:35 Philipp Tomsich
0 siblings, 0 replies; 5+ messages in thread
From: Philipp Tomsich @ 2023-11-28 13:35 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e9bbe3d12c929449053eadb485bcfa5586d311e0
commit e9bbe3d12c929449053eadb485bcfa5586d311e0
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date: Wed Nov 1 12:27:28 2023 +0100
match.pd: Look through view_convert when folding vec_perms
The match.pd patterns to merge two vector permutes into one fail to
match when a (potentially no-op) view convert expressions is
separating the two permutes. This is observable in the SLP tree for
the first loop of x264's satd and inhibits optimization.
This change adds a check whether a view_convert will be a no-op
(comparing the element precision) and rewrites the permute sequence
for those cases.
Ref #343
Diff:
---
gcc/match.pd | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index b30de36e836..c41e1f8796b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9818,7 +9818,7 @@ and,
d = VEC_PERM_EXPR <a, b, NEW_VCST>; */
(simplify
- (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
+ (vec_perm (view_convert?@0 (vec_perm @1 @2 VECTOR_CST@3)) @0 VECTOR_CST@4)
(if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
(with
{
@@ -9830,7 +9830,8 @@ and,
vec_perm_builder builder2 (nelts, nelts, 1);
}
(if (tree_to_vec_perm_builder (&builder0, @3)
- && tree_to_vec_perm_builder (&builder1, @4))
+ && tree_to_vec_perm_builder (&builder1, @4)
+ && element_precision (type) == element_precision (TREE_TYPE (@0)))
(with
{
vec_perm_indices sel0 (builder0, 2, nelts);
@@ -9855,7 +9856,7 @@ and,
op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
}
(if (op0)
- (vec_perm @1 @2 { op0; })))))))
+ (view_convert (vec_perm @1 @2 { op0; }))))))))
/* Merge
c = VEC_PERM_EXPR <a, b, VCST0>;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-27 13:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 19:14 [gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms Philipp Tomsich
-- strict thread matches above, loose matches on Subject: below --
2024-02-27 13:37 Philipp Tomsich
2024-01-23 20:57 Philipp Tomsich
2024-01-23 23:49 ` Andrew Pinski
2023-11-28 13:35 Philipp Tomsich
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).