This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize


2018-07-24 20:46 GMT+02:00 Janus Weil <janus@gcc.gnu.org>:
> 2018-07-23 23:05 GMT+02:00 Fritz Reese <fritzoreese@gmail.com>:
>> Otherwise looks OK.
>
> Thanks for the review. The new patch also disables the warnings from
> PR85599 if -ffrontend-optimize is not given, as noted by Dominique.
>
> The attached is what I'd like to commit (and is regtesting now), but
> I'll wait for further comments of course.

Regtesting showed one failure in inline_matmul_23, which is fixed by
adding -ffrontend-optimize. Updated patch attached.

Cheers,
Janus
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 262950)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -1793,13 +1793,17 @@ if @option{-ffrontend-optimize} is in effect.
 @opindex @code{frontend-optimize}
 @cindex Front-end optimization
 This option performs front-end optimization, based on manipulating
-parts the Fortran parse tree.  Enabled by default by any @option{-O}
-option.  Optimizations enabled by this option include inlining calls
-to @code{MATMUL}, elimination of identical function calls within
-expressions, removing unnecessary calls to @code{TRIM} in comparisons
-and assignments and replacing @code{TRIM(a)} with
-@code{a(1:LEN_TRIM(a))}.  It can be deselected by specifying
-@option{-fno-frontend-optimize}.
+parts the Fortran parse tree.  Enabled by default by any @option{-O} option
+except @option{-O0} and @option{-Og}.  Optimizations enabled by this option
+include:
+@itemize @bullet
+@item inlining calls to @code{MATMUL},
+@item elimination of identical function calls within expressions,
+@item removing unnecessary calls to @code{TRIM} in comparisons and assignments,
+@item replacing @code{TRIM(a)} with @code{a(1:LEN_TRIM(a))} and
+@item short-circuiting of logical operators (@code{.AND.} and @code{.OR.}).
+@end itemize
+It can be deselected by specifying @option{-fno-frontend-optimize}.
 
 @item -ffrontend-loop-interchange
 @opindex @code{frontend-loop-interchange}
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 262950)
+++ gcc/fortran/options.c	(working copy)
@@ -417,7 +417,7 @@ gfc_post_options (const char **pfilename)
      specified it directly.  */
 
   if (flag_frontend_optimize == -1)
-    flag_frontend_optimize = optimize;
+    flag_frontend_optimize = optimize && !optimize_debug;
 
   /* Same for front end loop interchange.  */
 
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 262950)
+++ gcc/fortran/resolve.c	(working copy)
@@ -3982,7 +3982,8 @@ resolve_operator (gfc_expr *e)
 	  else if (op2->ts.kind < e->ts.kind)
 	    gfc_convert_type (op2, &e->ts, 2);
 
-	  if (e->value.op.op == INTRINSIC_AND || e->value.op.op == INTRINSIC_OR)
+	  if (flag_frontend_optimize &&
+	    (e->value.op.op == INTRINSIC_AND || e->value.op.op == INTRINSIC_OR))
 	    {
 	      /* Warn about short-circuiting
 	         with impure function as second operand.  */
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(revision 262950)
+++ gcc/fortran/trans-expr.c	(working copy)
@@ -3348,12 +3348,12 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr * expr)
       return;
 
     case INTRINSIC_AND:
-      code = TRUTH_ANDIF_EXPR;
+      code = flag_frontend_optimize ? TRUTH_ANDIF_EXPR : TRUTH_AND_EXPR;
       lop = 1;
       break;
 
     case INTRINSIC_OR:
-      code = TRUTH_ORIF_EXPR;
+      code = flag_frontend_optimize ? TRUTH_ORIF_EXPR : TRUTH_OR_EXPR;
       lop = 1;
       break;
 
Index: gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90	(revision 262950)
+++ gcc/testsuite/gfortran.dg/actual_pointer_function_1.f90	(working copy)
@@ -17,7 +17,11 @@ CONTAINS
 
   logical function cp_logger_log(logger)
     TYPE(cp_logger_type), POINTER ::logger
-    cp_logger_log = associated (logger) .and. (logger%a .eq. 42)
+    if (associated (logger)) then
+      cp_logger_log = (logger%a .eq. 42)
+    else
+      cp_logger_log = .false.
+    end if
   END function
 
   FUNCTION cp_get_default_logger(v) RESULT(res)
Index: gcc/testsuite/gfortran.dg/inline_matmul_23.f90
===================================================================
--- gcc/testsuite/gfortran.dg/inline_matmul_23.f90	(revision 262950)
+++ gcc/testsuite/gfortran.dg/inline_matmul_23.f90	(working copy)
@@ -1,5 +1,5 @@
 ! { dg-do compile }
-! { dg-options "-Og -fcheck=bounds -fdump-tree-optimized" }
+! { dg-options "-Og -ffrontend-optimize -fcheck=bounds -fdump-tree-optimized" }
 ! Check that bounds checking is done only before the matrix
 ! multiplication.
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]