public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8277] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463]
@ 2024-01-19  9:02 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-01-19  9:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:df1cd90e32bb17d34f5fdce99bd0377fe1b8e5c6

commit r14-8277-gdf1cd90e32bb17d34f5fdce99bd0377fe1b8e5c6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jan 19 10:00:51 2024 +0100

    gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463]
    
    builtin_memref::extend_offset_range when it sees a NOP_EXPR from
    INTEGRAL_TYPE (to INTEGRAL_TYPE of sizetype/ptrdifftype precision
    given the callers) uses wi::to_offset on TYPE_{MIN,MAX}_VALUE
    of the rhs1 type.  This ICEs with large BITINT_TYPEs - to_offset
    is only supported for precisions up to the offset_int precision
    - but it even doesn't make any sense to do such thing for narrowing
    conversions, their range means the whole sizetype/ptrdifftype range
    and so the normal handling done later on (largest sized supported object)
    is the way to go in that case.
    
    So, the following patch just restrict this to non-narrowing conversions.
    
    2024-01-19  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/113463
            * gimple-ssa-warn-restrict.cc (builtin_memref::extend_offset_range):
            Only look through NOP_EXPRs if rhs1 doesn't have wider type than
            lhs.
    
            * gcc.dg/bitint-74.c: New test.

Diff:
---
 gcc/gimple-ssa-warn-restrict.cc  |  3 ++-
 gcc/testsuite/gcc.dg/bitint-74.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-warn-restrict.cc b/gcc/gimple-ssa-warn-restrict.cc
index dacb3b140bb..a552ce8dcdf 100644
--- a/gcc/gimple-ssa-warn-restrict.cc
+++ b/gcc/gimple-ssa-warn-restrict.cc
@@ -391,7 +391,8 @@ builtin_memref::extend_offset_range (tree offset)
       tree type;
       if (is_gimple_assign (stmt)
 	  && (type = TREE_TYPE (gimple_assign_rhs1 (stmt)))
-	  && INTEGRAL_TYPE_P (type))
+	  && INTEGRAL_TYPE_P (type)
+	  && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (offset)))
 	{
 	  tree_code code = gimple_assign_rhs_code (stmt);
 	  if (code == NOP_EXPR)
diff --git a/gcc/testsuite/gcc.dg/bitint-74.c b/gcc/testsuite/gcc.dg/bitint-74.c
new file mode 100644
index 00000000000..91143320dab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-74.c
@@ -0,0 +1,16 @@
+/* PR tree-optimization/113463 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+extern char *a, *b;
+#if __BITINT_MAXWIDTH__ >= 129
+_BitInt(129) o;
+#else
+_BitInt(63) o;
+#endif
+
+void
+foo (void)
+{
+  __builtin_memcpy (a + o, b, 4);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-19  9:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19  9:02 [gcc r14-8277] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463] Jakub Jelinek

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).