Test that A + 0 is simplified to A
| 56 | |
| 57 | // Test that A + 0 is simplified to A |
| 58 | TEST_F(AlgebraicSimplifierTest, AddZero) { |
| 59 | auto m = CreateNewVerifiedModule(); |
| 60 | Shape r0f32 = ShapeUtil::MakeShape(F32, {}); |
| 61 | HloComputation::Builder builder(TestName()); |
| 62 | HloInstruction* param0 = builder.AddInstruction( |
| 63 | HloInstruction::CreateParameter(0, r0f32, "param0")); |
| 64 | HloInstruction* zero = builder.AddInstruction( |
| 65 | HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.0f))); |
| 66 | builder.AddInstruction( |
| 67 | HloInstruction::CreateBinary(r0f32, HloOpcode::kAdd, param0, zero)); |
| 68 | |
| 69 | auto computation = m->AddEntryComputation(builder.Build()); |
| 70 | HloInstruction* root = computation->root_instruction(); |
| 71 | EXPECT_EQ(root->opcode(), HloOpcode::kAdd); |
| 72 | AlgebraicSimplifier simplifier(default_options_); |
| 73 | ASSERT_TRUE(simplifier.Run(m.get()).ValueOrDie()); |
| 74 | root = computation->root_instruction(); |
| 75 | EXPECT_EQ(root, param0); |
| 76 | } |
| 77 | |
| 78 | TEST_F(AlgebraicSimplifierTest, FactorIntegerAddition) { |
| 79 | const char* kModuleStr = R"( |
nothing calls this directly
no test coverage detected