------- Comment #19 from rguenth at gcc dot gnu dot org 2006-05-17 14:21 ------- if we are checking in scev_probably_wraps_p if the chrec does wrap in the target type we should _not_ use signed-types-don't-wrap as we do now:
/* After having set INIT_IS_MAX, we can return false: when not using wrapping arithmetic, signed types don't wrap. */ if (!flag_wrapv && !TYPE_UNSIGNED (type)) return false; but instead assert that on TREE_TYPE (base). So, the following is another try to fix the problem (allow mixed-type questions): Index: tree-ssa-loop-niter.c =================================================================== --- tree-ssa-loop-niter.c (revision 113852) +++ tree-ssa-loop-niter.c (working copy) @@ -1979,9 +1979,9 @@ scev_probably_wraps_p (tree type, tree b } *unknown_max = false; - base_plus_step = fold_build2 (PLUS_EXPR, type, base, step); - bpsps = fold_build2 (PLUS_EXPR, type, base_plus_step, step); - cps = compare_trees (base_plus_step, base); + base_plus_step = fold_convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (base), base, step)); + bpsps = fold_convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (base), base_plus_step, step)); + cps = compare_trees (base_plus_step, fold_convert (type, base)); cpsps = compare_trees (bpsps, base_plus_step); /* Check that the sequence is not wrapping in the first step: it @@ -1995,7 +1995,8 @@ scev_probably_wraps_p (tree type, tree b case -1: { tree extreme = upper_bound_in_type (type, TREE_TYPE (base)); - delta = fold_build2 (MINUS_EXPR, type, extreme, base); + delta = fold_build2 (MINUS_EXPR, type, extreme, + fold_convert (type, base)); step_abs = step; *init_is_max = false; break; @@ -2004,8 +2005,9 @@ scev_probably_wraps_p (tree type, tree b case 1: { tree extreme = lower_bound_in_type (type, TREE_TYPE (base)); - delta = fold_build2 (MINUS_EXPR, type, base, extreme); - step_abs = fold_build1 (NEGATE_EXPR, type, step); + delta = fold_build2 (MINUS_EXPR, type, + fold_convert (type, base), extreme); + step_abs = fold_convert (type, fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step)); *init_is_max = true; break; } @@ -2065,7 +2067,7 @@ scev_probably_wraps_p (tree type, tree b /* After having set INIT_IS_MAX, we can return false: when not using wrapping arithmetic, signed types don't wrap. */ - if (!flag_wrapv && !TYPE_UNSIGNED (type)) + if (!flag_wrapv && !TYPE_UNSIGNED (TREE_TYPE (base))) return false; unsigned_type = unsigned_type_for (type); -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27639