diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-12 00:27:31 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-18 10:00:01 +0000 |
commit | 721e96e8836d81d79f3ea9d6a7d25cbc2c04bac0 (patch) | |
tree | 710a98012bf363e537c1e1dd401bc0cc95979f32 /src | |
parent | a520b3188ba5b8eb114d9d8e609ffe6cbcceeb7e (diff) |
Constant fold &, | and ^
Change-Id: Ia882e14f5521d45343288a267ffee5f756286012
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 24907144ac..2ad5ee8610 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -903,9 +903,14 @@ Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Re } case QSOperator::BitAnd: if (right.isConst()) { + int rightAsInt = Primitive::fromReturnedValue(right.constant).toInt32(); + if (left.isConst()) { + int result = Primitive::fromReturnedValue(left.constant).toInt32() & rightAsInt; + return Reference::fromConst(this, Encode(result)); + } left.loadInAccumulator(); Instruction::BitAndConst bitAnd; - bitAnd.rhs = Primitive::fromReturnedValue(right.constant).toInt32(); + bitAnd.rhs = rightAsInt; bytecodeGenerator->addInstruction(bitAnd); } else { right.loadInAccumulator(); @@ -916,9 +921,14 @@ Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Re break; case QSOperator::BitOr: if (right.isConst()) { + int rightAsInt = Primitive::fromReturnedValue(right.constant).toInt32(); + if (left.isConst()) { + int result = Primitive::fromReturnedValue(left.constant).toInt32() | rightAsInt; + return Reference::fromConst(this, Encode(result)); + } left.loadInAccumulator(); Instruction::BitOrConst bitOr; - bitOr.rhs = Primitive::fromReturnedValue(right.constant).toInt32(); + bitOr.rhs = rightAsInt; bytecodeGenerator->addInstruction(bitOr); } else { right.loadInAccumulator(); @@ -929,9 +939,14 @@ Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Re break; case QSOperator::BitXor: if (right.isConst()) { + int rightAsInt = Primitive::fromReturnedValue(right.constant).toInt32(); + if (left.isConst()) { + int result = Primitive::fromReturnedValue(left.constant).toInt32() ^ rightAsInt; + return Reference::fromConst(this, Encode(result)); + } left.loadInAccumulator(); Instruction::BitXorConst bitXor; - bitXor.rhs = Primitive::fromReturnedValue(right.constant).toInt32(); + bitXor.rhs = rightAsInt; bytecodeGenerator->addInstruction(bitXor); } else { right.loadInAccumulator(); |