Merge remote-tracking branch 'GliniakRepo/const_prop_opcode_and_not' into canary_pr

This commit is contained in:
Gliniak 2022-05-19 10:18:58 +02:00
commit 0881725533
4 changed files with 31 additions and 21 deletions

View File

@ -2667,12 +2667,7 @@ EMITTER_OPCODE_TABLE(OPCODE_AND, AND_I8, AND_I16, AND_I32, AND_I64, AND_V128);
template <typename SEQ, typename REG, typename ARGS>
void EmitAndNotXX(X64Emitter& e, const ARGS& i) {
if (i.src1.is_constant) {
if (i.src2.is_constant) {
// Both constants.
e.mov(i.dest, i.src1.constant() & ~i.src2.constant());
} else {
// src1 constant.
// `and` instruction only supports up to 32-bit immediate constants
// 64-bit constants will need a temp register
if (i.dest.reg().getBit() == 64) {
@ -2695,7 +2690,6 @@ void EmitAndNotXX(X64Emitter& e, const ARGS& i) {
e.not_(i.dest);
e.and_(i.dest, uint32_t(i.src1.constant()));
}
}
} else if (i.src2.is_constant) {
// src2 constant.
if (i.dest == i.src1) {

View File

@ -648,6 +648,14 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder, bool& result) {
result = true;
}
break;
case OPCODE_AND_NOT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->AndNot(i->src2.value);
i->Remove();
result = true;
}
break;
case OPCODE_OR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);

View File

@ -750,6 +750,13 @@ void Value::Not() {
}
}
void Value::AndNot(Value* other) {
assert_true(type == other->type);
Value second = Value(*other);
second.Not();
And(&second);
}
void Value::Shl(Value* other) {
assert_true(other->type == INT8_TYPE);
switch (type) {

View File

@ -516,6 +516,7 @@ class Value {
void Or(Value* other);
void Xor(Value* other);
void Not();
void AndNot(Value* other);
void Shl(Value* other);
void Shr(Value* other);
void Sha(Value* other);