Test that a conditional of simple constants is transformed to a select
| 37 | |
| 38 | // Test that a conditional of simple constants is transformed to a select |
| 39 | TEST_F(ConditionalToSelectTest, MapConditionalConstants) { |
| 40 | const string hlo_text = R"( |
| 41 | HloModule MapConditionalConstants |
| 42 | |
| 43 | if { |
| 44 | %pif = () parameter(0) |
| 45 | ROOT %cif = f32[] constant(0) |
| 46 | } |
| 47 | |
| 48 | else { |
| 49 | %pelse = () parameter(0) |
| 50 | ROOT %celse = f32[] constant(1) |
| 51 | } |
| 52 | |
| 53 | mapped { |
| 54 | %a = f32[] parameter(0) |
| 55 | %b = f32[] parameter(1) |
| 56 | %lt = pred[] compare(%a, %b), direction=LT |
| 57 | %t = () tuple() |
| 58 | ROOT %conditional = f32[] conditional(%lt, %t, %t), true_computation=if, false_computation=else |
| 59 | } |
| 60 | |
| 61 | ENTRY comp { |
| 62 | %p1 = f32[1000]{0} parameter(0) |
| 63 | %p2 = f32[1000]{0} parameter(1) |
| 64 | ROOT %mapped = f32[1000]{0} map(%p1, %p2), dimensions={0}, to_apply=mapped |
| 65 | } |
| 66 | )"; |
| 67 | |
| 68 | auto module = ParseAndReturnVerifiedModule(hlo_text).ValueOrDie(); |
| 69 | ConditionalToSelect pass; |
| 70 | ASSERT_TRUE(pass.Run(&*module).ValueOrDie()); |
| 71 | |
| 72 | HloInstruction* root = module->entry_computation()->root_instruction(); |
| 73 | ASSERT_EQ(root->opcode(), HloOpcode::kMap); |
| 74 | HloComputation* mapped = root->called_computations()[0]; |
| 75 | EXPECT_THAT(mapped->root_instruction(), |
| 76 | op::Select(op::Lt(op::Parameter(0), op::Parameter(1)), |
| 77 | op::Constant(), op::Constant())); |
| 78 | } |
| 79 | |
| 80 | // Test that the condition gets broadcasted for feeding into |
| 81 | // select when the output is non-scalar. |
nothing calls this directly
no test coverage detected