diff options
author | Thomas Koenig <Thomas.Koenig@online.de> | 2006-02-28 11:12:22 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2006-02-28 11:12:22 +0000 |
commit | 8cd25827df5714010f0b16654765843634e53950 (patch) | |
tree | 8c94267614491656dfbdcdda6ad7e1741238b921 /gcc/fortran/trans-intrinsic.c | |
parent | b7ded1e0c5667fee48321f1e5c367e2eda964359 (diff) | |
download | gcc-8cd25827df5714010f0b16654765843634e53950.zip gcc-8cd25827df5714010f0b16654765843634e53950.tar.gz gcc-8cd25827df5714010f0b16654765843634e53950.tar.bz2 |
trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc): If the mask expression exists and has rank 0...
2006-02-28 Thomas Koenig <Thomas.Koenig@online.de>
* trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc):
If the mask expression exists and has rank 0, enclose the
generated loop in an "if (mask)". Put the default
initialization into the else branch.
2006-02-28 Thomas Koenig <Thomas.Koenig@online.de>
* scalar_mask_1.f90: Add tests for maxloc with scalar mask.
From-SVN: r111562
Diffstat (limited to 'gcc/fortran/trans-intrinsic.c')
-rw-r--r-- | gcc/fortran/trans-intrinsic.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 21477b1..f58a596 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -1567,9 +1567,11 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op) stmtblock_t body; stmtblock_t block; stmtblock_t ifblock; + stmtblock_t elseblock; tree limit; tree type; tree tmp; + tree elsetmp; tree ifbody; tree cond; gfc_loopinfo loop; @@ -1602,7 +1604,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op) actual = actual->next->next; gcc_assert (actual); maskexpr = actual->expr; - if (maskexpr) + if (maskexpr && maskexpr->rank != 0) { maskss = gfc_walk_expr (maskexpr); gcc_assert (maskss != gfc_ss_terminator); @@ -1712,8 +1714,39 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op) gfc_trans_scalarizing_loops (&loop, &body); - gfc_add_block_to_block (&se->pre, &loop.pre); - gfc_add_block_to_block (&se->pre, &loop.post); + /* For a scalar mask, enclose the loop in an if statement. */ + if (maskexpr && maskss == NULL) + { + gfc_init_se (&maskse, NULL); + gfc_conv_expr_val (&maskse, maskexpr); + gfc_init_block (&block); + gfc_add_block_to_block (&block, &loop.pre); + gfc_add_block_to_block (&block, &loop.post); + tmp = gfc_finish_block (&block); + + /* For the else part of the scalar mask, just initialize + the pos variable the same way as above. */ + + gfc_init_block (&elseblock); + + elsetmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, + loop.from[0], gfc_index_one_node); + cond = fold_build2 (GE_EXPR, boolean_type_node, + loop.to[0], loop.from[0]); + elsetmp = fold_build3 (COND_EXPR, gfc_array_index_type, cond, + loop.from[0], elsetmp); + gfc_add_modify_expr (&elseblock, pos, elsetmp); + elsetmp = gfc_finish_block (&elseblock); + + tmp = build3_v (COND_EXPR, maskse.expr, tmp, elsetmp); + gfc_add_expr_to_block (&block, tmp); + gfc_add_block_to_block (&se->pre, &block); + } + else + { + gfc_add_block_to_block (&se->pre, &loop.pre); + gfc_add_block_to_block (&se->pre, &loop.post); + } gfc_cleanup_loop (&loop); /* Return a value in the range 1..SIZE(array). */ |