constant_propagation_pass: Combine zero-extension folding code into its own function
Separates the behavior from the actual switch statement and gets rid of duplication, now that we can use the general GetImmediateAsU64() function.
This commit is contained in:
parent
4c6a9535ca
commit
2274214ff0
1 changed files with 12 additions and 17 deletions
|
@ -113,6 +113,15 @@ void FoldOR(IR::Inst& inst, bool is_32_bit) {
|
||||||
inst.ReplaceUsesWith(lhs);
|
inst.ReplaceUsesWith(lhs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoldZeroExtendXToWord(IR::Inst& inst) {
|
||||||
|
if (!inst.AreAllArgsImmediates()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u64 value = inst.GetArg(0).GetImmediateAsU64();
|
||||||
|
inst.ReplaceUsesWith(IR::Value{static_cast<u32>(value)});
|
||||||
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
void ConstantPropagation(IR::Block& block) {
|
void ConstantPropagation(IR::Block& block) {
|
||||||
|
@ -154,24 +163,10 @@ void ConstantPropagation(IR::Block& block) {
|
||||||
case IR::Opcode::Not64:
|
case IR::Opcode::Not64:
|
||||||
FoldNOT(inst, opcode == IR::Opcode::Not32);
|
FoldNOT(inst, opcode == IR::Opcode::Not32);
|
||||||
break;
|
break;
|
||||||
case IR::Opcode::ZeroExtendByteToWord: {
|
case IR::Opcode::ZeroExtendByteToWord:
|
||||||
if (!inst.AreAllArgsImmediates())
|
case IR::Opcode::ZeroExtendHalfToWord:
|
||||||
break;
|
FoldZeroExtendXToWord(inst);
|
||||||
|
|
||||||
u8 byte = inst.GetArg(0).GetU8();
|
|
||||||
u32 value = static_cast<u32>(byte);
|
|
||||||
inst.ReplaceUsesWith(IR::Value{value});
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case IR::Opcode::ZeroExtendHalfToWord: {
|
|
||||||
if (!inst.AreAllArgsImmediates())
|
|
||||||
break;
|
|
||||||
|
|
||||||
u16 half = inst.GetArg(0).GetU16();
|
|
||||||
u32 value = static_cast<u32>(half);
|
|
||||||
inst.ReplaceUsesWith(IR::Value{value});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue