This patch is to be applied on top of the recent 3-address patch (https://reviews.llvm.org/D60888). Without this, there were a dozen of tests that failed with D60888, but with this patch they do not.
TargetPassConfig::addPostRewrite() method and VirtRegMap argument to foldMemoryOperand() approved already on a separate patch by Quentin Colombet (https://reviews.llvm.org/D58923).
Statistics:
"regalloc - Number of folded stack accesses":
master: 17762
3-address patch without handling in foldMemoryOperand(): 14081
3-address patch + this patch without commutation: 15285
with commutation: 17395
"systemz-postrewrite - Number of copies inserted before folded mem ops."
with commuation: 9