* [PATCH] libgccjit: Allow comparing aligned int types
@ 2023-12-21 13:33 Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
2024-01-24 17:18 ` David Malcolm
0 siblings, 2 replies; 5+ messages in thread
From: Antoni Boucher @ 2023-12-21 13:33 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
[-- Attachment #1: Type: text/plain, Size: 213 bytes --]
Hi.
This patch allows comparing aligned integer types as equal.
There's a TODO in the code about whether we should check that the
alignment is equal.
What are your thoughts on this?
Thanks for the review.
[-- Attachment #2: 0001-libgccjit-Allow-comparing-aligned-int-types.patch --]
[-- Type: text/x-patch, Size: 3703 bytes --]
From b1db2e31729876d313061a94c13b155bcd552c02 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Sun, 8 Oct 2023 09:12:12 -0400
Subject: [PATCH] libgccjit: Allow comparing aligned int types
gcc/jit/ChangeLog:
* jit-recording.h (type::is_same_type_as): Compare integer
types.
(type::is_aligned, memento_of_get_aligned::is_same_type_as,
memento_of_get_aligned::is_aligned): new methods.
gcc/testsuite/ChangeLog:
* jit.dg/test-types.c: Add checks comparing aligned types.
---
gcc/jit/jit-recording.h | 28 +++++++++++++++++++++-------
gcc/testsuite/jit.dg/test-types.c | 10 +++++++---
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 4a8082991fb..97f39f3fc98 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -555,6 +555,14 @@ public:
virtual bool is_same_type_as (type *other)
{
+ if (is_int ()
+ && other->is_int ()
+ && get_size () == other->get_size ()
+ && is_signed () == other->is_signed ())
+ {
+ /* LHS (this) is an integer of the same size and sign as rtype. */
+ return true;
+ }
return this == other;
}
@@ -571,6 +579,7 @@ public:
virtual type *is_volatile () { return NULL; }
virtual type *is_restrict () { return NULL; }
virtual type *is_const () { return NULL; }
+ virtual type *is_aligned () { return NULL; }
virtual type *is_array () = 0;
virtual struct_ *is_struct () { return NULL; }
virtual bool is_union () const { return false; }
@@ -625,13 +634,6 @@ public:
accept it: */
return true;
}
- } else if (is_int ()
- && rtype->is_int ()
- && get_size () == rtype->get_size ()
- && is_signed () == rtype->is_signed ())
- {
- /* LHS (this) is an integer of the same size and sign as rtype. */
- return true;
}
return type::accepts_writes_from (rtype);
@@ -805,6 +807,18 @@ public:
: decorated_type (other_type),
m_alignment_in_bytes (alignment_in_bytes) {}
+ bool is_same_type_as (type *other) final override
+ {
+ // TODO: check if outermost alignment is equal?
+ if (!other->is_aligned ())
+ {
+ return m_other_type->is_same_type_as (other);
+ }
+ return m_other_type->is_same_type_as (other->is_aligned ());
+ }
+
+ type *is_aligned () final override { return m_other_type; }
+
/* Strip off the alignment, giving the underlying type. */
type *unqualified () final override { return m_other_type; }
diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c
index a01944e35fa..c2f4d2bcb3d 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -485,11 +485,15 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
CHECK_VALUE (z.m_FILE_ptr, stderr);
+ gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+ gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T);
if (sizeof(long) == 8)
- CHECK (gcc_jit_compatible_types (
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
+ CHECK (gcc_jit_compatible_types (long_type, int64_type));
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
+
+ gcc_jit_type *aligned_long = gcc_jit_type_get_aligned (long_type, 4);
+ gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned (int64_type, 4);
+ CHECK (gcc_jit_compatible_types (aligned_long, aligned_int64));
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow comparing aligned int types
2023-12-21 13:33 [PATCH] libgccjit: Allow comparing aligned int types Antoni Boucher
@ 2024-01-19 20:59 ` Antoni Boucher
2024-01-24 17:18 ` David Malcolm
1 sibling, 0 replies; 5+ messages in thread
From: Antoni Boucher @ 2024-01-19 20:59 UTC (permalink / raw)
To: jit, gcc-patches; +Cc: David Malcolm
David: Ping.
On Thu, 2023-12-21 at 08:33 -0500, Antoni Boucher wrote:
> Hi.
> This patch allows comparing aligned integer types as equal.
> There's a TODO in the code about whether we should check that the
> alignment is equal.
> What are your thoughts on this?
>
> Thanks for the review.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow comparing aligned int types
2023-12-21 13:33 [PATCH] libgccjit: Allow comparing aligned int types Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
@ 2024-01-24 17:18 ` David Malcolm
2024-02-22 17:40 ` Antoni Boucher
1 sibling, 1 reply; 5+ messages in thread
From: David Malcolm @ 2024-01-24 17:18 UTC (permalink / raw)
To: Antoni Boucher, jit, gcc-patches
On Thu, 2023-12-21 at 08:33 -0500, Antoni Boucher wrote:
> Hi.
> This patch allows comparing aligned integer types as equal.
> There's a TODO in the code about whether we should check that the
> alignment is equal.
> What are your thoughts on this?
I think we should check for equal alignment.
[...snip...]
> diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c
> index a01944e35fa..c2f4d2bcb3d 100644
> --- a/gcc/testsuite/jit.dg/test-types.c
> +++ b/gcc/testsuite/jit.dg/test-types.c
> @@ -485,11 +485,15 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
>
> CHECK_VALUE (z.m_FILE_ptr, stderr);
>
> + gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
> + gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T);
> if (sizeof(long) == 8)
> - CHECK (gcc_jit_compatible_types (
> - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
> - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
> + CHECK (gcc_jit_compatible_types (long_type, int64_type));
>
> CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
> CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
> +
> + gcc_jit_type *aligned_long = gcc_jit_type_get_aligned (long_type, 4);
> + gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned (int64_type, 4);
> + CHECK (gcc_jit_compatible_types (aligned_long, aligned_int64));
This CHECK should be guarded on sizeof(long) == 8 like the check above.
Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow comparing aligned int types
2024-01-24 17:18 ` David Malcolm
@ 2024-02-22 17:40 ` Antoni Boucher
2024-11-20 15:43 ` David Malcolm
0 siblings, 1 reply; 5+ messages in thread
From: Antoni Boucher @ 2024-02-22 17:40 UTC (permalink / raw)
To: David Malcolm, jit, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]
Thanks for the review.
Here's the updated patch.
On Wed, 2024-01-24 at 12:18 -0500, David Malcolm wrote:
> On Thu, 2023-12-21 at 08:33 -0500, Antoni Boucher wrote:
> > Hi.
> > This patch allows comparing aligned integer types as equal.
> > There's a TODO in the code about whether we should check that the
> > alignment is equal.
> > What are your thoughts on this?
>
> I think we should check for equal alignment.
>
> [...snip...]
>
> > diff --git a/gcc/testsuite/jit.dg/test-types.c
> > b/gcc/testsuite/jit.dg/test-types.c
> > index a01944e35fa..c2f4d2bcb3d 100644
> > --- a/gcc/testsuite/jit.dg/test-types.c
> > +++ b/gcc/testsuite/jit.dg/test-types.c
> > @@ -485,11 +485,15 @@ verify_code (gcc_jit_context *ctxt,
> > gcc_jit_result *result)
> >
> > CHECK_VALUE (z.m_FILE_ptr, stderr);
> >
> > + gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt,
> > GCC_JIT_TYPE_LONG);
> > + gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt,
> > GCC_JIT_TYPE_INT64_T);
> > if (sizeof(long) == 8)
> > - CHECK (gcc_jit_compatible_types (
> > - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
> > - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
> > + CHECK (gcc_jit_compatible_types (long_type, int64_type));
> >
> > CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
> > CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
> > +
> > + gcc_jit_type *aligned_long = gcc_jit_type_get_aligned
> > (long_type, 4);
> > + gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned
> > (int64_type, 4);
> > + CHECK (gcc_jit_compatible_types (aligned_long, aligned_int64));
>
> This CHECK should be guarded on sizeof(long) == 8 like the check
> above.
>
>
> Dave
>
[-- Attachment #2: 0001-libgccjit-Allow-comparing-aligned-int-types.patch --]
[-- Type: text/x-patch, Size: 4884 bytes --]
From 899a0555fa1b1796d29b59a6a41db854c46f6c09 Mon Sep 17 00:00:00 2001
From: Antoni Boucher <bouanto@zoho.com>
Date: Sun, 8 Oct 2023 09:12:12 -0400
Subject: [PATCH] libgccjit: Allow comparing aligned int types
gcc/jit/ChangeLog:
* jit-common.h: Add forward declaration of memento_of_get_aligned.
* jit-recording.h (type::is_same_type_as): Compare integer
types.
(dyn_cast_aligned_type): New method.
(type::is_aligned, memento_of_get_aligned::is_same_type_as,
memento_of_get_aligned::is_aligned): new methods.
gcc/testsuite/ChangeLog:
* jit.dg/test-types.c: Add checks comparing aligned types.
---
gcc/jit/jit-common.h | 1 +
gcc/jit/jit-recording.h | 30 +++++++++++++++++++++++-------
gcc/testsuite/jit.dg/test-types.c | 11 ++++++++---
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index 1e335878b56..53a6dcce79f 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -133,6 +133,7 @@ namespace recording {
class statement;
class extended_asm;
class case_;
+ class memento_of_get_aligned;
class top_level_asm;
/* End of recording types. */
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index d8d16f4fe29..9af952cc217 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -552,6 +552,7 @@ public:
virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
virtual struct_ *dyn_cast_struct () { return NULL; }
virtual vector_type *dyn_cast_vector_type () { return NULL; }
+ virtual memento_of_get_aligned *dyn_cast_aligned_type () { return NULL; }
/* Is it typesafe to copy to this type from rtype? */
virtual bool accepts_writes_from (type *rtype)
@@ -562,6 +563,14 @@ public:
virtual bool is_same_type_as (type *other)
{
+ if (is_int ()
+ && other->is_int ()
+ && get_size () == other->get_size ()
+ && is_signed () == other->is_signed ())
+ {
+ /* LHS (this) is an integer of the same size and sign as rtype. */
+ return true;
+ }
return this == other;
}
@@ -579,6 +588,7 @@ public:
virtual type *is_volatile () { return NULL; }
virtual type *is_restrict () { return NULL; }
virtual type *is_const () { return NULL; }
+ virtual type *is_aligned () { return NULL; }
virtual type *is_array () = 0;
virtual struct_ *is_struct () { return NULL; }
virtual bool is_union () const { return false; }
@@ -633,13 +643,6 @@ public:
accept it: */
return true;
}
- } else if (is_int ()
- && rtype->is_int ()
- && get_size () == rtype->get_size ()
- && is_signed () == rtype->is_signed ())
- {
- /* LHS (this) is an integer of the same size and sign as rtype. */
- return true;
}
return type::accepts_writes_from (rtype);
@@ -816,10 +819,23 @@ public:
: decorated_type (other_type),
m_alignment_in_bytes (alignment_in_bytes) {}
+ bool is_same_type_as (type *other) final override
+ {
+ if (!other->is_aligned ())
+ {
+ return m_other_type->is_same_type_as (other);
+ }
+ return m_alignment_in_bytes == other->dyn_cast_aligned_type ()->m_alignment_in_bytes
+ && m_other_type->is_same_type_as (other->is_aligned ());
+ }
+
+ type *is_aligned () final override { return m_other_type; }
+
/* Strip off the alignment, giving the underlying type. */
type *unqualified () final override { return m_other_type; }
void replay_into (replayer *) final override;
+ memento_of_get_aligned *dyn_cast_aligned_type () final override { return this; }
private:
string * make_debug_string () final override;
diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c
index a01944e35fa..d016bb5d001 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -485,11 +485,16 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
CHECK_VALUE (z.m_FILE_ptr, stderr);
+ gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+ gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T);
if (sizeof(long) == 8)
- CHECK (gcc_jit_compatible_types (
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
+ CHECK (gcc_jit_compatible_types (long_type, int64_type));
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
+
+ gcc_jit_type *aligned_long = gcc_jit_type_get_aligned (long_type, 4);
+ gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned (int64_type, 4);
+ if (sizeof(long) == 8)
+ CHECK (gcc_jit_compatible_types (aligned_long, aligned_int64));
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libgccjit: Allow comparing aligned int types
2024-02-22 17:40 ` Antoni Boucher
@ 2024-11-20 15:43 ` David Malcolm
0 siblings, 0 replies; 5+ messages in thread
From: David Malcolm @ 2024-11-20 15:43 UTC (permalink / raw)
To: Antoni Boucher, jit, gcc-patches
On Thu, 2024-02-22 at 12:40 -0500, Antoni Boucher wrote:
> Thanks for the review.
> Here's the updated patch.
Thanks; the updated patch is good for trunk.
Dave
>
> On Wed, 2024-01-24 at 12:18 -0500, David Malcolm wrote:
> > On Thu, 2023-12-21 at 08:33 -0500, Antoni Boucher wrote:
> > > Hi.
> > > This patch allows comparing aligned integer types as equal.
> > > There's a TODO in the code about whether we should check that the
> > > alignment is equal.
> > > What are your thoughts on this?
> >
> > I think we should check for equal alignment.
> >
> > [...snip...]
> >
> > > diff --git a/gcc/testsuite/jit.dg/test-types.c
> > > b/gcc/testsuite/jit.dg/test-types.c
> > > index a01944e35fa..c2f4d2bcb3d 100644
> > > --- a/gcc/testsuite/jit.dg/test-types.c
> > > +++ b/gcc/testsuite/jit.dg/test-types.c
> > > @@ -485,11 +485,15 @@ verify_code (gcc_jit_context *ctxt,
> > > gcc_jit_result *result)
> > >
> > > CHECK_VALUE (z.m_FILE_ptr, stderr);
> > >
> > > + gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt,
> > > GCC_JIT_TYPE_LONG);
> > > + gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt,
> > > GCC_JIT_TYPE_INT64_T);
> > > if (sizeof(long) == 8)
> > > - CHECK (gcc_jit_compatible_types (
> > > - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
> > > - gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
> > > + CHECK (gcc_jit_compatible_types (long_type, int64_type));
> > >
> > > CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > > (ctxt, GCC_JIT_TYPE_FLOAT)), sizeof (float));
> > > CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type
> > > (ctxt, GCC_JIT_TYPE_DOUBLE)), sizeof (double));
> > > +
> > > + gcc_jit_type *aligned_long = gcc_jit_type_get_aligned
> > > (long_type, 4);
> > > + gcc_jit_type *aligned_int64 = gcc_jit_type_get_aligned
> > > (int64_type, 4);
> > > + CHECK (gcc_jit_compatible_types (aligned_long,
> > > aligned_int64));
> >
> > This CHECK should be guarded on sizeof(long) == 8 like the check
> > above.
> >
> >
> > Dave
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-20 15:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 13:33 [PATCH] libgccjit: Allow comparing aligned int types Antoni Boucher
2024-01-19 20:59 ` Antoni Boucher
2024-01-24 17:18 ` David Malcolm
2024-02-22 17:40 ` Antoni Boucher
2024-11-20 15:43 ` David Malcolm
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).