constant_propagation_pass: Handle a few more bitwise instructions. (#3482)

Co-authored-by: TheTurtle <47210458+raphaelthegreat@users.noreply.github.com>
This commit is contained in:
squidbus
2025-08-29 18:11:14 -07:00
committed by GitHub
parent 62ddc0664b
commit bfa5c508ce

View File

@@ -456,6 +456,24 @@ void ConstantPropagation(IR::Block& block, IR::Inst& inst) {
case IR::Opcode::BitwiseXor32:
FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return a ^ b; });
return;
case IR::Opcode::BitwiseNot32:
FoldWhenAllImmediates(inst, [](u32 a) { return ~a; });
return;
case IR::Opcode::BitReverse32:
FoldWhenAllImmediates(inst, [](u32 a) {
u32 res{};
for (s32 i = 0; i < 32; i++, a >>= 1) {
res = (res << 1) | (a & 1);
}
return res;
});
return;
case IR::Opcode::BitCount32:
FoldWhenAllImmediates(inst, [](u32 a) { return static_cast<u32>(std::popcount(a)); });
return;
case IR::Opcode::BitCount64:
FoldWhenAllImmediates(inst, [](u64 a) { return static_cast<u32>(std::popcount(a)); });
return;
case IR::Opcode::BitFieldUExtract:
FoldWhenAllImmediates(inst, [](u32 base, u32 shift, u32 count) {
if (static_cast<size_t>(shift) + static_cast<size_t>(count) > 32) {