The patch is to fix the performance problem described in https://llvm.org/bugs/show_bug.cgi?id=23163.
As described in the bug above, gep merging may have negative effect on performance, especially when the src of gep has multiple uses, so we want to make sure every target gep after the merging has lower cost than before. In the patch, we achieve it by requiring that the index values of the src and target geps to be merged are both constants.
The patch is performance neutral for spec2000 on x86 sandybridge. It improves google internal benchmarks by 0.6 on x86 sandybridge and 0.4 on x86 westmere in geomean.
This seems too conservative. In particular, in your comment you had mentioned the number of users.
What does a heuristic based on that give?