a32_get_set_elimination_pass: Convert NZ to NZC

This commit is contained in:
Merry 2022-07-20 16:45:14 +01:00
parent 6f106602ba
commit da2b1c5724
4 changed files with 10 additions and 2 deletions

View file

@ -174,7 +174,7 @@ private:
IR::Block ir_block = A32::Translate(A32::LocationDescriptor{descriptor}, conf.callbacks, {conf.arch_version, conf.define_unpredictable_behaviour, conf.hook_hint_instructions});
Optimization::PolyfillPass(ir_block, polyfill_options);
if (conf.HasOptimization(OptimizationFlag::GetSetElimination) && !conf.check_halt_on_memory_access) {
Optimization::A32GetSetElimination(ir_block, {});
Optimization::A32GetSetElimination(ir_block, {.convert_nz_to_nzc = true});
Optimization::DeadCodeElimination(ir_block);
}
if (conf.HasOptimization(OptimizationFlag::ConstProp)) {

View file

@ -208,6 +208,13 @@ void A32GetSetElimination(IR::Block& block, A32GetSetEliminationOptions opt) {
cpsr_info.nzc.last_set_instruction->SetArg(0, IR::Value::EmptyNZCVImmediateMarker());
}
if (opt.convert_nz_to_nzc && !cpsr_info.c.register_value.IsEmpty()) {
ir.SetInsertionPoint(inst);
ir.SetCpsrNZC(IR::NZCV{inst->GetArg(0)}, ir.GetCFlag());
inst->Invalidate();
break;
}
// cpsr_info.c remains valid
cpsr_info.nzc = {};
cpsr_info.nzcv = {};

View file

@ -28,6 +28,7 @@ struct PolyfillOptions {
struct A32GetSetEliminationOptions {
bool convert_nzc_to_nz = false;
bool convert_nz_to_nzc = false;
};
void PolyfillPass(IR::Block& block, const PolyfillOptions& opt);

View file

@ -176,7 +176,7 @@ static void RunInstance(size_t run_number, ThumbTestEnv& test_env, A32Unicorn<Th
while (num_insts < instructions_to_execute_count) {
A32::LocationDescriptor descriptor = {u32(num_insts * 4), cpsr, A32::FPSCR{}};
IR::Block ir_block = A32::Translate(descriptor, &test_env, {});
Optimization::A32GetSetElimination(ir_block, {});
Optimization::A32GetSetElimination(ir_block, {.convert_nz_to_nzc = true});
Optimization::DeadCodeElimination(ir_block);
Optimization::A32ConstantMemoryReads(ir_block, &test_env);
Optimization::ConstantPropagation(ir_block);