This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Add missing test for reorder_operands_p
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Apr 2004 11:54:32 -0700 (MST)
- Subject: [Committed] Add missing test for reorder_operands_p
Whilst without internet connectivity last week, I came across the
following minor issue. The transformation of "(-A)+B" into "B-A" in
fold wasn't checking reorder_operands_p. This could potentially cause
evaluation order problems for Java.
The following patch was tested on i686-pc-linux-gnu with a full bootstrap,
all languages except treelang, and regression tested with no new failures.
Committed to mainline as obvious.
2004-04-03 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold) <PLUS_EXPR>: Guard (-A)+B -> B-A transformation
with reorder_operands_p.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.365
diff -c -3 -p -r1.365 fold-const.c
*** fold-const.c 1 Apr 2004 22:30:09 -0000 1.365
--- fold-const.c 3 Apr 2004 03:18:01 -0000
*************** fold (tree expr)
*** 5861,5869 ****
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (MINUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
/* (-A) + B -> B - A */
! if (TREE_CODE (arg0) == NEGATE_EXPR)
return fold (build (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
! else if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return non_lvalue (fold_convert (type, arg0));
--- 5861,5870 ----
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (MINUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
/* (-A) + B -> B - A */
! if (TREE_CODE (arg0) == NEGATE_EXPR
! && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
return fold (build (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
! if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return non_lvalue (fold_convert (type, arg0));
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833