From de9e2b90c156664a1bdc2b5c9911e4dfa527c148 Mon Sep 17 00:00:00 2001 From: Ben Cheng Date: Tue, 26 Apr 2011 10:00:22 -0700 Subject: [PATCH] Bug fixes for ld/st elimination. 1) Only optimize each block once. Strictly speaking this is not a correctness issue however it triggers the subsequent problem. 2) Ignore dead instructions. 1: ldr r2, [r5, #8] 2: ldr r3, [r5, #8](nop) 3: str r3, [r5, #4] 4: movs r3, r2 When using instruction 1 to initiate redundant ld/st eliminations, if instruction 2 (which is already dead) is not ignored, it will be turned into a "mov r3, r2" and that will clobber r3 used by the str. Change-Id: I8eecd13eeb30e4a67ecf1f8fbad925b1e6e91fc8 --- vm/compiler/codegen/arm/CodegenDriver.c | 2 ++ vm/compiler/codegen/arm/LocalOptimizations.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/vm/compiler/codegen/arm/CodegenDriver.c b/vm/compiler/codegen/arm/CodegenDriver.c index 599df90b4..e94fc1175 100644 --- a/vm/compiler/codegen/arm/CodegenDriver.c +++ b/vm/compiler/codegen/arm/CodegenDriver.c @@ -4575,6 +4575,8 @@ void dvmCompilerMIR2LIR(CompilationUnit *cUnit) */ dvmCompilerApplyLocalOptimizations(cUnit, (LIR *) headLIR, cUnit->lastLIRInsn); + /* Reset headLIR which is also the optimization boundary */ + headLIR = NULL; } gen_fallthrough: diff --git a/vm/compiler/codegen/arm/LocalOptimizations.c b/vm/compiler/codegen/arm/LocalOptimizations.c index 4c0354ac8..ffeaa576f 100644 --- a/vm/compiler/codegen/arm/LocalOptimizations.c +++ b/vm/compiler/codegen/arm/LocalOptimizations.c @@ -131,6 +131,12 @@ static void applyLoadStoreElimination(CompilationUnit *cUnit, checkLIR != tailLIR; checkLIR = NEXT_LIR(checkLIR)) { + /* + * Skip already dead instructions (whose dataflow information is + * outdated and misleading). + */ + if (checkLIR->flags.isNop) continue; + u8 checkMemMask = (checkLIR->useMask | checkLIR->defMask) & ENCODE_MEM; u8 aliasCondition = thisMemMask & checkMemMask; @@ -312,6 +318,10 @@ static void applyLoadHoisting(CompilationUnit *cUnit, checkLIR != headLIR; checkLIR = PREV_LIR(checkLIR)) { + /* + * Skip already dead instructions (whose dataflow information is + * outdated and misleading). + */ if (checkLIR->flags.isNop) continue; u8 checkMemMask = checkLIR->defMask & ENCODE_MEM; -- 2.11.0