* [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE
@ 2021-11-28 17:56 apinski
2021-11-28 20:25 ` Jeff Law
0 siblings, 1 reply; 4+ messages in thread
From: apinski @ 2021-11-28 17:56 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
From: Andrew Pinski <apinski@marvell.com>
This just adds a simplification to simplify_vector_constructor for
vector of 1 element to be VCE which should reduce memory usage in
the compiler and maybe allow for some more optimizations.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/101540
gcc/ChangeLog:
* tree-ssa-forwprop.c (simplify_vector_constructor):
Simplify constructor of vector of 1 element to just
be a VIEW_CONVERT_EXPR.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr101540-1.c: New test.
---
gcc/testsuite/gcc.dg/tree-ssa/pr101540-1.c | 13 +++++++++++++
gcc/tree-ssa-forwprop.c | 13 +++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr101540-1.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101540-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101540-1.c
new file mode 100644
index 00000000000..73fb342e029
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101540-1.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop1" } */
+/* PR tree-optimization/101540 */
+typedef unsigned char __attribute__((__vector_size__ (1))) W;
+
+W foo (unsigned char uc)
+{
+ return (W){uc};
+}
+/* The constructor in the above function should be converted into a VCE. */
+/* { dg-final { scan-tree-dump-times "VIEW_CONVERT_EXPR" 1 "forwprop1"} } */
+// {uc_1(D)}
+/* { dg-final { scan-tree-dump-times "{uc_\[0-9\]+.D.}" 0 "forwprop1"} } */
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index a830bab78ba..94b92d3d0af 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -2392,6 +2392,19 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
elem_type = TREE_TYPE (type);
elem_size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type));
+ /* Special case V1 constructor with the same type to being a VCE. */
+ if (nelts == 1 && CONSTRUCTOR_NELTS (op) == 1)
+ {
+ tree op1 = CONSTRUCTOR_ELT (op, 0)->value;
+ if (useless_type_conversion_p (elem_type, TREE_TYPE (op1)))
+ {
+ op1 = build1 (VIEW_CONVERT_EXPR, type, op1);
+ gimple_assign_set_rhs_from_tree (gsi, op1);
+ update_stmt (gsi_stmt (*gsi));
+ return true;
+ }
+ }
+
orig[0] = NULL;
orig[1] = NULL;
conv_code = ERROR_MARK;
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE
2021-11-28 17:56 [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE apinski
@ 2021-11-28 20:25 ` Jeff Law
2021-11-29 0:56 ` Andrew Pinski
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Law @ 2021-11-28 20:25 UTC (permalink / raw)
To: apinski, gcc-patches
On 11/28/2021 10:56 AM, apinski--- via Gcc-patches wrote:
> From: Andrew Pinski <apinski@marvell.com>
>
> This just adds a simplification to simplify_vector_constructor for
> vector of 1 element to be VCE which should reduce memory usage in
> the compiler and maybe allow for some more optimizations.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>
> PR tree-optimization/101540
>
> gcc/ChangeLog:
>
> * tree-ssa-forwprop.c (simplify_vector_constructor):
> Simplify constructor of vector of 1 element to just
> be a VIEW_CONVERT_EXPR.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/tree-ssa/pr101540-1.c: New test.
So why generate a VCE here if the type conversion is useless? Why not
just a NOP_EXPR? Is there something special about converting between
the element type and the outer vector type that requires VCE rather than
NOP_EXR? Neither an ACK or NAK, just trying to understand it a bit better.
Jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE
2021-11-28 20:25 ` Jeff Law
@ 2021-11-29 0:56 ` Andrew Pinski
2021-11-29 8:59 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Pinski @ 2021-11-29 0:56 UTC (permalink / raw)
To: Jeff Law; +Cc: Andrew Pinski, GCC Patches
On Sun, Nov 28, 2021 at 12:25 PM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
>
> On 11/28/2021 10:56 AM, apinski--- via Gcc-patches wrote:
> > From: Andrew Pinski <apinski@marvell.com>
> >
> > This just adds a simplification to simplify_vector_constructor for
> > vector of 1 element to be VCE which should reduce memory usage in
> > the compiler and maybe allow for some more optimizations.
> >
> > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
> >
> > PR tree-optimization/101540
> >
> > gcc/ChangeLog:
> >
> > * tree-ssa-forwprop.c (simplify_vector_constructor):
> > Simplify constructor of vector of 1 element to just
> > be a VIEW_CONVERT_EXPR.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.dg/tree-ssa/pr101540-1.c: New test.
> So why generate a VCE here if the type conversion is useless? Why not
> just a NOP_EXPR? Is there something special about converting between
> the element type and the outer vector type that requires VCE rather than
> NOP_EXR? Neither an ACK or NAK, just trying to understand it a bit better.
Because right now tree-cfg.c has this check for vector types for NOP_EXPR:
/* Allow conversions between vectors with the same number of elements,
provided that the conversion is OK for the element types too. */
if (VECTOR_TYPE_P (lhs_type)
&& VECTOR_TYPE_P (rhs1_type)
&& known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
TYPE_VECTOR_SUBPARTS (rhs1_type)))
{
lhs_type = TREE_TYPE (lhs_type);
rhs1_type = TREE_TYPE (rhs1_type);
}
else if (VECTOR_TYPE_P (lhs_type) || VECTOR_TYPE_P (rhs1_type))
{
error ("invalid vector types in nop conversion");
debug_generic_expr (lhs_type);
debug_generic_expr (rhs1_type);
return true;
}
We can change this check here for NOP_EXPR and vector types but VCE is
still a nop in most cases and handled as such really. But I wonder if
the rest of the compiler is ready for it though.
Thanks,
Andrew Pinski
>
> Jeff
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE
2021-11-29 0:56 ` Andrew Pinski
@ 2021-11-29 8:59 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2021-11-29 8:59 UTC (permalink / raw)
To: Andrew Pinski; +Cc: Jeff Law, Andrew Pinski, GCC Patches
On Mon, Nov 29, 2021 at 1:57 AM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Sun, Nov 28, 2021 at 12:25 PM Jeff Law via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> >
> >
> > On 11/28/2021 10:56 AM, apinski--- via Gcc-patches wrote:
> > > From: Andrew Pinski <apinski@marvell.com>
> > >
> > > This just adds a simplification to simplify_vector_constructor for
> > > vector of 1 element to be VCE which should reduce memory usage in
> > > the compiler and maybe allow for some more optimizations.
> > >
> > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
> > >
> > > PR tree-optimization/101540
> > >
> > > gcc/ChangeLog:
> > >
> > > * tree-ssa-forwprop.c (simplify_vector_constructor):
> > > Simplify constructor of vector of 1 element to just
> > > be a VIEW_CONVERT_EXPR.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.dg/tree-ssa/pr101540-1.c: New test.
> > So why generate a VCE here if the type conversion is useless? Why not
> > just a NOP_EXPR? Is there something special about converting between
> > the element type and the outer vector type that requires VCE rather than
> > NOP_EXR? Neither an ACK or NAK, just trying to understand it a bit better.
>
>
> Because right now tree-cfg.c has this check for vector types for NOP_EXPR:
> /* Allow conversions between vectors with the same number of elements,
> provided that the conversion is OK for the element types too. */
> if (VECTOR_TYPE_P (lhs_type)
> && VECTOR_TYPE_P (rhs1_type)
> && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
> TYPE_VECTOR_SUBPARTS (rhs1_type)))
> {
> lhs_type = TREE_TYPE (lhs_type);
> rhs1_type = TREE_TYPE (rhs1_type);
> }
> else if (VECTOR_TYPE_P (lhs_type) || VECTOR_TYPE_P (rhs1_type))
> {
> error ("invalid vector types in nop conversion");
> debug_generic_expr (lhs_type);
> debug_generic_expr (rhs1_type);
> return true;
> }
>
> We can change this check here for NOP_EXPR and vector types but VCE is
> still a nop in most cases and handled as such really. But I wonder if
> the rest of the compiler is ready for it though.
It's definitely not a NOP, I think the original patch is OK.
Thanks,
Richard.
>
> Thanks,
> Andrew Pinski
>
> >
> > Jeff
> >
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-29 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 17:56 [PATCH] tree-optimization: [PR101540] Simplify CONSTRUCTOR for vector(1) to be VCE apinski
2021-11-28 20:25 ` Jeff Law
2021-11-29 0:56 ` Andrew Pinski
2021-11-29 8:59 ` Richard Biener
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).