Selaa lähdekoodia

[MERGE #815] ShrU_A int type spec fix

Merge pull request #815 from pleath:shrurange
The int range for a ShrU_A result was using an int32 min/max. We detect ShrU_A whose result may not be an int32 (source may be negative, shift amount may be zero), but because the value type assigned to the result is 'Likely Int', we still use an int32 range. We could bail out on non-int32 result, or we could assign an 'Any Number' value type. I've gone with the latter, since there may be no operation downstream that is affected by the range. Benchmarks are flat.
Paul Leathers 10 vuotta sitten
vanhempi
sitoutus
a45862882a

+ 5 - 3
lib/Backend/GlobOpt.cpp

@@ -7303,9 +7303,11 @@ GlobOpt::ValueNumberDst(IR::Instr **pInstr, Value *src1Val, Value *src2Val)
             min1 < 0 &&
             IntConstantBounds(min2, max2).And_0x1f().Contains(0))
         {
-            // Src1 may be too large to represent as a signed int32, and src2 may be zero. Since the result can therefore be too
-            // large to represent as a signed int32, include Number in the value type.
-            return CreateDstUntransferredValue(ValueType::GetNumberAndLikelyInt(true), instr, src1Val, src2Val);
+            // Src1 may be too large to represent as a signed int32, and src2 may be zero. 
+            // Since the result can therefore be too large to represent as a signed int32, 
+            // include Number in the value type.
+            return CreateDstUntransferredValue(
+                ValueType::AnyNumber.SetCanBeTaggedValue(true), instr, src1Val, src2Val);
         }
 
         this->PropagateIntRangeBinary(instr, min1, max1, min2, max2, &newMin, &newMax);

+ 7 - 0
test/Optimizer/rlexe.xml

@@ -84,6 +84,13 @@
       <files>shru_peep.js</files>
     </default>
   </test>
+  <test>
+    <default>
+      <files>shru_intrange.js</files>
+      <compile-flags>-lic:1 -off:simplejit</compile-flags>
+      <baseline>shru_intrange.baseline</baseline>
+    </default>
+  </test>
   <test>
     <default>
       <files>test0.js</files>

+ 6 - 0
test/Optimizer/shru_intrange.baseline

@@ -0,0 +1,6 @@
+2147483647
+2147483649
+2147483649
+2147483647
+2147483649
+2147483649

+ 39 - 0
test/Optimizer/shru_intrange.js

@@ -0,0 +1,39 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+function test0() {
+    function leaf() {
+    }
+    var obj1 = {};
+    var func0 = function () {
+        WScript.Echo(a);
+    };
+    var func2 = function (argMath0) {
+        var __loopvar2 = 5;
+        for (; a < (argMath0 >>>= test0) ; a++) {
+            __loopvar2 += 2;
+            if (__loopvar2 >= 5 + 6) {
+                break;
+            }
+        }
+        func0();
+        return 65535;
+    };
+    obj1.method1 = func2;
+    var IntArr1 = [
+      -198980986,
+      476677656118063740
+    ];
+    var a = 2147483647;
+    var __loopvar0 = 5;
+    do {
+        __loopvar0 += 4;
+        if (__loopvar0 == 5 + 16) {
+            break;
+        }
+    } while (obj1.method1((IntArr1.pop())));
+}
+test0();
+test0();