Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion xla/hlo/ir/hlo_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6043,7 +6043,13 @@ void HloInstruction::set_output_to_operand_aliasing(
}

std::shared_ptr<OriginalValue> HloInstruction::original_value() const {
return original_value_;
if (original_value_ != nullptr || opcode_ != HloOpcode::kGetTupleElement) {
return original_value_;
}
const HloInstruction* tuple = operand(0);
return tuple->opcode() == HloOpcode::kTuple
? tuple->operand(tuple_index())->original_value()
: nullptr;
}

void HloInstruction::set_original_value(
Expand Down
19 changes: 19 additions & 0 deletions xla/hlo/ir/hlo_original_value_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,24 @@ ENTRY main {
EXPECT_EQ(p0->original_value(), p1->original_value());
}

TEST_F(OriginalValueHloTest, InferGetTupleElementOriginalValue) {
const char* hlo_string = R"(
HloModule test

ENTRY main {
p0 = f32[] parameter(0), origin={{"p0"}}
p1 = f32[] parameter(1)
tuple = (f32[], f32[]) tuple(p0, p1)
ROOT gte = f32[] get-tuple-element(tuple), index=0
}
)";
TF_ASSERT_OK_AND_ASSIGN(auto module,
ParseAndReturnVerifiedModule(hlo_string));
const HloInstruction* gte = module->entry_computation()->root_instruction();

EXPECT_NE(gte->original_value(), nullptr);
EXPECT_EQ(gte->original_value()->ToString(), R"({"p0"})");
}

} // namespace
} // namespace xla
Loading