Assembly and solidity optimizations

I noticed that if my code is using assembly, most optimization (even “inlining methods”) are disabled, unless all the assembly in the contract is considered “memory safe”

e.g. , even this block somewhere:

assembly { revert( add(reason,32), mload(reason) ) }  

Disables optimizations - unless I specifically mark it as “memory-safe” (which it is, for multiple reasons)

Is there a list of optimizations that are disabled when assembly is used?

Hi @drortirosh. Are you using via-ir or ‘legacy’ (i.e. default)?

Assuming that you’re using the via-ir pipeline, having assembly blocks that are not memory safe (i.e. have memory access within the block, but are not explicitly marked as memory safe) will prevent the ‘stack-to-memory’ mover, and will also not inline as aggressively (inlining is reduced to smaller functions than would be the case with memory safe blocks). All other optimizations are run, but of course, less aggressive inlining means that some optimizations will not take place that depending on said inlining. The reason for less aggressive inlining is to reduce the stack pressure (stack too deep) that could more easily happen with larger functions.

If you’re using legacy (default), then memory safety has no effect whatsoever.