On Thu, 11 Oct 2012, Jan Hubicka wrote: > Hi, > this patch address problem I run into with strenghtened cunroll pass. I made > cunroll to use loop_max_iterations bounds into an account that makes us to > occasionally produce out of bounds loop accesses in loop like: > > for (i=0;i<n;i++) > { > <something> > if (test) > break > a[i]=1; > } > Here the constantly sized array appears in loop with multiple exits and we > then > in the last iteration produce out of bound array (since we need to duplicate > <something> and tree-ssa-vrp warns. > > I think this is more generic problem (though appearing rarely): as soon as we > specialize the code, we can no longer warn about out of bounds accesses when > we > prove array ref to be constant. We have no idea if this code path will > execute > in practice. > > Seems resonable? I think similar problems can be constructed by inlining, > too. > Regtested/bootstrapped x86_64-linux.
No, I don't think this is reasonable. There are other PRs for this as well, btw. The array-bounds warning in VRP needs to be conditional if the path to it isn't always executed, too (thus a may-be warning). Richard. > Honza > > * tree-cfg.c (gimple_duplicate_bb): Drop NO_WARNING on array refs. > Index: tree-cfg.c > =================================================================== > *** tree-cfg.c (revision 192360) > --- tree-cfg.c (working copy) > *************** gimple_duplicate_bb (basic_block bb) > *** 5504,5509 **** > --- 5504,5519 ---- > if (lhs && TREE_CODE (lhs) != SSA_NAME) > { > tree base = get_base_address (lhs); > + tree op = lhs; > + > + /* Silence the array bounds warning. After specializing the code we > + no longer know if the particular code path can execute at runtime. > */ > + while (handled_component_p (op)) > + { > + if (TREE_CODE (op) == ARRAY_REF) > + TREE_NO_WARNING (op) = 1; > + op = TREE_OPERAND (op, 0); > + } > if (base > && (TREE_CODE (base) == VAR_DECL > || TREE_CODE (base) == RESULT_DECL) > *************** gimple_duplicate_bb (basic_block bb) > *** 5514,5519 **** > --- 5521,5539 ---- > || !DECL_HAS_VALUE_EXPR_P (base))) > DECL_NONSHAREABLE (base) = 1; > } > + > + /* Silence the array bounds warning. After specializing the code we > + no longer know if the particular code path can execute at runtime. > */ > + if (gimple_code (stmt) == GIMPLE_ASSIGN) > + { > + tree op = gimple_assign_rhs1 (stmt); > + while (handled_component_p (op)) > + { > + if (TREE_CODE (op) == ARRAY_REF) > + TREE_NO_WARNING (op) = 1; > + op = TREE_OPERAND (op, 0); > + } > + } > > /* Create new names for all the definitions created by COPY and > add replacement mappings for each new name. */ > > -- Richard Biener <rguent...@suse.de> SUSE / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 GF: Jeff Hawn, Jennifer Guild, Felix Imend