diff options
Diffstat (limited to 'src/shader_recompiler/ir_opt/constant_propagation_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index 02f5b653d..7fb3192d8 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <type_traits> | 6 | #include <type_traits> |
| 7 | 7 | ||
| 8 | #include "common/bit_cast.h" | ||
| 8 | #include "common/bit_util.h" | 9 | #include "common/bit_util.h" |
| 9 | #include "shader_recompiler/exception.h" | 10 | #include "shader_recompiler/exception.h" |
| 10 | #include "shader_recompiler/frontend/ir/microinstruction.h" | 11 | #include "shader_recompiler/frontend/ir/microinstruction.h" |
| @@ -25,6 +26,8 @@ template <typename T> | |||
| 25 | return value.U1(); | 26 | return value.U1(); |
| 26 | } else if constexpr (std::is_same_v<T, u32>) { | 27 | } else if constexpr (std::is_same_v<T, u32>) { |
| 27 | return value.U32(); | 28 | return value.U32(); |
| 29 | } else if constexpr (std::is_same_v<T, f32>) { | ||
| 30 | return value.F32(); | ||
| 28 | } else if constexpr (std::is_same_v<T, u64>) { | 31 | } else if constexpr (std::is_same_v<T, u64>) { |
| 29 | return value.U64(); | 32 | return value.U64(); |
| 30 | } | 33 | } |
| @@ -115,6 +118,19 @@ void FoldLogicalAnd(IR::Inst& inst) { | |||
| 115 | } | 118 | } |
| 116 | } | 119 | } |
| 117 | 120 | ||
| 121 | template <typename Dest, typename Source> | ||
| 122 | void FoldBitCast(IR::Inst& inst, IR::Opcode reverse) { | ||
| 123 | const IR::Value value{inst.Arg(0)}; | ||
| 124 | if (value.IsImmediate()) { | ||
| 125 | inst.ReplaceUsesWith(IR::Value{Common::BitCast<Dest>(Arg<Source>(value))}); | ||
| 126 | return; | ||
| 127 | } | ||
| 128 | IR::Inst* const arg_inst{value.InstRecursive()}; | ||
| 129 | if (value.InstRecursive()->Opcode() == reverse) { | ||
| 130 | inst.ReplaceUsesWith(arg_inst->Arg(0)); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 118 | void ConstantPropagation(IR::Inst& inst) { | 134 | void ConstantPropagation(IR::Inst& inst) { |
| 119 | switch (inst.Opcode()) { | 135 | switch (inst.Opcode()) { |
| 120 | case IR::Opcode::GetRegister: | 136 | case IR::Opcode::GetRegister: |
| @@ -123,6 +139,10 @@ void ConstantPropagation(IR::Inst& inst) { | |||
| 123 | return FoldGetPred(inst); | 139 | return FoldGetPred(inst); |
| 124 | case IR::Opcode::IAdd32: | 140 | case IR::Opcode::IAdd32: |
| 125 | return FoldAdd<u32>(inst); | 141 | return FoldAdd<u32>(inst); |
| 142 | case IR::Opcode::BitCastF32U32: | ||
| 143 | return FoldBitCast<f32, u32>(inst, IR::Opcode::BitCastU32F32); | ||
| 144 | case IR::Opcode::BitCastU32F32: | ||
| 145 | return FoldBitCast<u32, f32>(inst, IR::Opcode::BitCastF32U32); | ||
| 126 | case IR::Opcode::IAdd64: | 146 | case IR::Opcode::IAdd64: |
| 127 | return FoldAdd<u64>(inst); | 147 | return FoldAdd<u64>(inst); |
| 128 | case IR::Opcode::BitFieldUExtract: | 148 | case IR::Opcode::BitFieldUExtract: |