Skip to content

Commit

Permalink
[MERGE #5673 @sigatrev] oopjit branch fold BrTrue and BrFalse for tru…
Browse files Browse the repository at this point in the history
…e, false, and numbers.

Merge pull request #5673 from sigatrev:branchFold

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.
  • Loading branch information
sigatrev committed Sep 8, 2018
2 parents e565611 + aef954a commit a3737b0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/Backend/GlobOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/Optimizer/testsimplepathbrfold.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 2 additions & 0 deletions test/PRE/pre1.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a3737b0

Please sign in to comment.