OSDN Git Service

* trans-stmt.c (gfc_trans_forall_1): Optimize the cases where the
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Feb 2007 16:41:18 +0000 (16:41 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Feb 2007 16:41:18 +0000 (16:41 +0000)
mask expression is a compile-time constant (".true." or ".false.").

* gfortran.dg/forall_8.f90: New test case.
* gfortran.dg/forall_9.f90: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121714 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/forall_8.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/forall_9.f90 [new file with mode: 0644]

index 27a236b..59636db 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-08  Roger Sayle  <roger@eyesopen.com>
+
+       * trans-stmt.c (gfc_trans_forall_1): Optimize the cases where the
+       mask expression is a compile-time constant (".true." or ".false.").
+
 2007-02-04  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        PR fortran/30611
index daf68db..db92c02 100644 (file)
@@ -2458,6 +2458,13 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
   gfc_saved_var *saved_vars;
   iter_info *this_forall;
   forall_info *info;
+  bool need_mask;
+
+  /* Do nothing if the mask is false.  */
+  if (code->expr
+      && code->expr->expr_type == EXPR_CONSTANT
+      && !code->expr->value.logical)
+    return build_empty_stmt ();
 
   n = 0;
   /* Count the FORALL index number.  */
@@ -2557,9 +2564,21 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
   info->nvar = nvar;
   info->size = size;
 
-  /* First we need to allocate the mask.  */
   if (code->expr)
     {
+      /* If the mask is .true., consider the FORALL unconditional.  */
+      if (code->expr->expr_type == EXPR_CONSTANT
+         && code->expr->value.logical)
+       need_mask = false;
+      else
+       need_mask = true;
+    }
+  else
+    need_mask = false;
+
+  /* First we need to allocate the mask.  */
+  if (need_mask)
+    {
       /* As the mask array can be very big, prefer compact boolean types.  */
       tree mask_type = gfc_get_logical_type (gfc_logical_kinds[0].kind);
       mask = allocate_temp_for_forall_nest (nested_forall_info, mask_type,
@@ -2583,7 +2602,7 @@ gfc_trans_forall_1 (gfc_code * code, forall_info * nested_forall_info)
 
   /* Copy the mask into a temporary variable if required.
      For now we assume a mask temporary is needed.  */
-  if (code->expr)
+  if (need_mask)
     {
       /* As the mask array can be very big, prefer compact boolean types.  */
       tree mask_type = gfc_get_logical_type (gfc_logical_kinds[0].kind);
index ce9a320..8454452 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-08  Roger Sayle  <roger@eyesopen.com>
+
+       * gfortran.dg/forall_8.f90: New test case.
+       * gfortran.dg/forall_9.f90: Likewise.
+
 2007-02-07  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/builtins-20.c: Add some -~ complex cases.
diff --git a/gcc/testsuite/gfortran.dg/forall_8.f90 b/gcc/testsuite/gfortran.dg/forall_8.f90
new file mode 100644 (file)
index 0000000..b06f302
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-O2 -fdump-tree-original" }
+  integer a(100)
+  forall (i=1:100,.true.)
+      a(i) = 0
+  end forall
+  end
+! { dg-final { scan-tree-dump-times "temp" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }
diff --git a/gcc/testsuite/gfortran.dg/forall_9.f90 b/gcc/testsuite/gfortran.dg/forall_9.f90
new file mode 100644 (file)
index 0000000..12084b1
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-O2 -fdump-tree-original" }
+  integer a(100)
+  forall (i=1:100,.false.)
+      a(i) = 0
+  end forall
+  end
+! { dg-final { scan-tree-dump-times "temp" 0 "original" } }
+! { dg-final { cleanup-tree-dump "original" } }