Index: src/compiler/code-assembler.cc |
diff --git a/src/compiler/code-assembler.cc b/src/compiler/code-assembler.cc |
index 4844355abb08e61a694f9ae669e201477a21cf67..47669a6e5a5d512a550c207de1c23243956fad30 100644 |
--- a/src/compiler/code-assembler.cc |
+++ b/src/compiler/code-assembler.cc |
@@ -209,6 +209,10 @@ bool CodeAssembler::ToSmiConstant(Node* node, Smi*& out_value) { |
} |
bool CodeAssembler::ToIntPtrConstant(Node* node, intptr_t& out_value) { |
+ if (node->opcode() == IrOpcode::kBitcastWordToTaggedSigned || |
+ node->opcode() == IrOpcode::kBitcastWordToTagged) { |
+ node = node->InputAt(0); |
+ } |
IntPtrMatcher m(node); |
if (m.HasValue()) out_value = m.Value(); |
return m.HasValue(); |
@@ -269,6 +273,43 @@ Node* CodeAssembler::LoadStackPointer() { |
CODE_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_ASSEMBLER_BINARY_OP) |
#undef DEFINE_CODE_ASSEMBLER_BINARY_OP |
+Node* CodeAssembler::IntPtrAdd(Node* left, Node* right) { |
+ intptr_t left_constant; |
+ bool is_left_constant = ToIntPtrConstant(left, left_constant); |
+ intptr_t right_constant; |
+ bool is_right_constant = ToIntPtrConstant(right, right_constant); |
+ if (is_left_constant) { |
+ if (is_right_constant) { |
+ return IntPtrConstant(left_constant + right_constant); |
+ } |
+ if (left_constant == 0) { |
+ return right; |
+ } |
+ } else if (is_right_constant) { |
+ if (right_constant == 0) { |
+ return left; |
+ } |
+ } |
+ return raw_assembler()->IntPtrAdd(left, right); |
+} |
+ |
+Node* CodeAssembler::IntPtrSub(Node* left, Node* right) { |
+ intptr_t left_constant; |
+ bool is_left_constant = ToIntPtrConstant(left, left_constant); |
+ intptr_t right_constant; |
+ bool is_right_constant = ToIntPtrConstant(right, right_constant); |
+ if (is_left_constant) { |
+ if (is_right_constant) { |
+ return IntPtrConstant(left_constant - right_constant); |
+ } |
+ } else if (is_right_constant) { |
+ if (right_constant == 0) { |
+ return left; |
+ } |
+ } |
+ return raw_assembler()->IntPtrSub(left, right); |
+} |
+ |
Node* CodeAssembler::WordShl(Node* value, int shift) { |
return (shift != 0) ? raw_assembler()->WordShl(value, IntPtrConstant(shift)) |
: value; |