<?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>196911</bug_id>
          
          <creation_ts>2019-04-15 00:28:04 -0700</creation_ts>
          <short_desc>DFG IntegerRangeOptimizationPhase fails to optimize the situation when ArithAdd node&apos;s second child is a negative constant.</short_desc>
          <delta_ts>2019-04-15 15:15:43 -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>Safari 12</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>jundong.xjd</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fpizlo</cc>
    
    <cc>jundong.xjd</cc>
    
    <cc>keith_miller</cc>
    
    <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1527147</commentid>
    <comment_count>0</comment_count>
    <who name="">jundong.xjd</who>
    <bug_when>2019-04-15 00:28:04 -0700</bug_when>
    <thetext>In DFGIntegerRangeOptimizationPhase, the `executeNode` function fails to correctly deal with ArithAdd node when node&apos;s second child is a negative constant.
```
case ArithAdd: {
            ...
            
            int offset = node-&gt;child2()-&gt;asInt32();
            
            ...
            
            
            if (offset &lt; 0 &amp;&amp; offset != std::numeric_limits&lt;int&gt;::min()) {
                // If we have &quot;add: @value - 1&quot; then we know that @value &gt;= min + 1, i.e. that
                // @value &gt; min.
                if (!sumOverflows&lt;int&gt;(std::numeric_limits&lt;int&gt;::min(), offset, -1)) { &lt;-- this line definitely returns false because intMin plus two negative value definitely overflows!
                    setRelationship(
                        Relationship::safeCreate(
                            node-&gt;child1().node(), m_zero, Relationship::GreaterThan,
                            std::numeric_limits&lt;int&gt;::min() + offset - 1),
                        0);
                }
                
                // If we have &quot;add: @value + 1&quot; then we know that @add &lt;= max - 1, i.e. that
                // @add &lt; max.
                if (!sumOverflows&lt;int&gt;(std::numeric_limits&lt;int&gt;::max(), -offset, 1)) { &lt;-- intMax plus two positive value definitely overflows!
                    setRelationship(
                        Relationship(
                            node, m_zero, Relationship::LessThan,
                            std::numeric_limits&lt;int&gt;::max() - offset + 1),
                        0);
                }
            }
            break;
        }
```
If the offset is negative, we have add: @value - C, then we know @value &gt;= min + C, @value &gt; min + C - 1. C equals -offset, so final expression should be @value &gt; min - offset - 1.
If the offset is negative, we have add: @value - C, then we know @add &lt;= max - C, @add &lt; max - C + 1. C equals -offset, so final expression should be @add &lt; max + offset + 1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1527458</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-04-15 15:15:43 -0700</bug_when>
    <thetext>&lt;rdar://problem/49919886&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>