This also moves some code to a new patterns file. Differential Revision: https://reviews.llvm.org/D112575