[Bug optimization/14669] [3.4/3.5 Regression] Wrong code with -O for enum values expression E4 <= t && t <= E6

roger at eyesopen dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 22 15:19:00 GMT 2004


------- Additional Comments From roger at eyesopen dot com  2004-03-22 15:19 -------
This is a variant of Kazu's patch that I'm bootstrapping and reg-testing:

         can do the comparison in the narrower type.  */
        else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
               && TREE_CODE (arg0) == NOP_EXPR
!              && (tem = get_unwidened (arg0, NULL_TREE)) != arg0)
!       {
!         /* We need to preserve the signedness of ordered comparisons.  */
!         if (code != EQ_EXPR && code != NE_EXPR
!             && TREE_UNSIGNED (TREE_TYPE (arg0))
!                != TREE_UNSIGNED (TREE_TYPE (tem)))
!           {
!             tree ntype = TREE_UNSIGNED (TREE_TYPE (arg0))
!                          ? lang_hooks.types.unsigned_type (TREE_TYPE (tem))
!                          : lang_hooks.types.signed_type (TREE_TYPE (tem));
!             tem = fold_convert (ntype, tem);
!             /* If preserving signedness rewidens the type, skip this
!                transformation to avoid unbounded recursion.  */
!             if (get_unwidened (tem, NULL_TREE) != tem)
!               tem = NULL_TREE;
!           }
!
!         if (tem
!             && (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
!             && (TREE_TYPE (t1) == TREE_TYPE (tem)
!                 || (TREE_CODE (t1) == INTEGER_CST
!                     && int_fits_type_p (t1, TREE_TYPE (tem)))))
!           return fold (build (code, type, tem,
!                               fold_convert (TREE_TYPE (tem), t1)));
!       }

        /* If this is comparing a constant with a MIN_EXPR or a MAX_EXPR of a
         constant, we can simplify it.  */


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14669



More information about the Gcc-bugs mailing list