diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-28 11:12:22 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-28 11:12:22 +0000 |
commit | 622183f42869fa29ada44fbb6a203c927b6db43c (patch) | |
tree | 8c94267614491656dfbdcdda6ad7e1741238b921 /gcc/fortran | |
parent | 04f54a3a467d8574e44deabed571c40805c529fb (diff) | |
download | gcc-622183f42869fa29ada44fbb6a203c927b6db43c.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111562 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/trans-intrinsic.c | 39 |
2 files changed, 43 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b1172ba3fc9..8ed4f912b80 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +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-25 Thomas Koenig <Thomas.Koenig@online.de> PR fortran/23092 diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 21477b126d4..f58a5965299 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). */ |