Commit 997ac19
authored
ZJIT: Remove redundant PatchPoints within basic blocks (ruby#16231)
Add a new optimization pass that deduplicates PatchPoint instructions
asserting the same invariant within a basic block when no intervening
instruction could invalidate it.
This is common in practice — e.g., `1 + 2 + 3` produces two identical
`PatchPoint MethodRedefined(Integer, +, cme)` because each `+` call
inserts one. The second is redundant since nothing between them can
redefine Integer#+.
The approach adds a `PatchPoint` leaf to the abstract heap DAG so the
effect system can distinguish instructions that could invalidate
invariants (writes to PatchPoint, e.g. Send/CCall) from those that
cannot (e.g. IncrCounter, Const). The pass maintains a HashSet of
seen invariants per block and skips duplicates, clearing the set when
an instruction writes to the PatchPoint heap.
Removed PatchPoints' orphaned Snapshot dependencies are cleaned up by
the subsequent DCE pass.
I added a new test with snapshots to `zjit/src/hir/tests.rs` in the first commit
so that you can see how the change affects it in the second commit:
ruby@88cf26b#diff-38be021d8d0035cca77d3eab5ccc530109e7832f4711a5beb4dfced7001787ae
closes Shopify#7791 parent 8e9eb69 commit 997ac19
6 files changed
Lines changed: 75 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
1237 | 1237 | | |
1238 | 1238 | | |
1239 | 1239 | | |
1240 | | - | |
| 1240 | + | |
1241 | 1241 | | |
1242 | | - | |
1243 | | - | |
| 1242 | + | |
| 1243 | + | |
1244 | 1244 | | |
1245 | 1245 | | |
1246 | 1246 | | |
| |||
5037 | 5037 | | |
5038 | 5038 | | |
5039 | 5039 | | |
| 5040 | + | |
| 5041 | + | |
| 5042 | + | |
| 5043 | + | |
| 5044 | + | |
| 5045 | + | |
| 5046 | + | |
| 5047 | + | |
| 5048 | + | |
| 5049 | + | |
| 5050 | + | |
| 5051 | + | |
| 5052 | + | |
| 5053 | + | |
| 5054 | + | |
| 5055 | + | |
| 5056 | + | |
| 5057 | + | |
| 5058 | + | |
| 5059 | + | |
| 5060 | + | |
| 5061 | + | |
| 5062 | + | |
5040 | 5063 | | |
5041 | 5064 | | |
5042 | 5065 | | |
| |||
5260 | 5283 | | |
5261 | 5284 | | |
5262 | 5285 | | |
| 5286 | + | |
| 5287 | + | |
5263 | 5288 | | |
5264 | 5289 | | |
5265 | 5290 | | |
| |||
5286 | 5311 | | |
5287 | 5312 | | |
5288 | 5313 | | |
| 5314 | + | |
5289 | 5315 | | |
5290 | 5316 | | |
5291 | 5317 | | |
| |||
8473 | 8499 | | |
8474 | 8500 | | |
8475 | 8501 | | |
8476 | | - | |
8477 | | - | |
8478 | 8502 | | |
8479 | 8503 | | |
8480 | 8504 | | |
| |||
8536 | 8560 | | |
8537 | 8561 | | |
8538 | 8562 | | |
8539 | | - | |
8540 | 8563 | | |
8541 | 8564 | | |
8542 | 8565 | | |
| |||
8545 | 8568 | | |
8546 | 8569 | | |
8547 | 8570 | | |
8548 | | - | |
8549 | 8571 | | |
8550 | 8572 | | |
8551 | 8573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | 118 | | |
120 | | - | |
121 | | - | |
122 | 119 | | |
123 | 120 | | |
124 | 121 | | |
| |||
147 | 144 | | |
148 | 145 | | |
149 | 146 | | |
150 | | - | |
151 | 147 | | |
152 | | - | |
153 | | - | |
154 | 148 | | |
155 | 149 | | |
156 | 150 | | |
| |||
3063 | 3057 | | |
3064 | 3058 | | |
3065 | 3059 | | |
3066 | | - | |
3067 | 3060 | | |
3068 | 3061 | | |
3069 | | - | |
3070 | 3062 | | |
3071 | 3063 | | |
3072 | | - | |
3073 | 3064 | | |
3074 | 3065 | | |
3075 | 3066 | | |
| |||
3098 | 3089 | | |
3099 | 3090 | | |
3100 | 3091 | | |
3101 | | - | |
3102 | 3092 | | |
3103 | 3093 | | |
3104 | 3094 | | |
| |||
5226 | 5216 | | |
5227 | 5217 | | |
5228 | 5218 | | |
5229 | | - | |
5230 | 5219 | | |
5231 | 5220 | | |
5232 | 5221 | | |
| |||
5323 | 5312 | | |
5324 | 5313 | | |
5325 | 5314 | | |
5326 | | - | |
5327 | 5315 | | |
5328 | 5316 | | |
5329 | 5317 | | |
| |||
5420 | 5408 | | |
5421 | 5409 | | |
5422 | 5410 | | |
5423 | | - | |
5424 | 5411 | | |
5425 | 5412 | | |
5426 | 5413 | | |
| |||
7222 | 7209 | | |
7223 | 7210 | | |
7224 | 7211 | | |
7225 | | - | |
7226 | 7212 | | |
7227 | 7213 | | |
7228 | 7214 | | |
| |||
11514 | 11500 | | |
11515 | 11501 | | |
11516 | 11502 | | |
11517 | | - | |
11518 | 11503 | | |
11519 | 11504 | | |
11520 | 11505 | | |
| |||
12098 | 12083 | | |
12099 | 12084 | | |
12100 | 12085 | | |
12101 | | - | |
12102 | 12086 | | |
12103 | 12087 | | |
12104 | | - | |
12105 | 12088 | | |
12106 | 12089 | | |
12107 | 12090 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
27 | 62 | | |
28 | 63 | | |
29 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
| |||
0 commit comments