From 0ecda2ba70d65b613978d57e912b26617a6ee46d Mon Sep 17 00:00:00 2001 From: jb Date: Tue, 1 Dec 2009 18:32:37 +0000 Subject: [PATCH] PR fortran/42131 Sign test using ternary operator git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154876 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/trans-stmt.c | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 976061a..b39afe1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2009-12-01 Janne Blomqvist + + * PR fortran/42131 + * trans-stmt.c (gfc_trans_do): Sign test using ternary operator. + 2009-11-30 Janus Weil PR fortran/42053 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index e9f76a0..32c6efc 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1028,17 +1028,13 @@ gfc_trans_do (gfc_code * code) { tree pos, neg, step_sign, to2, from2, step2; - /* Calculate SIGN (1,step) */ + /* Calculate SIGN (1,step), as (step < 0 ? -1 : 1) */ - tmp = fold_build2 (RSHIFT_EXPR, type, step, - build_int_cst (type, - TYPE_PRECISION (type) - 1)); - - tmp = fold_build2 (MULT_EXPR, type, tmp, - build_int_cst (type, 2)); - - step_sign = fold_build2 (PLUS_EXPR, type, tmp, - fold_convert (type, integer_one_node)); + tmp = fold_build2 (LT_EXPR, boolean_type_node, step, + build_int_cst (TREE_TYPE (step), 0)); + step_sign = fold_build3 (COND_EXPR, type, tmp, + build_int_cst (type, -1), + build_int_cst (type, 1)); tmp = fold_build2 (LT_EXPR, boolean_type_node, to, from); pos = fold_build3 (COND_EXPR, void_type_node, tmp, -- 2.7.4