[clang] [CIR] Upstream overflow builtins (PR #166643)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 5 13:55:09 PST 2025
================
@@ -2503,6 +2503,118 @@ mlir::LogicalResult CIRToLLVMCmpOpLowering::matchAndRewrite(
return cmpOp.emitError() << "unsupported type for CmpOp: " << type;
}
+mlir::LogicalResult CIRToLLVMBinOpOverflowOpLowering::matchAndRewrite(
+ cir::BinOpOverflowOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ auto loc = op.getLoc();
+ auto arithKind = op.getKind();
+ auto operandTy = op.getLhs().getType();
+ auto resultTy = op.getResult().getType();
+
+ auto encompassedTyInfo = computeEncompassedTypeWidth(operandTy, resultTy);
+ auto encompassedLLVMTy = rewriter.getIntegerType(encompassedTyInfo.width);
+
+ auto lhs = adaptor.getLhs();
+ auto rhs = adaptor.getRhs();
+ if (operandTy.getWidth() < encompassedTyInfo.width) {
+ if (operandTy.isSigned()) {
+ lhs = rewriter.create<mlir::LLVM::SExtOp>(loc, encompassedLLVMTy, lhs);
+ rhs = rewriter.create<mlir::LLVM::SExtOp>(loc, encompassedLLVMTy, rhs);
+ } else {
+ lhs = rewriter.create<mlir::LLVM::ZExtOp>(loc, encompassedLLVMTy, lhs);
+ rhs = rewriter.create<mlir::LLVM::ZExtOp>(loc, encompassedLLVMTy, rhs);
----------------
xlauko wrote:
rewriter.create is deprecated construct, use `Op::create(rewriter,` instead
https://github.com/llvm/llvm-project/pull/166643
More information about the cfe-commits
mailing list