================
@@ -425,6 +425,22 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
// Cast/Conversion Operators
//===--------------------------------------------------------------------===//
+ /// Create an value truncation to a narrower type.
+ /// Returns the source if types already match. CIR casts do not
+ /// encode NUW/NSW; wrap semantics should be handled by callers.
+ /// Supports both scalar integers and vectors of integers.
+ mlir::Value createTrunc(mlir::Location loc, mlir::Value src,
+ mlir::Type newTy) {
+ auto srcIntTy = mlir::dyn_cast<cir::VectorType>(src.getType());
+ if (newTy == srcIntTy)
+ return src;
+ return createCast(loc, cir::CastKind::integral, src, newTy);
+ }
+
+ mlir::Value createTrunc(mlir::Value src, mlir::Type newTy) {
+ return createTrunc(src.getLoc(), src, newTy);
+ }
----------------
badumbatish wrote:
it seems we can compress this into 1 function? the former is only called by the
latter.
https://github.com/llvm/llvm-project/pull/173802
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits