From fa1693d3a31a9f6c8a1938d9fa53b06492b006cb Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Thu, 7 Aug 2014 13:23:44 -0700 Subject: [PATCH] ADD_CARRY constant prop for load-CA cases. --- .../passes/constant_propagation_pass.cc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/alloy/compiler/passes/constant_propagation_pass.cc b/src/alloy/compiler/passes/constant_propagation_pass.cc index 330e93fac..64eeb5f1d 100644 --- a/src/alloy/compiler/passes/constant_propagation_pass.cc +++ b/src/alloy/compiler/passes/constant_propagation_pass.cc @@ -300,6 +300,26 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) { } break; // TODO(benvanik): ADD_CARRY (w/ ARITHMETIC_SET_CARRY) + case OPCODE_ADD_CARRY: + if (i->src1.value->IsConstantZero() && i->src2.value->IsConstantZero()) { + Value* ca = i->src3.value; + // If carry is set find the DID_CARRY and fix it. + if (!!(i->flags & ARITHMETIC_SET_CARRY)) { + auto next = i->dest->use_head; + while (next) { + auto use = next; + next = use->next; + if (use->instr->opcode == &OPCODE_DID_CARRY_info) { + // Replace carry value. + use->instr->Replace(&OPCODE_ASSIGN_info, 0); + use->instr->set_src1(ca); + } + } + } + i->Replace(&OPCODE_ASSIGN_info, 0); + i->set_src1(ca); + } + break; case OPCODE_SUB: if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) { v->set_from(i->src1.value);