mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-19 09:54:54 +00:00
Optimise out unnecessary shifts (#1021)
This commit is contained in:
parent
581ddfec4d
commit
5db27109c9
2 changed files with 18 additions and 0 deletions
|
@ -1079,6 +1079,10 @@ U32 IREmitter::IAbs(const U32& value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
U32U64 IREmitter::ShiftLeftLogical(const U32U64& base, const U32& shift) {
|
U32U64 IREmitter::ShiftLeftLogical(const U32U64& base, const U32& shift) {
|
||||||
|
if (shift.IsImmediate() && shift.U32() == 0) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
switch (base.Type()) {
|
switch (base.Type()) {
|
||||||
case Type::U32:
|
case Type::U32:
|
||||||
return Inst<U32>(Opcode::ShiftLeftLogical32, base, shift);
|
return Inst<U32>(Opcode::ShiftLeftLogical32, base, shift);
|
||||||
|
@ -1090,6 +1094,10 @@ U32U64 IREmitter::ShiftLeftLogical(const U32U64& base, const U32& shift) {
|
||||||
}
|
}
|
||||||
|
|
||||||
U32U64 IREmitter::ShiftRightLogical(const U32U64& base, const U32& shift) {
|
U32U64 IREmitter::ShiftRightLogical(const U32U64& base, const U32& shift) {
|
||||||
|
if (shift.IsImmediate() && shift.U32() == 0) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
switch (base.Type()) {
|
switch (base.Type()) {
|
||||||
case Type::U32:
|
case Type::U32:
|
||||||
return Inst<U32>(Opcode::ShiftRightLogical32, base, shift);
|
return Inst<U32>(Opcode::ShiftRightLogical32, base, shift);
|
||||||
|
@ -1101,6 +1109,10 @@ U32U64 IREmitter::ShiftRightLogical(const U32U64& base, const U32& shift) {
|
||||||
}
|
}
|
||||||
|
|
||||||
U32U64 IREmitter::ShiftRightArithmetic(const U32U64& base, const U32& shift) {
|
U32U64 IREmitter::ShiftRightArithmetic(const U32U64& base, const U32& shift) {
|
||||||
|
if (shift.IsImmediate() && shift.U32() == 0) {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
switch (base.Type()) {
|
switch (base.Type()) {
|
||||||
case Type::U32:
|
case Type::U32:
|
||||||
return Inst<U32>(Opcode::ShiftRightArithmetic32, base, shift);
|
return Inst<U32>(Opcode::ShiftRightArithmetic32, base, shift);
|
||||||
|
|
|
@ -278,6 +278,12 @@ void ConstantPropagation(IR::Block& block, IR::Inst& inst) {
|
||||||
case IR::Opcode::FPCmpClass32:
|
case IR::Opcode::FPCmpClass32:
|
||||||
FoldCmpClass(inst);
|
FoldCmpClass(inst);
|
||||||
return;
|
return;
|
||||||
|
case IR::Opcode::ShiftLeftLogical32:
|
||||||
|
FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return static_cast<u32>(a << b); });
|
||||||
|
return;
|
||||||
|
case IR::Opcode::ShiftRightLogical32:
|
||||||
|
FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return static_cast<u32>(a >> b); });
|
||||||
|
return;
|
||||||
case IR::Opcode::ShiftRightArithmetic32:
|
case IR::Opcode::ShiftRightArithmetic32:
|
||||||
FoldWhenAllImmediates(inst, [](s32 a, s32 b) { return static_cast<u32>(a >> b); });
|
FoldWhenAllImmediates(inst, [](s32 a, s32 b) { return static_cast<u32>(a >> b); });
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue