Commit fa3a17e
Use sp for addressing locals when we can
Summary:
Take 2 of D114808854. The underlying issue here was actually manifested by the addition of D116050159 but the fix is here. For store pair if we can't encode the store in the offset that store pair supports we could emit two stores instead. We actually weren't properly using `ptr_offset` in the existing code path here so technically this could end up with a failure to compile. D114808854 made us use `getPairScratchPtr` which will handle large offsets properly. But that uses the scratch register and postalloc could have introduced the use of the scratch register as well! This causes us to generate code like:
```
sub x13, fp, #520
str x13, [x13] # we just stored the wrong thing here
```
This only gets hit when we actually start hitting more load pairs/store pairs on large stack references.
So there's a fix here so that instead of emitting: sub, str, sub, str we now do sub, stp which is an improvement in our code gen. In D116050159 we'll disallow the optimization when the value involves a scratch register.
Currently we always use `fp` for addressing variables on the stack. But if we use `sp` we can get to a wider range of variables more efficiently. This switches us over to doing that when it's safe to do so - usually we can track the stack pointer but in the case of generators we replace fp with the generators memory so we can't track it there.
Note there's an assumption here that we're not being insane with our stack allocation - e.g. we don't have one block modifying the stack state and transferring control to another block. That's true today and is likely to always be true. It would generally be hard to make arbitrary changes to the stack across multiple control flow paths. But if we ever needed to do that for some reason we could reset the known stack offset and just lose the optimization.
This will also let us use stp more in a subsequent diff.
Reviewed By: yoney
Differential Revision: D116050156
fbshipit-source-id: bf063b84cd62aacc1d9fad94b9bfbfb01b6021bf1 parent 4b56028 commit fa3a17e
5 files changed
Lines changed: 212 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
| |||
0 commit comments