Fix and improve shift and rotate operations.
- Define maximum int and long shift & rotate distances as
int32_t constants, as shift & rotate distances are 32-bit
integer values.
- Consider the (long, long) inputs case as invalid for
static evaluation of shift & rotate rotations.
- Add more checks in shift & rotate operations constructors
as well as in art::GraphChecker.
Change-Id: I754b326c3a341c9cc567d1720b327dad6fcbf9d6
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index 088dbb3..46fd852 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -1818,9 +1818,8 @@
Register lhs = InputRegisterAt(instr, 0);
Operand rhs = InputOperandAt(instr, 1);
if (rhs.IsImmediate()) {
- uint32_t shift_value = (type == Primitive::kPrimInt)
- ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
- : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
+ uint32_t shift_value = rhs.immediate() &
+ (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
if (instr->IsShl()) {
__ Lsl(dst, lhs, shift_value);
} else if (instr->IsShr()) {
@@ -1921,9 +1920,8 @@
// conversion) can have a different type from the current instruction's type,
// so we manually indicate the type.
Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type);
- int64_t shift_amount = (type == Primitive::kPrimInt)
- ? static_cast<uint32_t>(instruction->GetShiftAmount() & kMaxIntShiftValue)
- : static_cast<uint32_t>(instruction->GetShiftAmount() & kMaxLongShiftValue);
+ int64_t shift_amount = instruction->GetShiftAmount() &
+ (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Operand right_operand(0);