https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100582
--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> --- On Mon, 17 May 2021, crazylht at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100582 > > --- Comment #3 from Hongtao.liu <crazylht at gmail dot com> --- > (In reply to Richard Biener from comment #2) > > First of all we fail to if-convert because we think > > > > iftmp.0_9 = VIEW_CONVERT_EXPR<unsigned char[32]>(a)[i_15]; > > tree could trap... > > > > which is because we're concerned about out-of-bound access of 'a' and treat > > this as a array-at-struct-end. > > The tripcount of loop is constant, and the compiler should be able to analyze > that a[i] is not out of bounds, can't scev or vrp helps here? Yes, it works with a fix I am testing right now (still the actual ranges recorded in the IL are [0, 32]). diff --git a/gcc/tree.c b/gcc/tree.c index 01eda553a65..8afba598eb5 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -12550,13 +12550,11 @@ array_at_struct_end_p (tree ref) || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) return true; - if (TREE_CODE (ref) == MEM_REF - && TREE_CODE (TREE_OPERAND (ref, 0)) == ADDR_EXPR) - ref = TREE_OPERAND (TREE_OPERAND (ref, 0), 0); - /* If the reference is based on a declared entity, the size of the array is constrained by its given domain. (Do not trust commons PR/69368). */ - if (DECL_P (ref) + ref = get_base_address (ref); + if (ref + && DECL_P (ref) && !(flag_unconstrained_commons && VAR_P (ref) && DECL_COMMON (ref)) && DECL_SIZE_UNIT (ref)