diff options
Diffstat (limited to 'gcc/tree-ssa-loop-niter.c')
-rw-r--r-- | gcc/tree-ssa-loop-niter.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 3ebb0f9b45c..7134718c341 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2761,9 +2761,9 @@ static widest_int derive_constant_upper_bound (tree val) { enum tree_code code; - tree op0, op1; + tree op0, op1, op2; - extract_ops_from_tree (val, &code, &op0, &op1); + extract_ops_from_tree (val, &code, &op0, &op1, &op2); return derive_constant_upper_bound_ops (TREE_TYPE (val), op0, code, op1); } @@ -2776,7 +2776,7 @@ derive_constant_upper_bound_ops (tree type, tree op0, enum tree_code code, tree op1) { tree subtype, maxt; - widest_int bnd, max, mmax, cst; + widest_int bnd, max, cst; gimple stmt; if (INTEGRAL_TYPE_P (type)) @@ -2842,8 +2842,8 @@ derive_constant_upper_bound_ops (tree type, tree op0, /* OP0 + CST. We need to check that BND <= MAX (type) - CST. */ - mmax -= cst; - if (wi::ltu_p (bnd, max)) + widest_int mmax = max - cst; + if (wi::leu_p (bnd, mmax)) return max; return bnd + cst; @@ -3060,7 +3060,9 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, && get_range_info (orig_base, &min, &max) == VR_RANGE && wi::gts_p (high, max)) base = wide_int_to_tree (unsigned_type, max); - else if (TREE_CODE (base) != INTEGER_CST) + else if (TREE_CODE (base) != INTEGER_CST + && dominated_by_p (CDI_DOMINATORS, + loop->latch, gimple_bb (stmt))) base = fold_convert (unsigned_type, high); delta = fold_build2 (MINUS_EXPR, unsigned_type, base, extreme); step = fold_build1 (NEGATE_EXPR, unsigned_type, step); @@ -3075,7 +3077,9 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, && get_range_info (orig_base, &min, &max) == VR_RANGE && wi::gts_p (min, low)) base = wide_int_to_tree (unsigned_type, min); - else if (TREE_CODE (base) != INTEGER_CST) + else if (TREE_CODE (base) != INTEGER_CST + && dominated_by_p (CDI_DOMINATORS, + loop->latch, gimple_bb (stmt))) base = fold_convert (unsigned_type, low); delta = fold_build2 (MINUS_EXPR, unsigned_type, extreme, base); } |