constant_propagation_pass: Handle folding for Least/MostSignificant{Bit, Byte, Half, Word} opcodes
These are quite trivial to fold.
This commit is contained in:
parent
7c8fcaef26
commit
d302d9bd0c
1 changed files with 60 additions and 0 deletions
|
@ -98,6 +98,51 @@ void FoldEOR(IR::Inst& inst, bool is_32_bit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoldLeastSignificantByte(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto operand = inst.GetArg(0);
|
||||||
|
inst.ReplaceUsesWith(IR::Value{static_cast<u8>(operand.GetImmediateAsU64())});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FoldLeastSignificantHalf(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto operand = inst.GetArg(0);
|
||||||
|
inst.ReplaceUsesWith(IR::Value{static_cast<u16>(operand.GetImmediateAsU64())});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FoldLeastSignificantWord(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto operand = inst.GetArg(0);
|
||||||
|
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(operand.GetImmediateAsU64())});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FoldMostSignificantBit(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto operand = inst.GetArg(0);
|
||||||
|
inst.ReplaceUsesWith(IR::Value{(operand.GetImmediateAsU64() >> 31) != 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FoldMostSignificantWord(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto operand = inst.GetArg(0);
|
||||||
|
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(operand.GetImmediateAsU64() >> 32)});
|
||||||
|
}
|
||||||
|
|
||||||
// Folds multiplication operations based on the following:
|
// Folds multiplication operations based on the following:
|
||||||
//
|
//
|
||||||
// 1. imm_x * imm_y -> result
|
// 1. imm_x * imm_y -> result
|
||||||
|
@ -216,6 +261,21 @@ void ConstantPropagation(IR::Block& block) {
|
||||||
const auto opcode = inst.GetOpcode();
|
const auto opcode = inst.GetOpcode();
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
case IR::Opcode::LeastSignificantWord:
|
||||||
|
FoldLeastSignificantWord(inst);
|
||||||
|
break;
|
||||||
|
case IR::Opcode::MostSignificantWord:
|
||||||
|
FoldMostSignificantWord(inst);
|
||||||
|
break;
|
||||||
|
case IR::Opcode::LeastSignificantHalf:
|
||||||
|
FoldLeastSignificantHalf(inst);
|
||||||
|
break;
|
||||||
|
case IR::Opcode::LeastSignificantByte:
|
||||||
|
FoldLeastSignificantByte(inst);
|
||||||
|
break;
|
||||||
|
case IR::Opcode::MostSignificantBit:
|
||||||
|
FoldMostSignificantBit(inst);
|
||||||
|
break;
|
||||||
case IR::Opcode::LogicalShiftLeft32:
|
case IR::Opcode::LogicalShiftLeft32:
|
||||||
case IR::Opcode::LogicalShiftLeft64:
|
case IR::Opcode::LogicalShiftLeft64:
|
||||||
case IR::Opcode::LogicalShiftRight32:
|
case IR::Opcode::LogicalShiftRight32:
|
||||||
|
|
Loading…
Reference in a new issue