We use getExtractWithExtendCost to calculate the cost of extractelement and s|zext together when computing the extract cost after vectorization, but we calculate the cost of extractelement and s|zext separately when computing the scalar cost which is larger than it should be.
Could you regenerate test checks without your patch and without -instcombine first and commit as NFC? And after that generate these checks with your patch
I think you can use just GetElementPtr::classof here as a predicate. Also, it would be good to have negative test(s) for the situation where this should not work.
I tried, but I got this error when compiling
llvm/ADT/STLExtras.h:846:6: note: candidate template ignored: couldn't infer template argument 'UnaryPredicate'