getInMutable().assign(lhs.getIn());
return getResult();
}
- Type resType = getType();
- unsigned bitWidth;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- bitWidth = shapedType.getElementTypeBitWidth();
- else
- bitWidth = resType.getIntOrFloatBitWidth();
+
+ Type resType = getElementTypeOrSelf(getType());
+ unsigned bitWidth = resType.cast<IntegerType>().getWidth();
return constFoldCastOp<IntegerAttr, IntegerAttr>(
operands, getType(), [bitWidth](const APInt &a, bool &castStatus) {
return a.zext(bitWidth);
getInMutable().assign(lhs.getIn());
return getResult();
}
- Type resType = getType();
- unsigned bitWidth;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- bitWidth = shapedType.getElementTypeBitWidth();
- else
- bitWidth = resType.getIntOrFloatBitWidth();
+
+ Type resType = getElementTypeOrSelf(getType());
+ unsigned bitWidth = resType.cast<IntegerType>().getWidth();
return constFoldCastOp<IntegerAttr, IntegerAttr>(
operands, getType(), [bitWidth](const APInt &a, bool &castStatus) {
return a.sext(bitWidth);
return getResult();
}
- Type resType = getType();
- unsigned bitWidth;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- bitWidth = shapedType.getElementTypeBitWidth();
- else
- bitWidth = resType.getIntOrFloatBitWidth();
-
+ Type resType = getElementTypeOrSelf(getType());
+ unsigned bitWidth = resType.cast<IntegerType>().getWidth();
return constFoldCastOp<IntegerAttr, IntegerAttr>(
operands, getType(), [bitWidth](const APInt &a, bool &castStatus) {
return a.trunc(bitWidth);
}
OpFoldResult arith::UIToFPOp::fold(ArrayRef<Attribute> operands) {
- Type resType = getType();
- Type resEleType;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- resEleType = shapedType.getElementType();
- else
- resEleType = resType;
+ Type resEleType = getElementTypeOrSelf(getType());
return constFoldCastOp<IntegerAttr, FloatAttr>(
operands, getType(), [&resEleType](const APInt &a, bool &castStatus) {
FloatType floatTy = resEleType.cast<FloatType>();
}
OpFoldResult arith::SIToFPOp::fold(ArrayRef<Attribute> operands) {
- Type resType = getType();
- Type resEleType;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- resEleType = shapedType.getElementType();
- else
- resEleType = resType;
+ Type resEleType = getElementTypeOrSelf(getType());
return constFoldCastOp<IntegerAttr, FloatAttr>(
operands, getType(), [&resEleType](const APInt &a, bool &castStatus) {
FloatType floatTy = resEleType.cast<FloatType>();
}
OpFoldResult arith::FPToUIOp::fold(ArrayRef<Attribute> operands) {
- Type resType = getType();
- Type resEleType;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- resEleType = shapedType.getElementType();
- else
- resEleType = resType;
+ Type resType = getElementTypeOrSelf(getType());
+ unsigned bitWidth = resType.cast<IntegerType>().getWidth();
return constFoldCastOp<FloatAttr, IntegerAttr>(
- operands, getType(), [&resEleType](const APFloat &a, bool &castStatus) {
- IntegerType intTy = resEleType.cast<IntegerType>();
+ operands, getType(), [&bitWidth](const APFloat &a, bool &castStatus) {
bool ignored;
- APSInt api(intTy.getWidth(), /*isUnsigned=*/true);
+ APSInt api(bitWidth, /*isUnsigned=*/true);
castStatus = APFloat::opInvalidOp !=
a.convertToInteger(api, APFloat::rmTowardZero, &ignored);
return api;
}
OpFoldResult arith::FPToSIOp::fold(ArrayRef<Attribute> operands) {
- Type resType = getType();
- Type resEleType;
- if (auto shapedType = resType.dyn_cast<ShapedType>())
- resEleType = shapedType.getElementType();
- else
- resEleType = resType;
+ Type resType = getElementTypeOrSelf(getType());
+ unsigned bitWidth = resType.cast<IntegerType>().getWidth();
return constFoldCastOp<FloatAttr, IntegerAttr>(
- operands, getType(), [&resEleType](const APFloat &a, bool &castStatus) {
- IntegerType intTy = resEleType.cast<IntegerType>();
+ operands, getType(), [&bitWidth](const APFloat &a, bool &castStatus) {
bool ignored;
- APSInt api(intTy.getWidth(), /*isUnsigned=*/false);
+ APSInt api(bitWidth, /*isUnsigned=*/false);
castStatus = APFloat::opInvalidOp !=
a.convertToInteger(api, APFloat::rmTowardZero, &ignored);
return api;