Răsfoiți Sursa

oopjit branch fold BrTrue and BrFalse for true, false, and numbers.

allows the branch from ```if (a)``` to be folded when ```a``` is known to be true, false, or a number. This will also improve the IsIn optimization which currently replaces the instr with LdTrue when it is can be proven, and will improve any potential wins of allowing bools to be fixed fields.
Matt Gardner 7 ani în urmă
părinte
comite
aef954a77d

+ 24 - 4
lib/Backend/GlobOpt.cpp

@@ -6765,16 +6765,36 @@ GlobOpt::CanProveConditionalBranch(IR::Instr *instr, Value *src1Val, Value *src2
             break;
         }
 
-        if (func->IsOOPJIT() || !CONFIG_FLAG(OOPJITMissingOpts))
+        if (!src1Var)
         {
-            // TODO: OOP JIT, const folding
             return false;
         }
-        if (!src1Var)
+
+        // Set *result = (evaluates true) and negate it later for BrFalse
+        if (src1Var == reinterpret_cast<Js::Var>(this->func->GetScriptContextInfo()->GetTrueAddr()))
+        {
+            *result = true;
+        }
+        else if (src1Var == reinterpret_cast<Js::Var>(this->func->GetScriptContextInfo()->GetFalseAddr()))
+        {
+            *result = false;
+        }
+        else if (Js::TaggedInt::Is(src1Var))
+        {
+            *result = (src1Var != reinterpret_cast<Js::Var>(Js::AtomTag_IntPtr));
+        }
+#if FLOATVAR
+        else if (Js::JavascriptNumber::Is_NoTaggedIntCheck(src1Var))
+        {
+            double value = Js::JavascriptNumber::GetValue(src1Var);
+            *result = (!Js::JavascriptNumber::IsNan(value)) && (!Js::JavascriptNumber::IsZero(value));
+        }
+#endif
+        else
         {
             return false;
         }
-        *result = Js::JavascriptConversion::ToBoolean(src1Var, this->func->GetScriptContext());
+
         if (instr->m_opcode == Js::OpCode::BrFalse_A)
         {
             *result = !(*result);

+ 5 - 0
test/Optimizer/testsimplepathbrfold.baseline

@@ -46,10 +46,14 @@ Done bareq
 Done barnt
 
 false
+TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 1 from Block 3 to Block 4 in func barntbool
+TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 2 from Block 3 to Block 5 in func barntbool
 false
 Done barntbool
 
 true
+TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 1 from Block 3 to Block 5 in func barfalse
+TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 2 from Block 3 to Block 4 in func barfalse
 Done barfalse
 
 5
@@ -58,6 +62,7 @@ TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 1 from B
 Done iterator
 
 5
+TRACE PathDependentBranchFolding: Can prove retarget of branch in Block 1 from Block 3 to Block 5 in func iterator2
 5
 Done iterator2
 

+ 2 - 0
test/PRE/pre1.baseline

@@ -22,6 +22,7 @@ TestTrace fieldcopyprop [in landing pad]: function inlinee ( (#1.3), #4) inlined
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: count 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdRootFld field: Direction 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: FORWARD 
+TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: count 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdRootFld field: Direction 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: FORWARD 
 undefined
@@ -32,6 +33,7 @@ TestTrace fieldcopyprop [in landing pad]: function inlinee ( (#1.3), #4) inlined
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: count 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdRootFld field: Direction 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: FORWARD 
+TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: count 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdRootFld field: Direction 
 TestTrace fieldcopyprop: function inlinee ( (#1.3), #4) inlined caller function testInlined ( (#1.4), #5) opcode: LdFld field: FORWARD 
 2001