From e5671618d19489ad0781ec0d204c7765317170cf Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Wed, 16 Mar 2016 11:03:54 +0000 Subject: [PATCH] Accept boolean as an input of HDivZeroCheck. All our arithmetic operations accept it. bug:27624718 Change-Id: I1f6bb95dc77ecb3fb2fcabb35a93b31c524bfa0a --- compiler/optimizing/code_generator_arm.cc | 1 + compiler/optimizing/code_generator_arm64.cc | 4 +-- compiler/optimizing/code_generator_mips.cc | 1 + compiler/optimizing/code_generator_mips64.cc | 4 +-- compiler/optimizing/code_generator_x86.cc | 2 ++ compiler/optimizing/code_generator_x86_64.cc | 1 + test/584-checker-div-bool/expected.txt | 0 test/584-checker-div-bool/info.txt | 2 ++ test/584-checker-div-bool/src/Main.java | 41 ++++++++++++++++++++++++++++ 9 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/584-checker-div-bool/expected.txt create mode 100644 test/584-checker-div-bool/info.txt create mode 100644 test/584-checker-div-bool/src/Main.java diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc index 0b7fefafd..46f08a8d6 100644 --- a/compiler/optimizing/code_generator_arm.cc +++ b/compiler/optimizing/code_generator_arm.cc @@ -3151,6 +3151,7 @@ void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) Location value = locations->InAt(0); switch (instruction->GetType()) { + case Primitive::kPrimBoolean: case Primitive::kPrimByte: case Primitive::kPrimChar: case Primitive::kPrimShort: diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc index 89b9e2c59..99fa9c610 100644 --- a/compiler/optimizing/code_generator_arm64.cc +++ b/compiler/optimizing/code_generator_arm64.cc @@ -2718,8 +2718,8 @@ void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction Primitive::Type type = instruction->GetType(); - if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { - LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; + if (!Primitive::IsIntegralType(type)) { + LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; return; } diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc index f3c12efd8..ba6c16e33 100644 --- a/compiler/optimizing/code_generator_mips.cc +++ b/compiler/optimizing/code_generator_mips.cc @@ -2530,6 +2530,7 @@ void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) Primitive::Type type = instruction->GetType(); switch (type) { + case Primitive::kPrimBoolean: case Primitive::kPrimByte: case Primitive::kPrimChar: case Primitive::kPrimShort: diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc index c2b84b433..90a094159 100644 --- a/compiler/optimizing/code_generator_mips64.cc +++ b/compiler/optimizing/code_generator_mips64.cc @@ -2172,8 +2172,8 @@ void InstructionCodeGeneratorMIPS64::VisitDivZeroCheck(HDivZeroCheck* instructio Primitive::Type type = instruction->GetType(); - if ((type == Primitive::kPrimBoolean) || !Primitive::IsIntegralType(type)) { - LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; + if (!Primitive::IsIntegralType(type)) { + LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck."; return; } diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 6b4a18c68..830e69de3 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -3662,6 +3662,7 @@ void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { : LocationSummary::kNoCall; LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); switch (instruction->GetType()) { + case Primitive::kPrimBoolean: case Primitive::kPrimByte: case Primitive::kPrimChar: case Primitive::kPrimShort: @@ -3692,6 +3693,7 @@ void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) Location value = locations->InAt(0); switch (instruction->GetType()) { + case Primitive::kPrimBoolean: case Primitive::kPrimByte: case Primitive::kPrimChar: case Primitive::kPrimShort: diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index c13266301..b1674d65c 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -3713,6 +3713,7 @@ void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instructio Location value = locations->InAt(0); switch (instruction->GetType()) { + case Primitive::kPrimBoolean: case Primitive::kPrimByte: case Primitive::kPrimChar: case Primitive::kPrimShort: diff --git a/test/584-checker-div-bool/expected.txt b/test/584-checker-div-bool/expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/584-checker-div-bool/info.txt b/test/584-checker-div-bool/info.txt new file mode 100644 index 000000000..59650d566 --- /dev/null +++ b/test/584-checker-div-bool/info.txt @@ -0,0 +1,2 @@ +Regression test for optimizing that used to not accept +HDivZeroCheck taking a boolean. diff --git a/test/584-checker-div-bool/src/Main.java b/test/584-checker-div-bool/src/Main.java new file mode 100644 index 000000000..fadc995d1 --- /dev/null +++ b/test/584-checker-div-bool/src/Main.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Main { + + public static void main(String[] args) { + try { + foo(intField); + throw new Error("Expected ArithmeticException"); + } catch (ArithmeticException e) { + // expected + } + } + + /// CHECK-START: int Main.foo(int) register (after) + /// CHECK: <> StaticFieldGet + /// CHECK: DivZeroCheck [<>] + public static int foo(int a) { + return a / bar(); + } + + public static int bar() { + return booleanField ? 1 : 0; + } + + public static boolean booleanField; + public static int intField; +} -- 2.11.0