From e87d53742b5844f32a70f1f0f952174e9b065222 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 4 Dec 2020 00:03:15 -0800 Subject: [PATCH] Fix handling of negative seeds in random number generator op kernels for XLA Casting negative s32 number to u64 directly will have leading 1s in the representation which is not what we want to get a single u64 out of two s32 seeds. Fixed this by first getting unsigned number of the same bit-width. PiperOrigin-RevId: 345618958 --- lib/Dialect/mhlo/IR/hlo_ops.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/Dialect/mhlo/IR/hlo_ops.cc b/lib/Dialect/mhlo/IR/hlo_ops.cc index 4fc3e7e..64b42c9 100644 --- a/lib/Dialect/mhlo/IR/hlo_ops.cc +++ b/lib/Dialect/mhlo/IR/hlo_ops.cc @@ -518,19 +518,11 @@ void ConvertOp::build(OpBuilder& builder, OperationState& result, Value operand, } OpFoldResult ConvertOp::fold(ArrayRef operands) { - auto operand_ty = getOperand().getType().cast(); - auto result_ty = getResult().getType().cast(); - if (operand_ty == result_ty) return getOperand(); + if (getOperand().getType() == getResult().getType()) return getOperand(); // If the result has non-static shape, a convert op is necessary to go from // static shape to non-static shape. - if (!result_ty.hasStaticShape()) return {}; - - // TODO(hinsu): Handle unsigned types. - if (operand_ty.getElementType().isUnsignedInteger() || - result_ty.getElementType().isUnsignedInteger()) { - return {}; - } + if (!getResult().getType().cast().hasStaticShape()) return {}; // If the operand is constant, we can do the conversion now. if (auto elementsAttr = operands.front().dyn_cast_or_null()) {