The non-copypasta patterns set up proper type materializations, which
revealed the need for helper patterns that eliminate materializations,
which due to the complexity of the test cases (e.g. control flow),
tickles this particular issue.
The observation is that TestBufferPlacementPreparationPass is a
"finalizing" bufferization pass. That is, it does a "full" conversion
and needs all the materializations gone. So we expose a new helper
populateBufferizeEliminateMaterializationsPatternsAndLegality for
setting that up. This helper will soon be merged into
populateWithBufferizeOpConversionPatterns (which will be renamed
populateBufferizeFinalizationPatterns), but for now remains separate.
Note: LinalgBufferizePass is currently "finalizing", but I didn't apply
this there because I'm in the process of making that pass
non-finalizing (I'm making the finalizing process much nicer,
so that each dialect doesn't need its own finalizing bufferization).
Should this pattern fail if the operand is not a memref? Instead of creating wrong IR?