[mlir][Math] Fix RoundEven constant folder.

Use roundToIntegral instead roundeven of libm to avoid window build failed.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D133402
This commit is contained in:
jacquesguan 2022-09-07 12:45:57 +00:00 committed by Mehdi Amini
parent 7c57180900
commit 238e08d643
1 changed files with 5 additions and 11 deletions

View File

@ -420,17 +420,11 @@ OpFoldResult math::TanhOp::fold(ArrayRef<Attribute> operands) {
//===----------------------------------------------------------------------===//
OpFoldResult math::RoundEvenOp::fold(ArrayRef<Attribute> operands) {
return constFoldUnaryOpConditional<FloatAttr>(
operands, [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(roundeven(a.convertToDouble()));
case 32:
return APFloat(roundevenf(a.convertToFloat()));
default:
return {};
}
});
return constFoldUnaryOp<FloatAttr>(operands, [](const APFloat &a) {
APFloat result(a);
result.roundToIntegral(llvm::RoundingMode::NearestTiesToEven);
return result;
});
}
/// Materialize an integer or floating point constant.