llvm PeepholeOptimizer + optimizeLoadInstr question

Hello Lang,

PeepholeOptimizer allows backend to provide optimizeLoadInstr function to fold memory-load operand.

But it doesn’t work for folding load operand into store instruction (combine into memory-to-memory instruction).
It is rare case, but some backends have such instructions (like SystemZ MVC).

It doesn’t work because “FoldAsLoadDefCandidates.clear()” occurs too early, before current instruction “optimizeLoadInstr” check.

Could “FoldAsLoadDefCandidates.clear()” be moved later?

After “!isLoadFoldable(…) && !FoldAsLoadDefCandidates.empty()” condition check.

Hi Andrew,

Is this still an open question? I took a quick look at the code and I think the change you’re proposing makes sense. If you’d like to pursue this, I recommend posting a patch for review.