summaryrefslogtreecommitdiff
path: root/compiler/optimizing/constant_folding_test.cc
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2014-10-20 16:47:04 +0100
committer Roland Levillain <rpl@google.com> 2014-10-21 13:48:41 +0100
commit9240d6a2baa9ed1e18ee08744b461fe49a1ee269 (patch)
tree0adc27979a1c30defa16de4142b1d54fac6f93dc /compiler/optimizing/constant_folding_test.cc
parent88cb1755e1d6acaed0f66ce65d7a2a4465053342 (diff)
Constant folding on unary operations in the optimizing compiler.
Change-Id: I4b77afa2a89f5ad2eedd4d6c0c6c382585419349
Diffstat (limited to 'compiler/optimizing/constant_folding_test.cc')
-rw-r--r--compiler/optimizing/constant_folding_test.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/compiler/optimizing/constant_folding_test.cc b/compiler/optimizing/constant_folding_test.cc
index ec2ff33590..09bf2c8d7d 100644
--- a/compiler/optimizing/constant_folding_test.cc
+++ b/compiler/optimizing/constant_folding_test.cc
@@ -72,6 +72,61 @@ static void TestCode(const uint16_t* data,
/**
+ * Tiny three-register program exercising int constant folding on negation.
+ *
+ * 16-bit
+ * offset
+ * ------
+ * v0 <- 1 0. const/4 v0, #+1
+ * v1 <- -v0 1. neg-int v0, v1
+ * return v1 2. return v1
+ */
+TEST(ConstantFolding, IntConstantFoldingNegation) {
+ const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
+ Instruction::CONST_4 | 0 << 8 | 1 << 12,
+ Instruction::NEG_INT | 1 << 8 | 0 << 12,
+ Instruction::RETURN | 1 << 8);
+
+ std::string expected_before =
+ "BasicBlock 0, succ: 1\n"
+ " 2: IntConstant [5]\n"
+ " 10: SuspendCheck\n"
+ " 11: Goto 1\n"
+ "BasicBlock 1, pred: 0, succ: 2\n"
+ " 5: Neg(2) [8]\n"
+ " 8: Return(5)\n"
+ "BasicBlock 2, pred: 1\n"
+ " 9: Exit\n";
+
+ // Expected difference after constant folding.
+ diff_t expected_cf_diff = {
+ { " 2: IntConstant [5]\n", " 2: IntConstant\n" },
+ { " 5: Neg(2) [8]\n", " 12: IntConstant [8]\n" },
+ { " 8: Return(5)\n", " 8: Return(12)\n" }
+ };
+ std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
+
+ // Check the value of the computed constant.
+ auto check_after_cf = [](HGraph* graph) {
+ HInstruction* inst = graph->GetBlock(1)->GetFirstInstruction();
+ ASSERT_TRUE(inst->IsIntConstant());
+ ASSERT_EQ(inst->AsIntConstant()->GetValue(), -1);
+ };
+
+ // Expected difference after dead code elimination.
+ diff_t expected_dce_diff = {
+ { " 2: IntConstant\n", removed },
+ };
+ std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
+
+ TestCode(data,
+ expected_before,
+ expected_after_cf,
+ expected_after_dce,
+ check_after_cf);
+}
+
+/**
* Tiny three-register program exercising int constant folding on addition.
*
* 16-bit