shader: fold constant bit reversal before flat stack classification

Co-authored-by: TheCruZ <thecruzwtf@gmail.com>
Co-authored-by: Ali Almohaya <AliAlmohaya@gmail.com>
This commit is contained in:
nmzik
2026-10-04 05:40:54 +04:00
parent a55a28380d
commit 139b564c01
2 changed files with 14 additions and 1 deletions
@@ -503,6 +503,17 @@ void FoldInstruction(Block& block, Block::iterator instruction,
}
return;
}
case ValueOpcode::BitReverse32: {
const auto value = Arg(inst, 0);
if (IsImmediate(value, Type::U32)) {
uint32_t source = value.U32(), reversed = 0;
for (uint32_t bit = 0; bit < 32u; ++bit, source >>= 1u) {
reversed = (reversed << 1u) | (source & 1u);
}
Replace(inst, Value(reversed));
}
return;
}
case ValueOpcode::BitCount32: {
const auto value = Arg(inst, 0);
if (IsImmediate(value, Type::U32)) {