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.