<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>203406</bug_id>
          
          <creation_ts>2019-10-25 04:37:51 -0700</creation_ts>
          <short_desc>Chakracore test max.js broken in armv7 and mips builds of JSC</short_desc>
          <delta_ts>2020-07-17 01:20:00 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>204457</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>204457</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paulo Matos">pmatos</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>guijemont</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>xan.lopez</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1583762</commentid>
    <comment_count>0</comment_count>
    <who name="Paulo Matos">pmatos</who>
    <bug_when>2019-10-25 04:37:51 -0700</bug_when>
    <thetext>A recent patch has broken armv7 - chakracore test max.js is giving incorrect results:
Bad behaviour:

$ jsc --useDFGJIT=true --forceEagerCompilation=true --repatchBufferingCountdown=6 JSTests/ChakraCore/test/jsc-lib.js JSTests/ChakraCore/test/Math/max.js
Infinity
-Infinity
opD = 0 , onD = 0 op = 0 , on = 0 , infp = Infinity , infn = -Infinity , infpD = Infinity , infnD = -Infinity
Math.max(+0.0, -0.0) 0
Check (1 / Math.max(+0.0, -0.0) &lt; 0)  - false 
done
Infinity
Infinity
-Infinity
-Infinity
undefined
undefined
NaN
1

Changing repatchBufferingCountdown to 7 gives the correct result:
$ jsc --useDFGJIT=true --forceEagerCompilation=true --repatchBufferingCountdown=7 JSTests/ChakraCore/test/jsc-lib.js JSTests/ChakraCore/test/Math/max.js
Infinity
-Infinity
opD = 0 , onD = 0 op = 0 , on = 0 , infp = Infinity , infn = -Infinity , infpD = Infinity , infnD = -Infinity
Math.max(+0.0, -0.0) 0
Check (1 / Math.max(+0.0, -0.0) &lt; 0)  - false 
done
Infinity
Infinity
Infinity
-Infinity
undefined
undefined
NaN
1


Notice the change from -Infinity to Infinity. Disabling DFGJit altogether also returns a good result.
$ jsc --useDFGJIT=false JSTests/ChakraCore/test/jsc-lib.js JSTests/ChakraCore/test/Math/max.js
Infinity
-Infinity
opD = 0 , onD = 0 op = 0 , on = 0 , infp = Infinity , infn = -Infinity , infpD = Infinity , infnD = -Infinity
Math.max(+0.0, -0.0) 0
Check (1 / Math.max(+0.0, -0.0) &lt; 0)  - false 
done
Infinity
Infinity
Infinity
-Infinity
undefined
undefined
NaN
1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1583774</commentid>
    <comment_count>1</comment_count>
    <who name="Paulo Matos">pmatos</who>
    <bug_when>2019-10-25 05:10:40 -0700</bug_when>
    <thetext>This seems to have been introduced at r251468. This hash introduced a build failure so it&apos;s difficult to confirm this is the case but once the build failure was fixed we had this test failure. Before this commit at r251467 the failure didn&apos;t exist.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1583839</commentid>
    <comment_count>2</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-10-25 08:57:53 -0700</bug_when>
    <thetext>CCing Keith and Mark in case this is immediately obvious to them, we&apos;ll have a look at it ASAP.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1584399</commentid>
    <comment_count>3</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-10-28 02:49:10 -0700</bug_when>
    <thetext>FWIW I see the same result on x86-64, the result changes from Infinity to -Infinity when enabling DFG (the repatchBufferingCountdown option has no effect).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1584430</commentid>
    <comment_count>4</comment_count>
      <attachid>382065</attachid>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-10-28 04:33:08 -0700</bug_when>
    <thetext>Created attachment 382065
Reduced testcase

I have reduced the test as much as I could. Seems it&apos;s relevant that there are a bunch of calls to Math.max before the bug (they can be any kind of calls, see the loop), and we need the previous foo() calls for the bug to be triggered. With no DFG the result is correct, with DFG we need the forceEagerCompilation parameters to see the bug:

niraikanai:~/git/WebKit%./WebKitBuild/Debug/bin/jsc --useDFGJIT=false JSTests/ChakraCore/test/jsc-lib.js ~/js/chakra.max.js                            
Infinity
Infinity
Infinity
niraikanai:~/git/WebKit%./WebKitBuild/Debug/bin/jsc --useDFGJIT=true --forceEagerCompilation=true JSTests/ChakraCore/test/jsc-lib.js ~/js/chakra.max.js
Infinity
Infinity
-Infinity</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1584563</commentid>
    <comment_count>5</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-10-28 13:03:55 -0700</bug_when>
    <thetext>Xan, in case you haven&apos;t already read this, check out: https://webkit.org/blog/6411/javascriptcore-csi-a-crash-site-investigation-story/

