The bug was in building vector GEP before gather scatter.
Index of GEP may remain scalar if it is nit defined inside the loop. (isLoopInvariant() condition is not enough).
The patch fixes https://llvm.org/bugs/show_bug.cgi?id=27997.
You see a lot of insert/extract instructions inside the test. I'll optimize this in the next patch.
Better emphasize that:
we want to get a vector value for base and each index that's defined inside the loop, even if it is loop-invariant but wasn't hoisted out. Otherwise we want to keep them scalar.