Bug 244182 - JSC DFGFixup computes a wrong addSpeculation mode in DFGGraph::addImmediateShouldSpeculteInt32 when immediateValue is Double
Summary: JSC DFGFixup computes a wrong addSpeculation mode in DFGGraph::addImmediateSh...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-08-22 00:09 PDT by EntryHi
Modified: 2022-09-09 01:47 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description EntryHi 2022-08-22 00:09:29 PDT
var values = [0, 1, 2, 3, 4, -5];
function foo( arg) {
  let actual = 0.2 + ( arg | arg ) | 0
  print(actual)
} 
for (var i = 0; i < values.length; ++i) {
  foo( values[i]);
} 


With the above script as input to JSC, run JSC with the following parameters:
./jsc test.js --useConcurrentJIT=0 --jitPolicyScale=0

When the parameter passed to foo is -5, the correct result returned by foo should be -4, but JSC incorrectly returns -5.

We found that the problem lies in DFGFixupPhase. When handling ValueAdd node, it will first perform attemptToMakeIntegerAdd. In this step, 0.2 is first converted to 0, and 0 and -5 are added to get the result -5.
The correct case should be that 0.2 is added with -5 to get -4.8, and -4.8 is converted to an integer -4.

In the fixup phase, whether 0.2 is converted to 0 depends on the result of DFGGraph::addImmediateShouldSpeculateInt32, which incorrectly returns SpeculateInt32AndTruncateConstants mode. When immediateValue is Double, it should return DontSpeculateInt32.
Comment 1 Radar WebKit Bug Importer 2022-08-29 00:10:16 PDT
<rdar://problem/99264817>