diff mbox

[libfortran,fortran] Fix PR 79956, part two, attempt 2

Message ID ef90f6b8-901e-4847-c6af-6751e56ffae4@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig March 13, 2017, 10:24 p.m. UTC
Hello world,

Following Richard's suggestion, I have implemented the GFC_ASSERT macro
and used it to (hopefully) silence the ominous warning and allow
further optimization.

OK for trunk?

Regards

	Thomas

2017-03-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR libfortran/79956
         * libgfortran.h (GFC_ASSERT):  New macro.
         * m4/reshape.m4 (reshape_'rtype_ccode`):  Use GFC_ASSERT
         to specify that sdim > 0.
         * intrinsic/reshape_generic.c (reshape_internal):  Likweise.
         * generated/reshape_c10.c: Regenerated.
         * generated/reshape_c16.c: Regenerated.
         * generated/reshape_c4.c: Regenerated.
         * generated/reshape_c8.c: Regenerated.
         * generated/reshape_i16.c: Regenerated.
         * generated/reshape_i4.c: Regenerated.
         * generated/reshape_i8.c: Regenerated.
         * generated/reshape_r10.c: Regenerated.
         * generated/reshape_r16.c: Regenerated.
         * generated/reshape_r4.c: Regenerated.
         * generated/reshape_r8.c: Regenerated.
diff mbox

Patch

Index: generated/reshape_c10.c
===================================================================
--- generated/reshape_c10.c	(Revision 245760)
+++ generated/reshape_c10.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_c16.c
===================================================================
--- generated/reshape_c16.c	(Revision 245760)
+++ generated/reshape_c16.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_c4.c
===================================================================
--- generated/reshape_c4.c	(Revision 245760)
+++ generated/reshape_c4.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_c8.c
===================================================================
--- generated/reshape_c8.c	(Revision 245760)
+++ generated/reshape_c8.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_i16.c
===================================================================
--- generated/reshape_i16.c	(Revision 245760)
+++ generated/reshape_i16.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_16 (gfc_array_i16 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_i4.c
===================================================================
--- generated/reshape_i4.c	(Revision 245760)
+++ generated/reshape_i4.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_4 (gfc_array_i4 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_i8.c
===================================================================
--- generated/reshape_i8.c	(Revision 245760)
+++ generated/reshape_i8.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_8 (gfc_array_i8 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_r10.c
===================================================================
--- generated/reshape_r10.c	(Revision 245760)
+++ generated/reshape_r10.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_r16.c
===================================================================
--- generated/reshape_r16.c	(Revision 245760)
+++ generated/reshape_r16.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_r4.c
===================================================================
--- generated/reshape_r4.c	(Revision 245760)
+++ generated/reshape_r4.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: generated/reshape_r8.c
===================================================================
--- generated/reshape_r8.c	(Revision 245760)
+++ generated/reshape_r8.c	(Arbeitskopie)
@@ -232,6 +232,11 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)
Index: intrinsics/reshape_generic.c
===================================================================
--- intrinsics/reshape_generic.c	(Revision 245760)
+++ intrinsics/reshape_generic.c	(Arbeitskopie)
@@ -158,6 +158,10 @@  reshape_internal (parray *ret, parray *source, sha
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
+      /* sdim is always > 0; this lets the compiler optimize more and
+         avoids a warning.  */
+      GFC_ASSERT(sdim>0);
+
       for (n = 0; n < sdim; n++)
 	{
 	  index_type se;
Index: libgfortran.h
===================================================================
--- libgfortran.h	(Revision 245760)
+++ libgfortran.h	(Arbeitskopie)
@@ -111,7 +111,12 @@  typedef off_t gfc_offset;
 #define likely(x)       __builtin_expect(!!(x), 1)
 #define unlikely(x)     __builtin_expect(!!(x), 0)
 
+/* This macro can be used to annotate conditions which we know to
+   be true, so that the compiler can optimize based on the condition.  */
 
+#define GFC_ASSERT(EXPR)                                                \
+  ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
+
 /* Make sure we have ptrdiff_t. */
 #ifndef HAVE_PTRDIFF_T
 typedef intptr_t ptrdiff_t;
Index: m4/reshape.m4
===================================================================
--- m4/reshape.m4	(Revision 245760)
+++ m4/reshape.m4	(Arbeitskopie)
@@ -236,6 +236,11 @@  reshape_'rtype_ccode` ('rtype` * const restrict re
     }
 
   sdim = GFC_DESCRIPTOR_RANK (source);
+
+  /* sdim is always > 0; this lets the compiler optimize more and
+   avoids a warning.  */
+  GFC_ASSERT(sdim>0);
+
   ssize = 1;
   sempty = 0;
   for (n = 0; n < sdim; n++)