-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 Feature Request
Given the following code (brought up by @georgemitenkov ):
t1 = expensive();
if c {
use(t1); // t1 is only used here
}use(t1) is not always executed. Thus, by moving t1 = expensive() under if will optimize the execution when c is false. This is a typical case of code sinking.
Comment by @vineethk:
For this to be safe, either:
- expensive() has to be pure
- or all code following it has to be pure until the point of usage
For this code motion to be advantageous:
- we need a stack-machine cost model to show us that code motion does not cause increase in code size (what if there were multiple uses in multiple branches, etc)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
🆕 New