Tighten art::HNeg type constraints on its input.
Ensure art::HNeg is only passed a type having the kind of
its input. For a boolean, byte, short, or char input, it
means HNeg's type should be int.
Bug: 27684275
Change-Id: Ic8442c62090a8ab65590754874a14a0deb7acd8d
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 4a8186a..820c696 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -1538,7 +1538,10 @@
HInstruction* distance = invoke->InputAt(1);
// Replace the invoke with an HRor.
if (is_left) {
- distance = new (GetGraph()->GetArena()) HNeg(distance->GetType(), distance);
+ // Unconditionally set the type of the negated distance to `int`,
+ // as shift and rotate operations expect a 32-bit (or narrower)
+ // value for their distance input.
+ distance = new (GetGraph()->GetArena()) HNeg(Primitive::kPrimInt, distance);
invoke->GetBlock()->InsertInstructionBefore(distance, invoke);
}
HRor* ror = new (GetGraph()->GetArena()) HRor(type, value, distance);