Does anything depend on reg2mem?

According to the documentation,

This file demotes all registers to memory references. It is intended to be the inverse of mem2reg. By converting to load instructions, the only values live across basic blocks are alloca instructions and load instructions before phi nodes. It is intended that this should make CFG hacking much easier. To make later hacking easier, the entry block is split into two, such that all introduced alloca instructions (and nothing else) are in the entry block.

It does make sense that converting everything back to memory references, would make CFG hacking easier. For example, simplifycfg would have an easier job if it requires reg2mem to have been run first.

Does simplifycfg, or any other pass, actually have a ‘reg2mem must have been run first’ dependency?

I looked into this back when we were working on Windows EH around four years ago, and at the time, so far as I could tell, no, nothing depends on reg2mem. I asked Dan Gohman about it at the time, and he said that essentially SSAUpdater was introduced and rolled out across the codebase to address these CFG manipulation use cases properly.

I believe there may exist passes that call into reg2mem helper functions to demote specific values into memory across certain operations such as setjmp, for example. Parts of the code may still be in use, but IMO the pass can be deleted.

The web is full of scripts and descriptions that tell you to run reg2mem.

If we delete it we will get regular emails that things don't work anymore.
That said, if we introduce an alias reg2mem -> SROA, we should be fine.

~ Johannes

The web is full of scripts and descriptions that tell you to run reg2mem.

If we delete it we will get regular emails that things don't work anymore.
That said, if we introduce an alias reg2mem -> SROA, we should be fine.

Note that reg2mem is an opposite transform to that of SROA/mem2reg.

NACK to the removal, unless we also remove all of the functionality
that said pass uses, otherwise we are just reducing test coverage,

~ Johannes

Roman

The web is full of scripts and descriptions that tell you to run reg2mem.

If we delete it we will get regular emails that things don't work anymore.
That said, if we introduce an alias reg2mem -> SROA, we should be fine.

Note that reg2mem is an opposite transform to that of SROA/mem2reg.

Ups, misread. Need more or less coffee.