Commit 7aa82b97 authored by Kanghua Yu's avatar Kanghua Yu Committed by Commit Bot

[csa] Add more constant folding

This adds constant folding support for IntPtrEqual/Word{,32,64}{Equal,NotEqual}

Change-Id: I3afe2b5284baf077f03805d2cf48be33282d7bec
Reviewed-on: https://chromium-review.googlesource.com/1053162
Commit-Queue: Kanghua Yu <kanghua.yu@intel.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53768}
parent f1462b59
......@@ -396,9 +396,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
TNode<Int32T> HashSeed();
Node* IntPtrOrSmiConstant(int value, ParameterMode mode);
TNode<BoolT> BoolConstant(bool value) {
return value ? Int32TrueConstant() : Int32FalseConstant();
}
TNode<Smi> LanguageModeConstant(LanguageMode mode) {
return SmiConstant(static_cast<int>(mode));
}
......
......@@ -887,6 +887,25 @@ TNode<Word64T> CodeAssembler::Word64Sar(SloppyTNode<Word64T> left,
return UncheckedCast<Word64T>(raw_assembler()->Word64Sar(left, right));
}
#define CODE_ASSEMBLER_COMPARE(Name, ArgT, VarT, ToConstant, op) \
TNode<BoolT> CodeAssembler::Name(SloppyTNode<ArgT> left, \
SloppyTNode<ArgT> right) { \
VarT lhs, rhs; \
if (ToConstant(left, lhs) && ToConstant(right, rhs)) { \
return BoolConstant(lhs op rhs); \
} \
return UncheckedCast<BoolT>(raw_assembler()->Name(left, right)); \
}
CODE_ASSEMBLER_COMPARE(IntPtrEqual, WordT, intptr_t, ToIntPtrConstant, ==)
CODE_ASSEMBLER_COMPARE(WordEqual, WordT, intptr_t, ToIntPtrConstant, ==)
CODE_ASSEMBLER_COMPARE(WordNotEqual, WordT, intptr_t, ToIntPtrConstant, !=)
CODE_ASSEMBLER_COMPARE(Word32Equal, Word32T, int32_t, ToInt32Constant, ==)
CODE_ASSEMBLER_COMPARE(Word32NotEqual, Word32T, int32_t, ToInt32Constant, !=)
CODE_ASSEMBLER_COMPARE(Word64Equal, Word64T, int64_t, ToInt64Constant, ==)
CODE_ASSEMBLER_COMPARE(Word64NotEqual, Word64T, int64_t, ToInt64Constant, !=)
#undef CODE_ASSEMBLER_COMPARE
TNode<UintPtrT> CodeAssembler::ChangeUint32ToWord(SloppyTNode<Word32T> value) {
if (raw_assembler()->machine()->Is64()) {
return UncheckedCast<UintPtrT>(
......
......@@ -447,7 +447,6 @@ class SloppyTNode : public TNode<T> {
V(IntPtrLessThanOrEqual, BoolT, WordT, WordT) \
V(IntPtrGreaterThan, BoolT, WordT, WordT) \
V(IntPtrGreaterThanOrEqual, BoolT, WordT, WordT) \
V(IntPtrEqual, BoolT, WordT, WordT) \
V(Uint32LessThan, BoolT, Word32T, Word32T) \
V(Uint32LessThanOrEqual, BoolT, Word32T, Word32T) \
V(Uint32GreaterThan, BoolT, Word32T, Word32T) \
......@@ -455,13 +454,7 @@ class SloppyTNode : public TNode<T> {
V(UintPtrLessThan, BoolT, WordT, WordT) \
V(UintPtrLessThanOrEqual, BoolT, WordT, WordT) \
V(UintPtrGreaterThan, BoolT, WordT, WordT) \
V(UintPtrGreaterThanOrEqual, BoolT, WordT, WordT) \
V(WordEqual, BoolT, WordT, WordT) \
V(WordNotEqual, BoolT, WordT, WordT) \
V(Word32Equal, BoolT, Word32T, Word32T) \
V(Word32NotEqual, BoolT, Word32T, Word32T) \
V(Word64Equal, BoolT, Word64T, Word64T) \
V(Word64NotEqual, BoolT, Word64T, Word64T)
V(UintPtrGreaterThanOrEqual, BoolT, WordT, WordT)
#define CODE_ASSEMBLER_BINARY_OP_LIST(V) \
CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
......@@ -723,6 +716,9 @@ class V8_EXPORT_PRIVATE CodeAssembler {
TNode<BoolT> Int32FalseConstant() {
return ReinterpretCast<BoolT>(Int32Constant(0));
}
TNode<BoolT> BoolConstant(bool value) {
return value ? Int32TrueConstant() : Int32FalseConstant();
}
bool ToInt32Constant(Node* node, int32_t& out_value);
bool ToInt64Constant(Node* node, int64_t& out_value);
......@@ -879,6 +875,18 @@ class V8_EXPORT_PRIVATE CodeAssembler {
ReinterpretCast<WordT>(right));
}
TNode<BoolT> IntPtrEqual(SloppyTNode<WordT> left, SloppyTNode<WordT> right);
TNode<BoolT> WordEqual(SloppyTNode<WordT> left, SloppyTNode<WordT> right);
TNode<BoolT> WordNotEqual(SloppyTNode<WordT> left, SloppyTNode<WordT> right);
TNode<BoolT> Word32Equal(SloppyTNode<Word32T> left,
SloppyTNode<Word32T> right);
TNode<BoolT> Word32NotEqual(SloppyTNode<Word32T> left,
SloppyTNode<Word32T> right);
TNode<BoolT> Word64Equal(SloppyTNode<Word64T> left,
SloppyTNode<Word64T> right);
TNode<BoolT> Word64NotEqual(SloppyTNode<Word64T> left,
SloppyTNode<Word64T> right);
TNode<Int32T> Int32Add(TNode<Int32T> left, TNode<Int32T> right) {
return Signed(
Int32Add(static_cast<Node*>(left), static_cast<Node*>(right)));
......
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