Lines Matching defs:arith

25 namespace mlir::arith {
28 } // namespace mlir::arith
174 struct ConvertConstant final : OpConversionPattern<arith::ConstantOp> {
178 matchAndRewrite(arith::ConstantOp op, OpAdaptor,
192 rewriter.replaceOpWithNewOp<arith::ConstantOp>(op, newAttr);
208 rewriter.replaceOpWithNewOp<arith::ConstantOp>(op, attr);
223 rewriter.replaceOpWithNewOp<arith::ConstantOp>(op, attr);
236 struct ConvertAddI final : OpConversionPattern<arith::AddIOp> {
240 matchAndRewrite(arith::AddIOp op, OpAdaptor adaptor,
256 rewriter.create<arith::AddUIExtendedOp>(loc, lhsElem0, rhsElem0);
258 rewriter.create<arith::ExtUIOp>(loc, newElemTy, lowSum.getOverflow());
260 Value high0 = rewriter.create<arith::AddIOp>(loc, overflowVal, lhsElem1);
261 Value high = rewriter.create<arith::AddIOp>(loc, high0, rhsElem1);
274 /// Conversion pattern template for bitwise binary ops, e.g., `arith.andi`.
310 static arith::CmpIPredicate toUnsignedPredicate(arith::CmpIPredicate pred) {
311 using P = arith::CmpIPredicate;
326 struct ConvertCmpI final : OpConversionPattern<arith::CmpIOp> {
330 matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
339 arith::CmpIPredicate highPred = adaptor.getPredicate();
340 arith::CmpIPredicate lowPred = toUnsignedPredicate(highPred);
348 rewriter.create<arith::CmpIOp>(loc, lowPred, lhsElem0, rhsElem0);
350 rewriter.create<arith::CmpIOp>(loc, highPred, lhsElem1, rhsElem1);
354 case arith::CmpIPredicate::eq: {
355 cmpResult = rewriter.create<arith::AndIOp>(loc, lowCmp, highCmp);
358 case arith::CmpIPredicate::ne: {
359 cmpResult = rewriter.create<arith::OrIOp>(loc, lowCmp, highCmp);
364 Value highEq = rewriter.create<arith::CmpIOp>(
365 loc, arith::CmpIPredicate::eq, lhsElem1, rhsElem1);
367 rewriter.create<arith::SelectOp>(loc, highEq, lowCmp, highCmp);
382 struct ConvertMulI final : OpConversionPattern<arith::MulIOp> {
386 matchAndRewrite(arith::MulIOp op, OpAdaptor adaptor,
403 rewriter.create<arith::MulUIExtendedOp>(loc, lhsElem0, rhsElem0);
404 Value mulLowHi = rewriter.create<arith::MulIOp>(loc, lhsElem0, rhsElem1);
405 Value mulHiLow = rewriter.create<arith::MulIOp>(loc, lhsElem1, rhsElem0);
409 rewriter.create<arith::AddIOp>(loc, mulLowLow.getHigh(), mulLowHi);
410 resHi = rewriter.create<arith::AddIOp>(loc, resHi, mulHiLow);
423 struct ConvertExtSI final : OpConversionPattern<arith::ExtSIOp> {
427 matchAndRewrite(arith::ExtSIOp op, OpAdaptor adaptor,
441 Value extended = rewriter.createOrFold<arith::ExtSIOp>(
445 Value signBit = rewriter.create<arith::CmpIOp>(
446 loc, arith::CmpIPredicate::slt, extended, operandZeroCst);
448 rewriter.create<arith::ExtSIOp>(loc, newResultComponentTy, signBit);
461 struct ConvertExtUI final : OpConversionPattern<arith::ExtUIOp> {
465 matchAndRewrite(arith::ExtUIOp op, OpAdaptor adaptor,
478 Value extended = rewriter.createOrFold<arith::ExtUIOp>(
491 template <typename SourceOp, arith::CmpIPredicate CmpPred>
510 rewriter.create<arith::CmpIOp>(loc, CmpPred, op.getLhs(), op.getRhs());
511 rewriter.replaceOpWithNewOp<arith::SelectOp>(op, cmp, op.getLhs(),
572 this->template getTypeConverter<arith::WideIntEmulationConverter>();
599 struct ConvertSelect final : OpConversionPattern<arith::SelectOp> {
603 matchAndRewrite(arith::SelectOp op, OpAdaptor adaptor,
618 rewriter.create<arith::SelectOp>(loc, cond, trueElem0, falseElem0);
620 rewriter.create<arith::SelectOp>(loc, cond, trueElem1, falseElem1);
632 struct ConvertShLI final : OpConversionPattern<arith::ShLIOp> {
636 matchAndRewrite(arith::ShLIOp op, OpAdaptor adaptor,
682 Value illegalElemShift = rewriter.create<arith::CmpIOp>(
683 loc, arith::CmpIPredicate::uge, rhsElem0, elemBitWidth);
686 rewriter.create<arith::ShLIOp>(loc, lhsElem0, rhsElem0);
687 Value resElem0 = rewriter.create<arith::SelectOp>(loc, illegalElemShift,
690 Value cappedShiftAmount = rewriter.create<arith::SelectOp>(
693 rewriter.create<arith::SubIOp>(loc, elemBitWidth, cappedShiftAmount);
695 rewriter.create<arith::ShRUIOp>(loc, lhsElem0, rightShiftAmount);
697 rewriter.create<arith::SubIOp>(loc, rhsElem0, elemBitWidth);
699 rewriter.create<arith::ShLIOp>(loc, lhsElem0, overshotShiftAmount);
702 rewriter.create<arith::ShLIOp>(loc, lhsElem1, rhsElem0);
703 Value resElem1High = rewriter.create<arith::SelectOp>(
705 Value resElem1Low = rewriter.create<arith::SelectOp>(
708 rewriter.create<arith::OrIOp>(loc, resElem1Low, resElem1High);
721 struct ConvertShRUI final : OpConversionPattern<arith::ShRUIOp> {
725 matchAndRewrite(arith::ShRUIOp op, OpAdaptor adaptor,
771 Value illegalElemShift = rewriter.create<arith::CmpIOp>(
772 loc, arith::CmpIPredicate::uge, rhsElem0, elemBitWidth);
775 rewriter.create<arith::ShRUIOp>(loc, lhsElem0, rhsElem0);
776 Value resElem0Low = rewriter.create<arith::SelectOp>(loc, illegalElemShift,
779 rewriter.create<arith::ShRUIOp>(loc, lhsElem1, rhsElem0);
780 Value resElem1 = rewriter.create<arith::SelectOp>(loc, illegalElemShift,
783 Value cappedShiftAmount = rewriter.create<arith::SelectOp>(
786 rewriter.create<arith::SubIOp>(loc, elemBitWidth, cappedShiftAmount);
788 rewriter.create<arith::ShLIOp>(loc, lhsElem1, leftShiftAmount);
790 rewriter.create<arith::SubIOp>(loc, rhsElem0, elemBitWidth);
792 rewriter.create<arith::ShRUIOp>(loc, lhsElem1, overshotShiftAmount);
794 Value resElem0High = rewriter.create<arith::SelectOp>(
797 rewriter.create<arith::OrIOp>(loc, resElem0Low, resElem0High);
810 struct ConvertShRSI final : OpConversionPattern<arith::ShRSIOp> {
814 matchAndRewrite(arith::ShRSIOp op, OpAdaptor adaptor,
830 // Rewrite this as an bitwise or of `arith.shrui` and sign extension bits.
834 Value signBit = rewriter.create<arith::CmpIOp>(
835 loc, arith::CmpIPredicate::slt, lhsElem1, elemZero);
841 Value allSign = rewriter.create<arith::ExtSIOp>(loc, oldTy, signBit);
845 rewriter.create<arith::SubIOp>(loc, maxShift, rhsElem0);
848 rewriter.create<arith::ExtUIOp>(loc, oldTy, numNonSignExtBits);
850 rewriter.create<arith::ShLIOp>(loc, allSign, numNonSignExtBits);
854 rewriter.create<arith::ShRUIOp>(loc, op.getLhs(), op.getRhs());
855 Value shrsi = rewriter.create<arith::OrIOp>(loc, shrui, signBits);
859 Value isNoop = rewriter.create<arith::CmpIOp>(loc, arith::CmpIPredicate::eq,
862 rewriter.replaceOpWithNewOp<arith::SelectOp>(op, isNoop, op.getLhs(),
873 struct ConvertSIToFP final : OpConversionPattern<arith::SIToFPOp> {
877 matchAndRewrite(arith::SIToFPOp op, OpAdaptor adaptor,
900 Value isNeg = rewriter.create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt,
902 Value bitwiseNeg = rewriter.create<arith::XOrIOp>(loc, in, allOnesCst);
903 Value neg = rewriter.create<arith::AddIOp>(loc, bitwiseNeg, oneCst);
904 Value abs = rewriter.create<arith::SelectOp>(loc, isNeg, neg, in);
906 Value absResult = rewriter.create<arith::UIToFPOp>(loc, op.getType(), abs);
907 Value negResult = rewriter.create<arith::NegFOp>(loc, absResult);
908 rewriter.replaceOpWithNewOp<arith::SelectOp>(op, isNeg, negResult,
918 struct ConvertUIToFP final : OpConversionPattern<arith::UIToFPOp> {
922 matchAndRewrite(arith::UIToFPOp op, OpAdaptor adaptor,
953 Value hiEqZero = rewriter.create<arith::CmpIOp>(
954 loc, arith::CmpIPredicate::eq, hiInt, zeroCst);
958 Value lowFp = rewriter.create<arith::UIToFPOp>(loc, resultTy, lowInt);
959 Value hiFp = rewriter.create<arith::UIToFPOp>(loc, resultTy, hiInt);
967 Value pow2Val = rewriter.create<arith::ConstantOp>(loc, resultTy, pow2Attr);
969 Value hiVal = rewriter.create<arith::MulFOp>(loc, hiFp, pow2Val);
970 Value result = rewriter.create<arith::AddFOp>(loc, lowFp, hiVal);
972 rewriter.replaceOpWithNewOp<arith::SelectOp>(op, hiEqZero, lowFp, result);
981 struct ConvertTruncI final : OpConversionPattern<arith::TruncIOp> {
985 matchAndRewrite(arith::TruncIOp op, OpAdaptor adaptor,
1000 rewriter.createOrFold<arith::TruncIOp>(loc, op.getType(), extracted);
1026 : arith::impl::ArithEmulateWideIntBase<EmulateWideIntPass> {
1038 arith::WideIntEmulationConverter typeConverter(widestIntSupported);
1048 .addDynamicallyLegalDialect<arith::ArithDialect, vector::VectorDialect>(
1052 arith::populateArithWideIntEmulationPatterns(typeConverter, patterns);
1064 arith::WideIntEmulationConverter::WideIntEmulationConverter(
1124 void arith::populateArithWideIntEmulationPatterns(
1133 // Populate `arith.*` conversion patterns.
1139 ConvertMaxMin<arith::MaxUIOp, arith::CmpIPredicate::ugt>,
1140 ConvertMaxMin<arith::MaxSIOp, arith::CmpIPredicate::sgt>,
1141 ConvertMaxMin<arith::MinUIOp, arith::CmpIPredicate::ult>,
1142 ConvertMaxMin<arith::MinSIOp, arith::CmpIPredicate::slt>,
1144 ConvertBitwiseBinary<arith::AndIOp>, ConvertBitwiseBinary<arith::OrIOp>,
1145 ConvertBitwiseBinary<arith::XOrIOp>,
1149 ConvertIndexCastIntToIndex<arith::IndexCastOp>,
1150 ConvertIndexCastIntToIndex<arith::IndexCastUIOp>,
1151 ConvertIndexCastIndexToInt<arith::IndexCastOp, arith::ExtSIOp>,
1152 ConvertIndexCastIndexToInt<arith::IndexCastUIOp, arith::ExtUIOp>,