Fixing subfme.

This commit is contained in:
Ben Vanik 2015-05-13 00:15:35 -07:00
parent 3ba6598caf
commit 6fd7e35deb
3 changed files with 24 additions and 11 deletions

View File

@ -318,12 +318,19 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder) {
} }
} }
} }
if (i->dest->type == ca->type) { if (ca->IsConstant()) {
i->Replace(&OPCODE_ASSIGN_info, 0); TypeName target_type = v->type;
i->set_src1(ca); v->set_from(ca);
v->ZeroExtend(target_type);
i->Remove();
} else { } else {
i->Replace(&OPCODE_ZERO_EXTEND_info, 0); if (i->dest->type == ca->type) {
i->set_src1(ca); i->Replace(&OPCODE_ASSIGN_info, 0);
i->set_src1(ca);
} else {
i->Replace(&OPCODE_ZERO_EXTEND_info, 0);
i->set_src1(ca);
}
} }
} }
break; break;
@ -404,6 +411,11 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder) {
v->set_from(i->src1.value); v->set_from(i->src1.value);
v->Xor(i->src2.value); v->Xor(i->src2.value);
i->Remove(); i->Remove();
} else if (!i->src1.value->IsConstant() &&
!i->src2.value->IsConstant() &&
i->src1.value == i->src2.value) {
v->set_zero(v->type);
i->Remove();
} }
break; break;
case OPCODE_NOT: case OPCODE_NOT:
@ -478,7 +490,7 @@ void ConstantPropagationPass::PropagateCarry(Value* v, bool did_carry) {
next = use->next; next = use->next;
if (use->instr->opcode == &OPCODE_DID_CARRY_info) { if (use->instr->opcode == &OPCODE_DID_CARRY_info) {
// Replace carry value. // Replace carry value.
use->instr->dest->set_constant(did_carry ? 1 : 0); use->instr->dest->set_constant(int8_t(did_carry ? 1 : 0));
use->instr->Remove(); use->instr->Remove();
} }
} }

View File

@ -466,8 +466,9 @@ XEEMITTER(subfex, 0x7C000110, XO)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(subfmex, 0x7C0001D0, XO)(PPCHIRBuilder& f, InstrData& i) { XEEMITTER(subfmex, 0x7C0001D0, XO)(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + CA - 1 // RT <- ¬(RA) + CA - 1
Value* v = f.AddWithCarry(f.Not(f.LoadGPR(i.XO.RA)), Value* v =
f.LoadConstant((int64_t)-1), f.LoadCA()); f.AddWithCarry(f.Not(f.LoadGPR(i.XO.RA)), f.LoadConstant((int64_t)-1),
f.LoadCA(), ARITHMETIC_SET_CARRY);
if (i.XO.OE) { if (i.XO.OE) {
assert_always(); assert_always();
// e.update_xer_with_overflow_and_carry(b.CreateExtractValue(v, 1)); // e.update_xer_with_overflow_and_carry(b.CreateExtractValue(v, 1));

View File

@ -55,7 +55,7 @@ test_subfme_zero_ca_1:
blr blr
#_ REGISTER_OUT r10 0x00000000000103BF #_ REGISTER_OUT r10 0x00000000000103BF
#_ REGISTER_OUT r3 0xfffffffffffefc3f #_ REGISTER_OUT r3 0xfffffffffffefc3f
#_ REGISTER_OUT r4 0 #_ REGISTER_OUT r4 1
test_subfme_zero_ca_2: test_subfme_zero_ca_2:
#_ REGISTER_IN r10 0 #_ REGISTER_IN r10 0
@ -66,7 +66,7 @@ test_subfme_zero_ca_2:
blr blr
#_ REGISTER_OUT r10 0 #_ REGISTER_OUT r10 0
#_ REGISTER_OUT r3 0xfffffffffffffffe #_ REGISTER_OUT r3 0xfffffffffffffffe
#_ REGISTER_OUT r4 0 #_ REGISTER_OUT r4 1
test_subfme_zero_ca_3: test_subfme_zero_ca_3:
#_ REGISTER_IN r10 1 #_ REGISTER_IN r10 1
@ -77,7 +77,7 @@ test_subfme_zero_ca_3:
blr blr
#_ REGISTER_OUT r10 1 #_ REGISTER_OUT r10 1
#_ REGISTER_OUT r3 0xfffffffffffffffd #_ REGISTER_OUT r3 0xfffffffffffffffd
#_ REGISTER_OUT r4 0 #_ REGISTER_OUT r4 1
test_subfme_zero_ca_4: test_subfme_zero_ca_4:
#_ REGISTER_IN r10 0xFFFFFFFFFFFFFFFF #_ REGISTER_IN r10 0xFFFFFFFFFFFFFFFF