constant_propagation_pass: Fold NOT operations
This commit is contained in:
parent
0d1f9841d1
commit
7868411de5
@ -77,6 +77,21 @@ void FoldEOR(IR::Inst& inst, bool is_32_bit) {
|
||||
}
|
||||
}
|
||||
|
||||
// Folds NOT operations if the contained value is an immediate.
|
||||
void FoldNOT(IR::Inst& inst, bool is_32_bit) {
|
||||
const auto operand = inst.GetArg(0);
|
||||
|
||||
if (operand.IsImmediate()) {
|
||||
const u64 result = ~operand.GetImmediateAsU64();
|
||||
|
||||
if (is_32_bit) {
|
||||
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(result)});
|
||||
} else {
|
||||
inst.ReplaceUsesWith(IR::Value{result});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Folds OR operations based on the following:
|
||||
//
|
||||
// 1. imm_x | imm_y -> result
|
||||
@ -141,6 +156,10 @@ void ConstantPropagation(IR::Block& block) {
|
||||
case IR::Opcode::Or64:
|
||||
FoldOR(inst, opcode == IR::Opcode::Or32);
|
||||
break;
|
||||
case IR::Opcode::Not32:
|
||||
case IR::Opcode::Not64:
|
||||
FoldNOT(inst, opcode == IR::Opcode::Not32);
|
||||
break;
|
||||
case IR::Opcode::ZeroExtendByteToWord: {
|
||||
if (!inst.AreAllArgsImmediates())
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user