aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMerry <[email protected]>2024-01-30 23:10:23 +0000
committerMerry <[email protected]>2024-01-30 23:10:23 +0000
commit24bf921ff9cc0376ebd3bb1bd7158191dad6320a (patch)
tree9a7814c405f4d4193432d911ccdc3e78e6162b74
parentca2cc2c4ba4006e9dffe5c9d6b38b1eebec2216c (diff)
downloaddynarmic-24bf921ff9cc0376ebd3bb1bd7158191dad6320a.tar.gz
dynarmic-24bf921ff9cc0376ebd3bb1bd7158191dad6320a.zip
constant_propagation_pass: x + 0 == x
-rw-r--r--src/dynarmic/ir/opt/constant_propagation_pass.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/dynarmic/ir/opt/constant_propagation_pass.cpp b/src/dynarmic/ir/opt/constant_propagation_pass.cpp
index f63f6464..83ed8499 100644
--- a/src/dynarmic/ir/opt/constant_propagation_pass.cpp
+++ b/src/dynarmic/ir/opt/constant_propagation_pass.cpp
@@ -96,10 +96,18 @@ void FoldAdd(IR::Inst& inst, bool is_32_bit) {
const IR::Inst* lhs_inst = lhs.GetInstRecursive();
if (lhs_inst->GetOpcode() == inst.GetOpcode() && lhs_inst->GetArg(1).IsImmediate() && lhs_inst->GetArg(2).IsImmediate()) {
const u64 combined = rhs.GetImmediateAsU64() + lhs_inst->GetArg(1).GetImmediateAsU64() + lhs_inst->GetArg(2).GetU1();
+ if (combined == 0) {
+ inst.ReplaceUsesWith(lhs_inst->GetArg(0));
+ return;
+ }
inst.SetArg(0, lhs_inst->GetArg(0));
inst.SetArg(1, Value(is_32_bit, combined));
return;
}
+ if (rhs.IsZero() && carry.IsZero()) {
+ inst.ReplaceUsesWith(lhs);
+ return;
+ }
}
if (inst.AreAllArgsImmediates()) {