It details steps for debugging that you might find useful for this bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1584879</commentid>
    <comment_count>6</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-10-29 03:45:58 -0700</bug_when>
    <thetext>(In reply to Mark Lam from comment #5)
&gt; Xan, in case you haven&apos;t already read this, check out:
&gt; https://webkit.org/blog/6411/javascriptcore-csi-a-crash-site-investigation-
&gt; story/
&gt; 
&gt; It details steps for debugging that you might find useful for this bug.

Yes, thank you. Seems the bug is in DFG, with the eager compilation parameters some optimization pass must be triggered that generates slightly different (and buggy) DFG code. Almost all of it is identical though, so hopefully it won&apos;t be that hard to narrow it down.

(Also, I guess that means the bug probably is in the parts of the bytecode index patch that touch DFG classes)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1585588</commentid>
    <comment_count>7</comment_count>
    <who name="Guillaume Emont">guijemont</who>
    <bug_when>2019-10-30 15:34:12 -0700</bug_when>
    <thetext>As gardening, skipping test in Bug 203636 until this is fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1592321</commentid>
    <comment_count>8</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-11-21 02:30:26 -0800</bug_when>
    <thetext>Hey, a bit more info about this:

On x86-64 what&apos;s happening is that with the eager parameters we optimize the Math.max call, using what&apos;s in DFGSpeculativeJIT. For that platform the Math.max check is done with two comparisons, using the UCOMISD instruction. This instruction says 0.0 and -0.0 are equal, so the function just returns whatever value (which randomly turns out to be -0.0). This is wrong and gives us the -Infinity.

(I have not checked but I assume something similar is happening in other architectures)

A couple of questions:
- I assume the fact that the DFG Math.max cannot do this properly is intentional? The code has been there for a while. In that case I suppose the bug is that we end up there.
- If it&apos;s not intentional I guess we just figured out and need to change it.
- I really don&apos;t understand how the BytecodeIndex patch ended up causing this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1592416</commentid>
    <comment_count>9</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-11-21 09:51:39 -0800</bug_when>
    <thetext>(In reply to Xan Lopez from comment #8)
&gt; Hey, a bit more info about this:
&gt; 
&gt; On x86-64 what&apos;s happening is that with the eager parameters we optimize the
&gt; Math.max call, using what&apos;s in DFGSpeculativeJIT. For that platform the
&gt; Math.max check is done with two comparisons, using the UCOMISD instruction.
&gt; This instruction says 0.0 and -0.0 are equal, so the function just returns
&gt; whatever value (which randomly turns out to be -0.0). This is wrong and
&gt; gives us the -Infinity.
&gt; 
&gt; (I have not checked but I assume something similar is happening in other
&gt; architectures)
&gt; 
&gt; A couple of questions:
&gt; - I assume the fact that the DFG Math.max cannot do this properly is
&gt; intentional? The code has been there for a while. In that case I suppose the
&gt; bug is that we end up there.
&gt; - If it&apos;s not intentional I guess we just figured out and need to change it.
&gt; - I really don&apos;t understand how the BytecodeIndex patch ended up causing
&gt; this.

It is incorrect for ArithMax to treat -0 as the same as 0.  ArithMax is supposed to work like Math.max(), and https://www.ecma-international.org/ecma-262/6.0/#sec-math.max says that Math.max() should treat 0 &gt; -0.  Thanks for pointing out this issue.

We&apos;ll address this issue for x86_64 (and Apple supported ports) in https://bugs.webkit.org/show_bug.cgi?id=204457.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1592422</commentid>
    <comment_count>10</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2019-11-21 10:12:30 -0800</bug_when>
    <thetext>Great. I&apos;m still a bit puzzled about what changed for us to see this (incorrect) behavior now, since the code has been there for more than a year AFAICT. Probably would like to understand that to make sure there are no more lingering bugs here.

(I&apos;ll CC in the other bug in case the fix has architecture dependent bits)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1672428</commentid>
    <comment_count>11</comment_count>
    <who name="Xan Lopez">xan.lopez</who>
    <bug_when>2020-07-17 01:20:00 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 204457 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>382065</attachid>
            <date>2019-10-28 04:33:08 -0700</date>
            <delta_ts>2019-10-28 04:33:08 -0700</delta_ts>
            <desc>Reduced testcase</desc>
            <filename>chakra.max.js</filename>
            <type>text/javascript</type>
            <size>204</size>
            <attacher name="Xan Lopez">xan.lopez</attacher>
            
              <data encoding="base64">Zm9yICh2YXIgaT0wOyBpIDwgNjsgaSsrKQp7CiAgICBNYXRoLm1heChpKTsKfQoKLy9uZWdhdGl2
ZSB6ZXJvCmZ1bmN0aW9uIGZvbyhhLGIpCnsKICAgIHZhciBjID0gTWF0aC5tYXgoYSxiKTsKICAg
IHJldHVybiAxL2M7Cn0KV1NjcmlwdC5FY2hvKGZvbygtMCwwKSk7CldTY3JpcHQuRWNobyhmb28o
LTAsMCkpOwpXU2NyaXB0LkVjaG8oZm9vKDAsLTApKTsK
</data>

          </attachment>
      

    </bug>

</bugzilla>