Compiler constant handling rework
In preparation for de-optimization, reworked the constant
handling mechanism. Also took advantage of knowledge of
constant operands (particularly for long operations).
Significant performance improvements for Mandelbrot
(~60 seconds to ~34 seconds). Minor improvements in other
benchmarks.
The new constant handling breaks two of the existing
optimization passes: "Skip Large Method" and "Load/Store
Elimization."
I don't intend to update the large method optimization
because it will be superceeded by the upcoming interpreter/
fingerprinting mechanism. Leaving the code in place for
now in order to compare compile-time improvements with
fingerprinting/interpret. All related code will be deleted
when that is complete.
The load/store elimination pass needs some rework to handle
uses of multiple-register loads and stores. It will be
updated & restored in a future CL.
Change-Id: Ia979abaf51b8ae81bbb0428031cbcea854625fac
diff --git a/src/compiler/ralloc.cc b/src/compiler/ralloc.cc
index 2038e19..3514200 100644
--- a/src/compiler/ralloc.cc
+++ b/src/compiler/ralloc.cc
@@ -479,6 +479,39 @@
}
}
+ /*
+ * Now that everything is typed and constants propagated, identify those constants
+ * that can be cheaply materialized and don't need to be flushed to a home location.
+ * The default is to not flush, and some have already been marked as must flush.
+ */
+ for (i=0; i < cu->num_ssa_regs; i++) {
+ if (IsBitSet(cu->is_constant_v, i)) {
+ bool flush = false;
+ RegLocation loc = cu->reg_location[i];
+ if (loc.wide) {
+ int64_t value = ConstantValueWide(cu, loc);
+ if (loc.fp) {
+ flush = !cu->cg->InexpensiveConstantDouble(value);
+ } else {
+ flush = !cu->cg->InexpensiveConstantLong(value);
+ }
+ } else {
+ int32_t value = ConstantValue(cu, loc);
+ if (loc.fp) {
+ flush = !cu->cg->InexpensiveConstantFloat(value);
+ } else {
+ flush = !cu->cg->InexpensiveConstantInt(value);
+ }
+ }
+ if (flush) {
+ SetBit(cu, cu->must_flush_constant_v, i);
+ }
+ if (loc.wide) {
+ i++; // Skip the high word
+ }
+ }
+ }
+
cu->core_spill_mask = 0;
cu->fp_spill_mask = 0;
cu->num_core_spills = 0;