Created attachment 23680 [details] Input & output test/Transforms/LoadStoreVectorizer/X86/vectorize-i8-nested-add.ll 's ld_v4i8_add_nuw vectorizes a sequence of loads, which is illegal. https://godbolt.org/z/NzK5oY (the attached file contains this input/output) Counter example: if v0 and v1 is 0, nuw is never triggered, but the offsets aren't still consecutive. https://alive2.llvm.org/ce/z/4nZKBs This can happen when a program has an allocation larger than 4G.
I briefly looked at Vectorizer::lookThroughComplexAddresses . I think what's happening is that it's using getSExtValue() incorrectly: essentially, it's accidentally treating "zext(x+c)" as if it were "zext(x)+sext(c)", as opposed to "zext(x)+zext(c)". That throws off the rest of the math.