https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106365
--- Comment #10 from Kewen Lin <linkw at gcc dot gnu.org> --- (In reply to Richard Biener from comment #7) > Created attachment 53323 [details] > prototype > > I'm testing this - for .LEN_STORE you mainly have to compute pd.rhs_off, > pd.offset, pd.size and do a single > > return data->push_partial_def (pd, set, set, offseti, maxsizei); Thanks! Added the below diff and confirm it can make most of code optimized away and generate "return 285;". diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 0a16984d2ca..ea5b7c54f82 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -3228,6 +3228,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, return (void *)-1; tree mask = NULL_TREE; + tree len = NULL_TREE; switch (fn) { case IFN_MASK_STORE: @@ -3236,6 +3237,19 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, if (TREE_CODE (mask) != VECTOR_CST) return (void *)-1; break; + case IFN_LEN_STORE: + { + /* Extract the length without bias. */ + tree len0 = gimple_call_arg (call, 2); + len0 = vn_valueize (len0); + if (TREE_CODE (len0) != INTEGER_CST) + return (void *) -1; + tree bias = gimple_call_arg (call, 4); + len = fold_build2 (MINUS_EXPR, TREE_TYPE (len0), len0, bias); + /* Bias is either 0 or -1, biased length should be constant. */ + gcc_assert (TREE_CODE (len) == INTEGER_CST); + break; + } default: return (void *)-1; } @@ -3311,6 +3325,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, offseti, maxsizei); } } + else if (len) + { + pd.rhs_off = 0; + pd.offset = offset2i; + pd.size = tree_to_uhwi (len) * elsz; + if (ranges_known_overlap_p (offset, maxsize, pd.offset, + pd.size)) + return data->push_partial_def (pd, set, set, offseti, + maxsizei); + } else gcc_unreachable (); return NULL; But it still keeps the .LEN_STORE there: int foo () { int a[10]; <bb 2> [local count: 97603129]: .LEN_STORE (&MEM <int[10]> [(void *)&a + 32B], 128B, 8, { 64, 0, 0, 0, 81, 0, 0, 0, 100, 0, 0, 0, 121, 0, 0, 0 }, 0); a ={v} {CLOBBER(eol)}; return 285; } btw, the latest commit "Add alias disambiguation for vectorizer load/store IFNs" has been applied.