Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ class ConvertToLibdevice : public mlir::OpRewritePattern<OpTy> {

llvm::SmallVector<Value, 2> casted_inputs;
if (output_type_is_16bit_float &&
(output_type.isF16() &&
!HasF16Implementation(OpInfo<OpTy>::kFunctionID, triple_))) {
(output_type.isBF16() ||
(output_type.isF16() &&
!HasF16Implementation(OpInfo<OpTy>::kFunctionID, triple_)))) {
// Upcast the inputs to F32.
for (auto operand : op->getOperands()) {
casted_inputs.push_back(
Expand All @@ -213,8 +214,9 @@ class ConvertToLibdevice : public mlir::OpRewritePattern<OpTy> {
/*pure=*/true);

if (res.getType() != output_type ||
(output_type.isF16() &&
!HasF16Implementation(OpInfo<OpTy>::kFunctionID, triple_))) {
(output_type.isBF16() ||
(output_type.isF16() &&
!HasF16Implementation(OpInfo<OpTy>::kFunctionID, triple_)))) {
Comment on lines 216 to +219
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fragile downcast condition — The output_type.isBF16() disjunction here can be true even when res.getType() == output_type. In practice this doesn't fire because bf16 always enters the upcast path above, so res will have type f32 and res.getType() != output_type is already sufficient. But the condition is fragile: if someone later changes the upcast logic without updating this downcast logic, the isBF16() arm could trigger a spurious bf16→bf16 cast.

Consider simplifying the downcast condition to just res.getType() != output_type, which is correct in all cases and doesn't duplicate the logic of the upcast block.

// Downcast back to the original output type.
res = ::xla::xtile::Cast(builder, res, output_type);
}
Expand Down
Loading