[PATCH]: Constant fold comparisons against UINT_MAX
Roger Sayle
roger@eyesopen.com
Mon Jan 21 23:23:00 GMT 2002
> Actually, you should be able to make use of TYPE_MAX_VALUE here. Try
> else if (TREE_UNSIGNED (TREE_TYPE (arg1))
> && tree_int_cst_equal (TYPE_MAX_VALUE (TREE_TYPE (arg1)),
> arg1))
Yep, that works and makes for a significantly shorter patch. I've
tested this improved version with "make bootstrap" and "make -k check"
on i686-pc-linux-gnu with no new regressions. I've also checked
that it solves PR opt/3640 by examining the output from "-da" and "-S".
I've taken the liberty of adding you as co-author, I hope that's OK.
Is this a suitable fix for mainline and to close PR opt/3640?
2002-01-21 Roger Sayle <roger@eyesopen.com>
Richard Henderson <rth@redhat.com>
* fold-const.c (fold): Optimize unsigned comparisons against
UINT_MAX (and similar unsigned constants). Fixes PR opt/3640.
*** gcc/gcc/fold-const.c Sun Dec 16 21:19:08 2001
--- patch8b/gcc/fold-const.c Mon Jan 21 21:04:26 2002
***************
*** 1,6 ****
/* Fold a constant sub-tree into a single node for C-compiler
Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
! 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GCC.
--- 1,6 ----
/* Fold a constant sub-tree into a single node for C-compiler
Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
! 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GCC.
*************** fold (expr)
*** 6753,6758 ****
--- 6753,6783 ----
default:
break;
}
+
+ else if (TREE_UNSIGNED (TREE_TYPE (arg1))
+ && tree_int_cst_equal (TYPE_MAX_VALUE (TREE_TYPE (arg1)),
+ arg1))
+ switch (TREE_CODE (t))
+ {
+ case GT_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_zero_node),
+ arg0);
+ case GE_EXPR:
+ TREE_SET_CODE (t, EQ_EXPR);
+ break;
+
+ case LE_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_one_node),
+ arg0);
+ case LT_EXPR:
+ TREE_SET_CODE (t, NE_EXPR);
+ break;
+
+ default:
+ break;
+ }
}
}
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-438-3470
More information about the Gcc-patches
mailing list