Commit aa58053d authored by Hao Xu's avatar Hao Xu Committed by V8 LUCI CQ

[CSA] Load jump offset on the branch it is used in JumpIf Handler

Some of the JumpIf Bytecode Handlers will load the jump offset from
bytecode array or constant pool before checking whether the condition is
matched, and this jump offset is unused if the jump not actually happens.

This CL move the Load operations to the branch on which the condition is
matched.

Bug: v8:12431
Change-Id: I3cb2fa7447ee2a9cb514148efb605617f95b1b68
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3300994
Commit-Queue: Hao A Xu <hao.a.xu@intel.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78088}
parent ae6eb0e2
......@@ -1108,18 +1108,67 @@ void InterpreterAssembler::JumpConditional(TNode<BoolT> condition,
Dispatch();
}
void InterpreterAssembler::JumpConditionalByImmediateOperand(
TNode<BoolT> condition, int operand_index) {
Label match(this), no_match(this);
Branch(condition, &match, &no_match);
BIND(&match);
TNode<IntPtrT> jump_offset = Signed(BytecodeOperandUImmWord(operand_index));
Jump(jump_offset);
BIND(&no_match);
Dispatch();
}
void InterpreterAssembler::JumpConditionalByConstantOperand(
TNode<BoolT> condition, int operand_index) {
Label match(this), no_match(this);
Branch(condition, &match, &no_match);
BIND(&match);
TNode<IntPtrT> jump_offset =
LoadAndUntagConstantPoolEntryAtOperandIndex(operand_index);
Jump(jump_offset);
BIND(&no_match);
Dispatch();
}
void InterpreterAssembler::JumpIfTaggedEqual(TNode<Object> lhs,
TNode<Object> rhs,
TNode<IntPtrT> jump_offset) {
JumpConditional(TaggedEqual(lhs, rhs), jump_offset);
}
void InterpreterAssembler::JumpIfTaggedEqual(TNode<Object> lhs,
TNode<Object> rhs,
int operand_index) {
JumpConditionalByImmediateOperand(TaggedEqual(lhs, rhs), operand_index);
}
void InterpreterAssembler::JumpIfTaggedEqualConstant(TNode<Object> lhs,
TNode<Object> rhs,
int operand_index) {
JumpConditionalByConstantOperand(TaggedEqual(lhs, rhs), operand_index);
}
void InterpreterAssembler::JumpIfTaggedNotEqual(TNode<Object> lhs,
TNode<Object> rhs,
TNode<IntPtrT> jump_offset) {
JumpConditional(TaggedNotEqual(lhs, rhs), jump_offset);
}
void InterpreterAssembler::JumpIfTaggedNotEqual(TNode<Object> lhs,
TNode<Object> rhs,
int operand_index) {
JumpConditionalByImmediateOperand(TaggedNotEqual(lhs, rhs), operand_index);
}
void InterpreterAssembler::JumpIfTaggedNotEqualConstant(TNode<Object> lhs,
TNode<Object> rhs,
int operand_index) {
JumpConditionalByConstantOperand(TaggedNotEqual(lhs, rhs), operand_index);
}
TNode<WordT> InterpreterAssembler::LoadBytecode(
TNode<IntPtrT> bytecode_offset) {
TNode<Uint8T> bytecode =
......
......@@ -204,11 +204,33 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
void JumpIfTaggedEqual(TNode<Object> lhs, TNode<Object> rhs,
TNode<IntPtrT> jump_offset);
// Jump forward relative to the current bytecode by offest specified in
// operand |operand_index| if the word values |lhs| and |rhs| are equal.
void JumpIfTaggedEqual(TNode<Object> lhs, TNode<Object> rhs,
int operand_index);
// Jump forward relative to the current bytecode by offest specified from the
// constant pool if the word values |lhs| and |rhs| are equal.
// The constant's index is specified in operand |operand_index|.
void JumpIfTaggedEqualConstant(TNode<Object> lhs, TNode<Object> rhs,
int operand_index);
// Jump forward relative to the current bytecode by |jump_offset| if the
// word values |lhs| and |rhs| are not equal.
void JumpIfTaggedNotEqual(TNode<Object> lhs, TNode<Object> rhs,
TNode<IntPtrT> jump_offset);
// Jump forward relative to the current bytecode by offest specified in
// operand |operand_index| if the word values |lhs| and |rhs| are not equal.
void JumpIfTaggedNotEqual(TNode<Object> lhs, TNode<Object> rhs,
int operand_index);
// Jump forward relative to the current bytecode by offest specified from the
// constant pool if the word values |lhs| and |rhs| are not equal.
// The constant's index is specified in operand |operand_index|.
void JumpIfTaggedNotEqualConstant(TNode<Object> lhs, TNode<Object> rhs,
int operand_index);
// Updates the profiler interrupt budget for a return.
void UpdateInterruptBudgetOnReturn();
......@@ -345,6 +367,19 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
// JumpIfTaggedNotEqual.
void JumpConditional(TNode<BoolT> condition, TNode<IntPtrT> jump_offset);
// Jump forward relative to the current bytecode by offest specified in
// operand |operand_index| if the |condition| is true. Helper function for
// JumpIfTaggedEqual and JumpIfTaggedNotEqual.
void JumpConditionalByImmediateOperand(TNode<BoolT> condition,
int operand_index);
// Jump forward relative to the current bytecode by offest specified from the
// constant pool if the |condition| is true. The constant's index is specified
// in operand |operand_index|. Helper function for JumpIfTaggedEqualConstant
// and JumpIfTaggedNotEqualConstant.
void JumpConditionalByConstantOperand(TNode<BoolT> condition,
int operand_index);
// Save the bytecode offset to the interpreter frame.
void SaveBytecodeOffset();
// Reload the bytecode offset from the interpreter frame.
......
......@@ -1919,9 +1919,8 @@ IGNITION_HANDLER(JumpConstant, InterpreterAssembler) {
// will misbehave if passed arbitrary input values.
IGNITION_HANDLER(JumpIfTrue, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
CSA_DCHECK(this, IsBoolean(CAST(accumulator)));
JumpIfTaggedEqual(accumulator, TrueConstant(), relative_jump);
JumpIfTaggedEqual(accumulator, TrueConstant(), 0);
}
// JumpIfTrueConstant <idx>
......@@ -1931,9 +1930,8 @@ IGNITION_HANDLER(JumpIfTrue, InterpreterAssembler) {
// and will misbehave if passed arbitrary input values.
IGNITION_HANDLER(JumpIfTrueConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
CSA_DCHECK(this, IsBoolean(CAST(accumulator)));
JumpIfTaggedEqual(accumulator, TrueConstant(), relative_jump);
JumpIfTaggedEqualConstant(accumulator, TrueConstant(), 0);
}
// JumpIfFalse <imm>
......@@ -1943,9 +1941,8 @@ IGNITION_HANDLER(JumpIfTrueConstant, InterpreterAssembler) {
// will misbehave if passed arbitrary input values.
IGNITION_HANDLER(JumpIfFalse, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
CSA_DCHECK(this, IsBoolean(CAST(accumulator)));
JumpIfTaggedEqual(accumulator, FalseConstant(), relative_jump);
JumpIfTaggedEqual(accumulator, FalseConstant(), 0);
}
// JumpIfFalseConstant <idx>
......@@ -1955,9 +1952,8 @@ IGNITION_HANDLER(JumpIfFalse, InterpreterAssembler) {
// and will misbehave if passed arbitrary input values.
IGNITION_HANDLER(JumpIfFalseConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
CSA_DCHECK(this, IsBoolean(CAST(accumulator)));
JumpIfTaggedEqual(accumulator, FalseConstant(), relative_jump);
JumpIfTaggedEqualConstant(accumulator, FalseConstant(), 0);
}
// JumpIfToBooleanTrue <imm>
......@@ -1966,10 +1962,10 @@ IGNITION_HANDLER(JumpIfFalseConstant, InterpreterAssembler) {
// referenced by the accumulator is true when the object is cast to boolean.
IGNITION_HANDLER(JumpIfToBooleanTrue, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Label if_true(this), if_false(this);
BranchIfToBooleanIsTrue(value, &if_true, &if_false);
BIND(&if_true);
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Jump(relative_jump);
BIND(&if_false);
Dispatch();
......@@ -1982,10 +1978,10 @@ IGNITION_HANDLER(JumpIfToBooleanTrue, InterpreterAssembler) {
// cast to boolean.
IGNITION_HANDLER(JumpIfToBooleanTrueConstant, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Label if_true(this), if_false(this);
BranchIfToBooleanIsTrue(value, &if_true, &if_false);
BIND(&if_true);
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Jump(relative_jump);
BIND(&if_false);
Dispatch();
......@@ -1997,12 +1993,12 @@ IGNITION_HANDLER(JumpIfToBooleanTrueConstant, InterpreterAssembler) {
// referenced by the accumulator is false when the object is cast to boolean.
IGNITION_HANDLER(JumpIfToBooleanFalse, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Label if_true(this), if_false(this);
BranchIfToBooleanIsTrue(value, &if_true, &if_false);
BIND(&if_true);
Dispatch();
BIND(&if_false);
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Jump(relative_jump);
}
......@@ -2013,12 +2009,12 @@ IGNITION_HANDLER(JumpIfToBooleanFalse, InterpreterAssembler) {
// cast to boolean.
IGNITION_HANDLER(JumpIfToBooleanFalseConstant, InterpreterAssembler) {
TNode<Object> value = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Label if_true(this), if_false(this);
BranchIfToBooleanIsTrue(value, &if_true, &if_false);
BIND(&if_true);
Dispatch();
BIND(&if_false);
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Jump(relative_jump);
}
......@@ -2028,8 +2024,7 @@ IGNITION_HANDLER(JumpIfToBooleanFalseConstant, InterpreterAssembler) {
// referenced by the accumulator is the null constant.
IGNITION_HANDLER(JumpIfNull, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
JumpIfTaggedEqual(accumulator, NullConstant(), relative_jump);
JumpIfTaggedEqual(accumulator, NullConstant(), 0);
}
// JumpIfNullConstant <idx>
......@@ -2038,8 +2033,7 @@ IGNITION_HANDLER(JumpIfNull, InterpreterAssembler) {
// pool if the object referenced by the accumulator is the null constant.
IGNITION_HANDLER(JumpIfNullConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
JumpIfTaggedEqual(accumulator, NullConstant(), relative_jump);
JumpIfTaggedEqualConstant(accumulator, NullConstant(), 0);
}
// JumpIfNotNull <imm>
......@@ -2048,8 +2042,7 @@ IGNITION_HANDLER(JumpIfNullConstant, InterpreterAssembler) {
// referenced by the accumulator is not the null constant.
IGNITION_HANDLER(JumpIfNotNull, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
JumpIfTaggedNotEqual(accumulator, NullConstant(), relative_jump);
JumpIfTaggedNotEqual(accumulator, NullConstant(), 0);
}
// JumpIfNotNullConstant <idx>
......@@ -2058,8 +2051,7 @@ IGNITION_HANDLER(JumpIfNotNull, InterpreterAssembler) {
// pool if the object referenced by the accumulator is not the null constant.
IGNITION_HANDLER(JumpIfNotNullConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
JumpIfTaggedNotEqual(accumulator, NullConstant(), relative_jump);
JumpIfTaggedNotEqualConstant(accumulator, NullConstant(), 0);
}
// JumpIfUndefined <imm>
......@@ -2068,8 +2060,7 @@ IGNITION_HANDLER(JumpIfNotNullConstant, InterpreterAssembler) {
// referenced by the accumulator is the undefined constant.
IGNITION_HANDLER(JumpIfUndefined, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
JumpIfTaggedEqual(accumulator, UndefinedConstant(), relative_jump);
JumpIfTaggedEqual(accumulator, UndefinedConstant(), 0);
}
// JumpIfUndefinedConstant <idx>
......@@ -2078,8 +2069,7 @@ IGNITION_HANDLER(JumpIfUndefined, InterpreterAssembler) {
// pool if the object referenced by the accumulator is the undefined constant.
IGNITION_HANDLER(JumpIfUndefinedConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
JumpIfTaggedEqual(accumulator, UndefinedConstant(), relative_jump);
JumpIfTaggedEqualConstant(accumulator, UndefinedConstant(), 0);
}
// JumpIfNotUndefined <imm>
......@@ -2088,8 +2078,7 @@ IGNITION_HANDLER(JumpIfUndefinedConstant, InterpreterAssembler) {
// referenced by the accumulator is not the undefined constant.
IGNITION_HANDLER(JumpIfNotUndefined, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
JumpIfTaggedNotEqual(accumulator, UndefinedConstant(), relative_jump);
JumpIfTaggedNotEqual(accumulator, UndefinedConstant(), 0);
}
// JumpIfNotUndefinedConstant <idx>
......@@ -2099,8 +2088,7 @@ IGNITION_HANDLER(JumpIfNotUndefined, InterpreterAssembler) {
// constant.
IGNITION_HANDLER(JumpIfNotUndefinedConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
JumpIfTaggedNotEqual(accumulator, UndefinedConstant(), relative_jump);
JumpIfTaggedNotEqualConstant(accumulator, UndefinedConstant(), 0);
}
// JumpIfUndefinedOrNull <imm>
......@@ -2144,7 +2132,6 @@ IGNITION_HANDLER(JumpIfUndefinedOrNullConstant, InterpreterAssembler) {
// referenced by the accumulator is a JSReceiver.
IGNITION_HANDLER(JumpIfJSReceiver, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Label if_object(this), if_notobject(this, Label::kDeferred), if_notsmi(this);
Branch(TaggedIsSmi(accumulator), &if_notobject, &if_notsmi);
......@@ -2152,6 +2139,7 @@ IGNITION_HANDLER(JumpIfJSReceiver, InterpreterAssembler) {
BIND(&if_notsmi);
Branch(IsJSReceiver(CAST(accumulator)), &if_object, &if_notobject);
BIND(&if_object);
TNode<IntPtrT> relative_jump = Signed(BytecodeOperandUImmWord(0));
Jump(relative_jump);
BIND(&if_notobject);
......@@ -2164,7 +2152,6 @@ IGNITION_HANDLER(JumpIfJSReceiver, InterpreterAssembler) {
// pool if the object referenced by the accumulator is a JSReceiver.
IGNITION_HANDLER(JumpIfJSReceiverConstant, InterpreterAssembler) {
TNode<Object> accumulator = GetAccumulator();
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Label if_object(this), if_notobject(this), if_notsmi(this);
Branch(TaggedIsSmi(accumulator), &if_notobject, &if_notsmi);
......@@ -2173,6 +2160,7 @@ IGNITION_HANDLER(JumpIfJSReceiverConstant, InterpreterAssembler) {
Branch(IsJSReceiver(CAST(accumulator)), &if_object, &if_notobject);
BIND(&if_object);
TNode<IntPtrT> relative_jump = LoadAndUntagConstantPoolEntryAtOperandIndex(0);
Jump(relative_jump);
BIND(&if_notobject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment