It is safe to fold when extending, as we will not lose precision.
Differential Revision: https://reviews.llvm.org/D144251
When operating on vectors, casts elementwise.
}];
let hasVerifier = 1;
+ let hasFolder = 1;
}
//===----------------------------------------------------------------------===//
// ExtFOp
//===----------------------------------------------------------------------===//
+/// Always fold extension of FP constants.
+OpFoldResult arith::ExtFOp::fold(FoldAdaptor adaptor) {
+ auto constOperand = adaptor.getIn().dyn_cast_or_null<FloatAttr>();
+ if (!constOperand)
+ return {};
+
+ // Convert to target type via 'double'.
+ return FloatAttr::get(getType(), constOperand.getValue().convertToDouble());
+}
+
bool arith::ExtFOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
return checkWidthChangeCast<std::greater, FloatType>(inputs, outputs);
}
return %ext : vector<4xi16>
}
+// CHECK-LABEL: @extFPConstant
+// CHECK: %[[cres:.+]] = arith.constant 1.000000e+00 : f64
+// CHECK: return %[[cres]]
+func.func @extFPConstant() -> f64 {
+ %cst = arith.constant 1.000000e+00 : f32
+ %0 = arith.extf %cst : f32 to f64
+ return %0 : f64
+}
+
// CHECK-LABEL: @truncConstant
// CHECK: %[[cres:.+]] = arith.constant -2 : i16
// CHECK: return %[[cres]]