diff options
| author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-08 16:41:18 +0000 |
|---|---|---|
| committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-02-08 16:41:18 +0000 |
| commit | 0b4337472ae18e4d89e9a56683fb98541df101a0 (patch) | |
| tree | 75e0d7456cf8fa5760ed4e45b9344dabaa89e88e /gcc/fortran/trans-stmt.c | |
| parent | c8a78da7c5712909dc6ba58444c4de5ce23773e5 (diff) | |
| download | ppe42-gcc-0b4337472ae18e4d89e9a56683fb98541df101a0.tar.gz ppe42-gcc-0b4337472ae18e4d89e9a56683fb98541df101a0.zip | |
* trans-stmt.c (gfc_trans_forall_1): Optimize the cases where the
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
Diffstat (limited to 'gcc/fortran/trans-stmt.c')
| -rw-r--r-- | gcc/fortran/trans-stmt.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index daf68db4246..db92c02d3d4 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -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); |

