This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Latest bit-field patch version
On Tue, Jul 06, 2004 at 03:26:54PM +0000, Joseph S. Myers wrote:
> The following regression is still present:
>
> > gcc.dg/tree-ssa/20030922-1.c - the known sort of tree-ssa problem with
> > useless type conversions not being optimized past (as the bit-field gets a
> > narrowed type, promoted to int for the switch, and the optimizers can't
> > see that this promoted value being known implies that the unpromoted value
> > is known).
Fixed thus.
Original patch approved.
r~
* tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): Look
through any value-preserving cast.
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.23
diff -c -p -d -r2.23 tree-ssa-dom.c
*** tree-ssa-dom.c 7 Jul 2004 20:16:00 -0000 2.23
--- tree-ssa-dom.c 7 Jul 2004 23:59:38 -0000
*************** simplify_switch_and_lookup_avail_expr (t
*** 2460,2474 ****
def = TREE_OPERAND (def, 1);
if (TREE_CODE (def) == NOP_EXPR)
{
def = TREE_OPERAND (def, 0);
to = TREE_TYPE (cond);
ti = TREE_TYPE (def);
! /* If we have an extension that preserves sign, then we
can copy the source value into the switch. */
! if (TYPE_UNSIGNED (to) == TYPE_UNSIGNED (ti)
! && TYPE_PRECISION (to) >= TYPE_PRECISION (ti)
! && is_gimple_val (def))
{
SWITCH_COND (stmt) = def;
ann->modified = 1;
--- 2460,2492 ----
def = TREE_OPERAND (def, 1);
if (TREE_CODE (def) == NOP_EXPR)
{
+ int need_precision;
+ bool fail;
+
def = TREE_OPERAND (def, 0);
+
+ #ifdef ENABLE_CHECKING
+ /* ??? Why was Jeff testing this? We are gimple... */
+ if (!is_gimple_val (def))
+ abort ();
+ #endif
+
to = TREE_TYPE (cond);
ti = TREE_TYPE (def);
! /* If we have an extension that preserves value, then we
can copy the source value into the switch. */
!
! need_precision = TYPE_PRECISION (ti);
! fail = false;
! if (TYPE_UNSIGNED (to) && !TYPE_UNSIGNED (ti))
! fail = true;
! else if (!TYPE_UNSIGNED (to) && TYPE_UNSIGNED (ti))
! need_precision += 1;
! if (TYPE_PRECISION (to) < need_precision)
! fail = true;
!
! if (!fail)
{
SWITCH_COND (stmt) = def;
ann->modified = 1;