summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/optimizing/instruction_simplifier.cc13
-rw-r--r--test/475-simplify-mul-zero/expected.txt1
-rw-r--r--test/475-simplify-mul-zero/info.txt2
-rw-r--r--test/475-simplify-mul-zero/src/Main.java28
4 files changed, 41 insertions, 3 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 98c0eedeb2..225af77a19 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -427,9 +427,16 @@ void InstructionSimplifierVisitor::VisitMul(HMul* instruction) {
if (Primitive::IsIntOrLongType(type)) {
int64_t factor = Int64FromConstant(input_cst);
- // We expect the `0` case to have been handled in the constant folding pass.
- DCHECK_NE(factor, 0);
- if (IsPowerOfTwo(factor)) {
+ // Even though constant propagation also takes care of the zero case, other
+ // optimizations can lead to having a zero multiplication.
+ if (factor == 0) {
+ // Replace code looking like
+ // MUL dst, src, 0
+ // with
+ // 0
+ instruction->ReplaceWith(input_cst);
+ instruction->GetBlock()->RemoveInstruction(instruction);
+ } else if (IsPowerOfTwo(factor)) {
// Replace code looking like
// MUL dst, src, pow_of_2
// with
diff --git a/test/475-simplify-mul-zero/expected.txt b/test/475-simplify-mul-zero/expected.txt
new file mode 100644
index 0000000000..7ed6ff82de
--- /dev/null
+++ b/test/475-simplify-mul-zero/expected.txt
@@ -0,0 +1 @@
+5
diff --git a/test/475-simplify-mul-zero/info.txt b/test/475-simplify-mul-zero/info.txt
new file mode 100644
index 0000000000..0db11f2823
--- /dev/null
+++ b/test/475-simplify-mul-zero/info.txt
@@ -0,0 +1,2 @@
+Regression check for optimizing simplify instruction pass.
+Mul should expect zero constant as input. \ No newline at end of file
diff --git a/test/475-simplify-mul-zero/src/Main.java b/test/475-simplify-mul-zero/src/Main.java
new file mode 100644
index 0000000000..57adcff01e
--- /dev/null
+++ b/test/475-simplify-mul-zero/src/Main.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2015 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) {
+ long l3 = 2207693990L;
+ int i12 = 5;
+
+ for (int i = 1; i < 2; ++i) {
+ i12 ^= (int)(-((-(-(l3 - l3))) * i));
+ }
+
+ System.out.println(i12);
+ }
+}