Repository navigation
Commit 2eb82b3
committed
[JSC] Truncate int32 multiplications by narrow integer typed array loads
https://bugs.webkit.org/show_bug.cgi?id=327584
rdar://190051724
Reviewed by Marcus Plutowski.
When we have a code like `(i * data[i]) | 0` (the result is represented
as int32), it can be computed with a wrapping 32-bit multiply only if it
is exact as a double. This can be proven if one operand is within 2^22.
We can leverage Int8, Uint8, Uint8Clamped, Int16 or Uint16 array result
information to make it weaken.
Graph::isWithinPowerOfTwo bounds an integer typed array load by
|x| < 2^(8 * elementSize), so Int32 and Uint32 array loads also satisfy
the 2^32 bound which backwards propagation uses for additions.
This patch changes the pipeline,
1. Now fixup phase does not change ArithMode. We should weaken it in
strength reduction phase. This weakening is relying on backward
propagation, and it is fragile to do it at fixup phase.
2. Backwards propagation no longer folds "the product may be inexact"
into NodeBytecodeUsesAsNumber of ArithMul. Backwards propagation runs
once in the bytecode parser, before fixup decides array modes, and
node flags are only ever merged, so a bit set there could never be
withdrawn once a narrow typed array load proves the product exact.
Instead, Graph::mulProductIsExact computes exactness from the operands
wherever it is needed: Graph::mulShouldSpeculateInt32 uses it so that
an overflowing, inexact multiply is not speculated as Int32 (which
would keep OSR exiting), and strength reduction uses it, after fixup,
to relax the multiply to Arith::Unchecked.
Test: JSTests/stress/arith-mul-narrow-typed-array-load-truncation.js
* JSTests/stress/arith-mul-narrow-typed-array-load-truncation.js: Added.
(shouldBe):
(hash):
(referenceHash):
(mulByLoad):
(mulByLoadWithAnyIndex):
* Source/JavaScriptCore/dfg/DFGBackwardsPropagationPhase.cpp:
(JSC::DFG::BackwardsPropagationPhase::propagate):
(JSC::DFG::BackwardsPropagationPhase::isWithinPowerOfTwoForConstant): Deleted.
(JSC::DFG::BackwardsPropagationPhase::isWithinPowerOfTwo): Deleted.
* Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupArithDivInt32):
(JSC::DFG::FixupPhase::fixupArithDiv):
(JSC::DFG::FixupPhase::fixupArithMul):
(JSC::DFG::FixupPhase::fixupNode):
(JSC::DFG::FixupPhase::fixupToNumberOrToNumericOrCallNumberConstructor):
(JSC::DFG::FixupPhase::attemptToMakeIntegerAdd):
* Source/JavaScriptCore/dfg/DFGGraph.h:
* Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:
* Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp:
(JSC::DFG::StrengthReductionPhase::hasBytecodeUseFlags const):
(JSC::DFG::StrengthReductionPhase::relaxArithMode):
(JSC::DFG::StrengthReductionPhase::relaxDivOrModArithMode):
(JSC::DFG::StrengthReductionPhase::handleNode):
Canonical link: https://commits.webkit.org/324148@main1 parent 61f2d9a commit 2eb82b3
6 files changed
Lines changed: 282 additions & 171 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/dfg
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 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 | + | |
| 62 | + | |
| 63 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | 167 | | |
243 | 168 | | |
244 | 169 | | |
| |||
442 | 367 | | |
443 | 368 | | |
444 | 369 | | |
445 | | - | |
| 370 | + | |
446 | 371 | | |
447 | 372 | | |
448 | 373 | | |
| |||
457 | 382 | | |
458 | 383 | | |
459 | 384 | | |
460 | | - | |
| 385 | + | |
461 | 386 | | |
462 | 387 | | |
463 | 388 | | |
| |||
479 | 404 | | |
480 | 405 | | |
481 | 406 | | |
482 | | - | |
| 407 | + | |
483 | 408 | | |
484 | 409 | | |
485 | 410 | | |
| |||
502 | 427 | | |
503 | 428 | | |
504 | 429 | | |
505 | | - | |
| 430 | + | |
506 | 431 | | |
507 | 432 | | |
508 | 433 | | |
| |||
517 | 442 | | |
518 | 443 | | |
519 | 444 | | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
528 | 448 | | |
529 | 449 | | |
530 | 450 | | |
| |||
673 | 593 | | |
674 | 594 | | |
675 | 595 | | |
| 596 | + | |
676 | 597 | | |
677 | 598 | | |
678 | 599 | | |
| |||
0 commit comments