Quick compiler: Fix handling of unused returns
As part of the inlining process, the quick compiler will attempt
to eliminate MOVE_RESULT instructions and deliver the result of
the inlined function directly to the eventual use.
The type of the returned value is determined by the subsequent
use (which had already been typed via the size and type
inference pass). However, if a method result is never used the code
just defaulted to assigning dummy core sink register[s]. This
caused a DCHECK failure on some 64-bit systems for methods returning
an unused reference (although the generated code was correct).
This CL selects sink registers for the unused return case based
on the type of the inlined method, and adds another DCHECK to
verify that the result of the size & type inference pass matches
with the inlined method's type.
Internal b/17328561
Change-Id: I9803ad604fe1bdcf9ff9a1d310cf022a7b6deae2
diff --git a/compiler/dex/quick/gen_invoke.cc b/compiler/dex/quick/gen_invoke.cc
index e1d3241..78f5c73 100755
--- a/compiler/dex/quick/gen_invoke.cc
+++ b/compiler/dex/quick/gen_invoke.cc
@@ -1107,9 +1107,12 @@
RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
RegLocation res;
if (info->result.location == kLocInvalid) {
- res = GetReturn(LocToRegClass(info->result));
+ // If result is unused, return a sink target based on type of invoke target.
+ res = GetReturn(ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
} else {
res = info->result;
+ DCHECK_EQ(LocToRegClass(res),
+ ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
}
return res;
}
@@ -1117,9 +1120,12 @@
RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
RegLocation res;
if (info->result.location == kLocInvalid) {
- res = GetReturnWide(kCoreReg);
+ // If result is unused, return a sink target based on type of invoke target.
+ res = GetReturnWide(ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
} else {
res = info->result;
+ DCHECK_EQ(LocToRegClass(res),
+ ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
}
return res;
}