Eliminate redundant x86 compare for GenDivZeroCheck
For x86, the ALU operations on general purpose registers update the flags.
Thus, when generating the zero check for divide/remainder operations, the
compare is not needed.
Change-Id: I07bfdf7d5491d3e3e9d98a932472d7f18d5b46d3
Signed-off-by: Razvan A Lupusoru <razvan.a.lupusoru@intel.com>
diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc
index 2c646d4..75eddd6 100644
--- a/compiler/dex/quick/x86/int_x86.cc
+++ b/compiler/dex/quick/x86/int_x86.cc
@@ -454,9 +454,17 @@
}
void X86Mir2Lir::GenDivZeroCheck(int reg_lo, int reg_hi) {
+ // We are not supposed to clobber either of the provided registers, so allocate
+ // a temporary to use for the check.
int t_reg = AllocTemp();
+
+ // Doing an OR is a quick way to check if both registers are zero. This will set the flags.
OpRegRegReg(kOpOr, t_reg, reg_lo, reg_hi);
- GenImmedCheck(kCondEq, t_reg, 0, kThrowDivZero);
+
+ // In case of zero, throw ArithmeticException.
+ GenCheck(kCondEq, kThrowDivZero);
+
+ // The temp is no longer needed so free it at this time.
FreeTemp(t_reg);
}