[Mlir-commits] [mlir] 942be7c - [mlir] Add DivOp lowering from Complex dialect to Standard/Math dialect.
Adrian Kuegel
llvmlistbot at llvm.org
Wed Jun 2 02:16:24 PDT 2021
Author: Adrian Kuegel
Date: 2021-06-02T11:16:00+02:00
New Revision: 942be7cb4d98eb1fa0ffdc5d122e8c931cbc4cd6
URL: https://github.com/llvm/llvm-project/commit/942be7cb4d98eb1fa0ffdc5d122e8c931cbc4cd6
DIFF: https://github.com/llvm/llvm-project/commit/942be7cb4d98eb1fa0ffdc5d122e8c931cbc4cd6.diff
LOG: [mlir] Add DivOp lowering from Complex dialect to Standard/Math dialect.
Differential Revision: https://reviews.llvm.org/D103507
Added:
Modified:
mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index 5b1765407e690..f5c06638c86e2 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -77,14 +77,223 @@ struct ComparisonOpConversion : public OpConversionPattern<ComparisonOp> {
return success();
}
};
+
+struct DivOpConversion : public OpConversionPattern<complex::DivOp> {
+ using OpConversionPattern<complex::DivOp>::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(complex::DivOp op, ArrayRef<Value> operands,
+ ConversionPatternRewriter &rewriter) const override {
+ complex::DivOp::Adaptor transformed(operands);
+ auto loc = op.getLoc();
+ auto type = transformed.lhs().getType().template cast<ComplexType>();
+ auto elementType = type.getElementType().cast<FloatType>();
+
+ Value lhsReal =
+ rewriter.create<complex::ReOp>(loc, elementType, transformed.lhs());
+ Value lhsImag =
+ rewriter.create<complex::ImOp>(loc, elementType, transformed.lhs());
+ Value rhsReal =
+ rewriter.create<complex::ReOp>(loc, elementType, transformed.rhs());
+ Value rhsImag =
+ rewriter.create<complex::ImOp>(loc, elementType, transformed.rhs());
+
+ // Smith's algorithm to divide complex numbers. It is just a bit smarter
+ // way to compute the following formula:
+ // (lhsReal + lhsImag * i) / (rhsReal + rhsImag * i)
+ // = (lhsReal + lhsImag * i) (rhsReal - rhsImag * i) /
+ // ((rhsReal + rhsImag * i)(rhsReal - rhsImag * i))
+ // = ((lhsReal * rhsReal + lhsImag * rhsImag) +
+ // (lhsImag * rhsReal - lhsReal * rhsImag) * i) / ||rhs||^2
+ //
+ // Depending on whether |rhsReal| < |rhsImag| we compute either
+ // rhsRealImagRatio = rhsReal / rhsImag
+ // rhsRealImagDenom = rhsImag + rhsReal * rhsRealImagRatio
+ // resultReal = (lhsReal * rhsRealImagRatio + lhsImag) / rhsRealImagDenom
+ // resultImag = (lhsImag * rhsRealImagRatio - lhsReal) / rhsRealImagDenom
+ //
+ // or
+ //
+ // rhsImagRealRatio = rhsImag / rhsReal
+ // rhsImagRealDenom = rhsReal + rhsImag * rhsImagRealRatio
+ // resultReal = (lhsReal + lhsImag * rhsImagRealRatio) / rhsImagRealDenom
+ // resultImag = (lhsImag - lhsReal * rhsImagRealRatio) / rhsImagRealDenom
+ //
+ // See https://dl.acm.org/citation.cfm?id=368661 for more details.
+ Value rhsRealImagRatio = rewriter.create<DivFOp>(loc, rhsReal, rhsImag);
+ Value rhsRealImagDenom = rewriter.create<AddFOp>(
+ loc, rhsImag, rewriter.create<MulFOp>(loc, rhsRealImagRatio, rhsReal));
+ Value realNumerator1 = rewriter.create<AddFOp>(
+ loc, rewriter.create<MulFOp>(loc, lhsReal, rhsRealImagRatio), lhsImag);
+ Value resultReal1 =
+ rewriter.create<DivFOp>(loc, realNumerator1, rhsRealImagDenom);
+ Value imagNumerator1 = rewriter.create<SubFOp>(
+ loc, rewriter.create<MulFOp>(loc, lhsImag, rhsRealImagRatio), lhsReal);
+ Value resultImag1 =
+ rewriter.create<DivFOp>(loc, imagNumerator1, rhsRealImagDenom);
+
+ Value rhsImagRealRatio = rewriter.create<DivFOp>(loc, rhsImag, rhsReal);
+ Value rhsImagRealDenom = rewriter.create<AddFOp>(
+ loc, rhsReal, rewriter.create<MulFOp>(loc, rhsImagRealRatio, rhsImag));
+ Value realNumerator2 = rewriter.create<AddFOp>(
+ loc, lhsReal, rewriter.create<MulFOp>(loc, lhsImag, rhsImagRealRatio));
+ Value resultReal2 =
+ rewriter.create<DivFOp>(loc, realNumerator2, rhsImagRealDenom);
+ Value imagNumerator2 = rewriter.create<SubFOp>(
+ loc, lhsImag, rewriter.create<MulFOp>(loc, lhsReal, rhsImagRealRatio));
+ Value resultImag2 =
+ rewriter.create<DivFOp>(loc, imagNumerator2, rhsImagRealDenom);
+
+ // Consider corner cases.
+ // Case 1. Zero denominator, numerator contains at most one NaN value.
+ Value zero = rewriter.create<ConstantOp>(loc, elementType,
+ rewriter.getZeroAttr(elementType));
+ Value rhsRealAbs = rewriter.create<AbsFOp>(loc, rhsReal);
+ Value rhsRealIsZero =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, rhsRealAbs, zero);
+ Value rhsImagAbs = rewriter.create<AbsFOp>(loc, rhsImag);
+ Value rhsImagIsZero =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, rhsImagAbs, zero);
+ Value lhsRealIsNotNaN =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ORD, lhsReal, zero);
+ Value lhsImagIsNotNaN =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ORD, lhsImag, zero);
+ Value lhsContainsNotNaNValue =
+ rewriter.create<OrOp>(loc, lhsRealIsNotNaN, lhsImagIsNotNaN);
+ Value resultIsInfinity = rewriter.create<AndOp>(
+ loc, lhsContainsNotNaNValue,
+ rewriter.create<AndOp>(loc, rhsRealIsZero, rhsImagIsZero));
+ Value inf = rewriter.create<ConstantOp>(
+ loc, elementType,
+ rewriter.getFloatAttr(
+ elementType, APFloat::getInf(elementType.getFloatSemantics())));
+ Value infWithSignOfRhsReal = rewriter.create<CopySignOp>(loc, inf, rhsReal);
+ Value infinityResultReal =
+ rewriter.create<MulFOp>(loc, infWithSignOfRhsReal, lhsReal);
+ Value infinityResultImag =
+ rewriter.create<MulFOp>(loc, infWithSignOfRhsReal, lhsImag);
+
+ // Case 2. Infinite numerator, finite denominator.
+ Value rhsRealFinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ONE, rhsRealAbs, inf);
+ Value rhsImagFinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ONE, rhsImagAbs, inf);
+ Value rhsFinite = rewriter.create<AndOp>(loc, rhsRealFinite, rhsImagFinite);
+ Value lhsRealAbs = rewriter.create<AbsFOp>(loc, lhsReal);
+ Value lhsRealInfinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, lhsRealAbs, inf);
+ Value lhsImagAbs = rewriter.create<AbsFOp>(loc, lhsImag);
+ Value lhsImagInfinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, lhsImagAbs, inf);
+ Value lhsInfinite =
+ rewriter.create<OrOp>(loc, lhsRealInfinite, lhsImagInfinite);
+ Value infNumFiniteDenom =
+ rewriter.create<AndOp>(loc, lhsInfinite, rhsFinite);
+ Value one = rewriter.create<ConstantOp>(
+ loc, elementType, rewriter.getFloatAttr(elementType, 1));
+ Value lhsRealIsInfWithSign = rewriter.create<CopySignOp>(
+ loc, rewriter.create<SelectOp>(loc, lhsRealInfinite, one, zero),
+ lhsReal);
+ Value lhsImagIsInfWithSign = rewriter.create<CopySignOp>(
+ loc, rewriter.create<SelectOp>(loc, lhsImagInfinite, one, zero),
+ lhsImag);
+ Value lhsRealIsInfWithSignTimesRhsReal =
+ rewriter.create<MulFOp>(loc, lhsRealIsInfWithSign, rhsReal);
+ Value lhsImagIsInfWithSignTimesRhsImag =
+ rewriter.create<MulFOp>(loc, lhsImagIsInfWithSign, rhsImag);
+ Value resultReal3 = rewriter.create<MulFOp>(
+ loc, inf,
+ rewriter.create<AddFOp>(loc, lhsRealIsInfWithSignTimesRhsReal,
+ lhsImagIsInfWithSignTimesRhsImag));
+ Value lhsRealIsInfWithSignTimesRhsImag =
+ rewriter.create<MulFOp>(loc, lhsRealIsInfWithSign, rhsImag);
+ Value lhsImagIsInfWithSignTimesRhsReal =
+ rewriter.create<MulFOp>(loc, lhsImagIsInfWithSign, rhsReal);
+ Value resultImag3 = rewriter.create<MulFOp>(
+ loc, inf,
+ rewriter.create<SubFOp>(loc, lhsImagIsInfWithSignTimesRhsReal,
+ lhsRealIsInfWithSignTimesRhsImag));
+
+ // Case 3: Finite numerator, infinite denominator.
+ Value lhsRealFinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ONE, lhsRealAbs, inf);
+ Value lhsImagFinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::ONE, lhsImagAbs, inf);
+ Value lhsFinite = rewriter.create<AndOp>(loc, lhsRealFinite, lhsImagFinite);
+ Value rhsRealInfinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, rhsRealAbs, inf);
+ Value rhsImagInfinite =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::OEQ, rhsImagAbs, inf);
+ Value rhsInfinite =
+ rewriter.create<OrOp>(loc, rhsRealInfinite, rhsImagInfinite);
+ Value finiteNumInfiniteDenom =
+ rewriter.create<AndOp>(loc, lhsFinite, rhsInfinite);
+ Value rhsRealIsInfWithSign = rewriter.create<CopySignOp>(
+ loc, rewriter.create<SelectOp>(loc, rhsRealInfinite, one, zero),
+ rhsReal);
+ Value rhsImagIsInfWithSign = rewriter.create<CopySignOp>(
+ loc, rewriter.create<SelectOp>(loc, rhsImagInfinite, one, zero),
+ rhsImag);
+ Value rhsRealIsInfWithSignTimesLhsReal =
+ rewriter.create<MulFOp>(loc, lhsReal, rhsRealIsInfWithSign);
+ Value rhsImagIsInfWithSignTimesLhsImag =
+ rewriter.create<MulFOp>(loc, lhsImag, rhsImagIsInfWithSign);
+ Value resultReal4 = rewriter.create<MulFOp>(
+ loc, zero,
+ rewriter.create<AddFOp>(loc, rhsRealIsInfWithSignTimesLhsReal,
+ rhsImagIsInfWithSignTimesLhsImag));
+ Value rhsRealIsInfWithSignTimesLhsImag =
+ rewriter.create<MulFOp>(loc, lhsImag, rhsRealIsInfWithSign);
+ Value rhsImagIsInfWithSignTimesLhsReal =
+ rewriter.create<MulFOp>(loc, lhsReal, rhsImagIsInfWithSign);
+ Value resultImag4 = rewriter.create<MulFOp>(
+ loc, zero,
+ rewriter.create<SubFOp>(loc, rhsRealIsInfWithSignTimesLhsImag,
+ rhsImagIsInfWithSignTimesLhsReal));
+
+ Value realAbsSmallerThanImagAbs = rewriter.create<CmpFOp>(
+ loc, CmpFPredicate::OLT, rhsRealAbs, rhsImagAbs);
+ Value resultReal = rewriter.create<SelectOp>(loc, realAbsSmallerThanImagAbs,
+ resultReal1, resultReal2);
+ Value resultImag = rewriter.create<SelectOp>(loc, realAbsSmallerThanImagAbs,
+ resultImag1, resultImag2);
+ Value resultRealSpecialCase3 = rewriter.create<SelectOp>(
+ loc, finiteNumInfiniteDenom, resultReal4, resultReal);
+ Value resultImagSpecialCase3 = rewriter.create<SelectOp>(
+ loc, finiteNumInfiniteDenom, resultImag4, resultImag);
+ Value resultRealSpecialCase2 = rewriter.create<SelectOp>(
+ loc, infNumFiniteDenom, resultReal3, resultRealSpecialCase3);
+ Value resultImagSpecialCase2 = rewriter.create<SelectOp>(
+ loc, infNumFiniteDenom, resultImag3, resultImagSpecialCase3);
+ Value resultRealSpecialCase1 = rewriter.create<SelectOp>(
+ loc, resultIsInfinity, infinityResultReal, resultRealSpecialCase2);
+ Value resultImagSpecialCase1 = rewriter.create<SelectOp>(
+ loc, resultIsInfinity, infinityResultImag, resultImagSpecialCase2);
+
+ Value resultRealIsNaN =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::UNO, resultReal, zero);
+ Value resultImagIsNaN =
+ rewriter.create<CmpFOp>(loc, CmpFPredicate::UNO, resultImag, zero);
+ Value resultIsNaN =
+ rewriter.create<AndOp>(loc, resultRealIsNaN, resultImagIsNaN);
+ Value resultRealWithSpecialCases = rewriter.create<SelectOp>(
+ loc, resultIsNaN, resultRealSpecialCase1, resultReal);
+ Value resultImagWithSpecialCases = rewriter.create<SelectOp>(
+ loc, resultIsNaN, resultImagSpecialCase1, resultImag);
+
+ rewriter.replaceOpWithNewOp<complex::CreateOp>(
+ op, type, resultRealWithSpecialCases, resultImagWithSpecialCases);
+ return success();
+ }
+};
} // namespace
void mlir::populateComplexToStandardConversionPatterns(
RewritePatternSet &patterns) {
patterns.add<AbsOpConversion,
ComparisonOpConversion<complex::EqualOp, CmpFPredicate::OEQ>,
- ComparisonOpConversion<complex::NotEqualOp, CmpFPredicate::UNE>>(
- patterns.getContext());
+ ComparisonOpConversion<complex::NotEqualOp, CmpFPredicate::UNE>,
+ DivOpConversion>(patterns.getContext());
}
namespace {
@@ -103,7 +312,8 @@ void ConvertComplexToStandardPass::runOnFunction() {
ConversionTarget target(getContext());
target.addLegalDialect<StandardOpsDialect, math::MathDialect,
complex::ComplexDialect>();
- target.addIllegalOp<complex::AbsOp, complex::EqualOp, complex::NotEqualOp>();
+ target.addIllegalOp<complex::AbsOp, complex::DivOp, complex::EqualOp,
+ complex::NotEqualOp>();
if (failed(applyPartialConversion(function, target, std::move(patterns))))
signalPassFailure();
}
diff --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index d09f1a0cb708d..998104045720e 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -14,6 +14,115 @@ func @complex_abs(%arg: complex<f32>) -> f32 {
// CHECK: %[[NORM:.*]] = math.sqrt %[[SQ_NORM]] : f32
// CHECK: return %[[NORM]] : f32
+// CHECK-LABEL: func @complex_div
+// CHECK-SAME: (%[[LHS:.*]]: complex<f32>, %[[RHS:.*]]: complex<f32>)
+func @complex_div(%lhs: complex<f32>, %rhs: complex<f32>) -> complex<f32> {
+ %div = complex.div %lhs, %rhs : complex<f32>
+ return %div : complex<f32>
+}
+// CHECK: %[[LHS_REAL:.*]] = complex.re %[[LHS]] : complex<f32>
+// CHECK: %[[LHS_IMAG:.*]] = complex.im %[[LHS]] : complex<f32>
+// CHECK: %[[RHS_REAL:.*]] = complex.re %[[RHS]] : complex<f32>
+// CHECK: %[[RHS_IMAG:.*]] = complex.im %[[RHS]] : complex<f32>
+
+// CHECK: %[[RHS_REAL_IMAG_RATIO:.*]] = divf %[[RHS_REAL]], %[[RHS_IMAG]] : f32
+// CHECK: %[[RHS_REAL_TIMES_RHS_REAL_IMAG_RATIO:.*]] = mulf %[[RHS_REAL_IMAG_RATIO]], %[[RHS_REAL]] : f32
+// CHECK: %[[RHS_REAL_IMAG_DENOM:.*]] = addf %[[RHS_IMAG]], %[[RHS_REAL_TIMES_RHS_REAL_IMAG_RATIO]] : f32
+// CHECK: %[[LHS_REAL_TIMES_RHS_REAL_IMAG_RATIO:.*]] = mulf %[[LHS_REAL]], %[[RHS_REAL_IMAG_RATIO]] : f32
+// CHECK: %[[REAL_NUMERATOR_1:.*]] = addf %[[LHS_REAL_TIMES_RHS_REAL_IMAG_RATIO]], %[[LHS_IMAG]] : f32
+// CHECK: %[[RESULT_REAL_1:.*]] = divf %[[REAL_NUMERATOR_1]], %[[RHS_REAL_IMAG_DENOM]] : f32
+// CHECK: %[[LHS_IMAG_TIMES_RHS_REAL_IMAG_RATIO:.*]] = mulf %[[LHS_IMAG]], %[[RHS_REAL_IMAG_RATIO]] : f32
+// CHECK: %[[IMAG_NUMERATOR_1:.*]] = subf %[[LHS_IMAG_TIMES_RHS_REAL_IMAG_RATIO]], %[[LHS_REAL]] : f32
+// CHECK: %[[RESULT_IMAG_1:.*]] = divf %[[IMAG_NUMERATOR_1]], %[[RHS_REAL_IMAG_DENOM]] : f32
+
+// CHECK: %[[RHS_IMAG_REAL_RATIO:.*]] = divf %[[RHS_IMAG]], %[[RHS_REAL]] : f32
+// CHECK: %[[RHS_IMAG_TIMES_RHS_IMAG_REAL_RATIO:.*]] = mulf %[[RHS_IMAG_REAL_RATIO]], %[[RHS_IMAG]] : f32
+// CHECK: %[[RHS_IMAG_REAL_DENOM:.*]] = addf %[[RHS_REAL]], %[[RHS_IMAG_TIMES_RHS_IMAG_REAL_RATIO]] : f32
+// CHECK: %[[LHS_IMAG_TIMES_RHS_IMAG_REAL_RATIO:.*]] = mulf %[[LHS_IMAG]], %[[RHS_IMAG_REAL_RATIO]] : f32
+// CHECK: %[[REAL_NUMERATOR_2:.*]] = addf %[[LHS_REAL]], %[[LHS_IMAG_TIMES_RHS_IMAG_REAL_RATIO]] : f32
+// CHECK: %[[RESULT_REAL_2:.*]] = divf %[[REAL_NUMERATOR_2]], %[[RHS_IMAG_REAL_DENOM]] : f32
+// CHECK: %[[LHS_REAL_TIMES_RHS_IMAG_REAL_RATIO:.*]] = mulf %[[LHS_REAL]], %[[RHS_IMAG_REAL_RATIO]] : f32
+// CHECK: %[[IMAG_NUMERATOR_2:.*]] = subf %[[LHS_IMAG]], %[[LHS_REAL_TIMES_RHS_IMAG_REAL_RATIO]] : f32
+// CHECK: %[[RESULT_IMAG_2:.*]] = divf %[[IMAG_NUMERATOR_2]], %[[RHS_IMAG_REAL_DENOM]] : f32
+
+// Case 1. Zero denominator, numerator contains at most one NaN value.
+// CHECK: %[[ZERO:.*]] = constant 0.000000e+00 : f32
+// CHECK: %[[RHS_REAL_ABS:.*]] = absf %[[RHS_REAL]] : f32
+// CHECK: %[[RHS_REAL_ABS_IS_ZERO:.*]] = cmpf oeq, %[[RHS_REAL_ABS]], %[[ZERO]] : f32
+// CHECK: %[[RHS_IMAG_ABS:.*]] = absf %[[RHS_IMAG]] : f32
+// CHECK: %[[RHS_IMAG_ABS_IS_ZERO:.*]] = cmpf oeq, %[[RHS_IMAG_ABS]], %[[ZERO]] : f32
+// CHECK: %[[LHS_REAL_IS_NOT_NAN:.*]] = cmpf ord, %[[LHS_REAL]], %[[ZERO]] : f32
+// CHECK: %[[LHS_IMAG_IS_NOT_NAN:.*]] = cmpf ord, %[[LHS_IMAG]], %[[ZERO]] : f32
+// CHECK: %[[LHS_CONTAINS_NOT_NAN_VALUE:.*]] = or %[[LHS_REAL_IS_NOT_NAN]], %[[LHS_IMAG_IS_NOT_NAN]] : i1
+// CHECK: %[[RHS_IS_ZERO:.*]] = and %[[RHS_REAL_ABS_IS_ZERO]], %[[RHS_IMAG_ABS_IS_ZERO]] : i1
+// CHECK: %[[RESULT_IS_INFINITY:.*]] = and %[[LHS_CONTAINS_NOT_NAN_VALUE]], %[[RHS_IS_ZERO]] : i1
+// CHECK: %[[INF:.*]] = constant 0x7F800000 : f32
+// CHECK: %[[INF_WITH_SIGN_OF_RHS_REAL:.*]] = copysign %[[INF]], %[[RHS_REAL]] : f32
+// CHECK: %[[INFINITY_RESULT_REAL:.*]] = mulf %[[INF_WITH_SIGN_OF_RHS_REAL]], %[[LHS_REAL]] : f32
+// CHECK: %[[INFINITY_RESULT_IMAG:.*]] = mulf %[[INF_WITH_SIGN_OF_RHS_REAL]], %[[LHS_IMAG]] : f32
+
+// Case 2. Infinite numerator, finite denominator.
+// CHECK: %[[RHS_REAL_FINITE:.*]] = cmpf one, %[[RHS_REAL_ABS]], %[[INF]] : f32
+// CHECK: %[[RHS_IMAG_FINITE:.*]] = cmpf one, %[[RHS_IMAG_ABS]], %[[INF]] : f32
+// CHECK: %[[RHS_IS_FINITE:.*]] = and %[[RHS_REAL_FINITE]], %[[RHS_IMAG_FINITE]] : i1
+// CHECK: %[[LHS_REAL_ABS:.*]] = absf %[[LHS_REAL]] : f32
+// CHECK: %[[LHS_REAL_INFINITE:.*]] = cmpf oeq, %[[LHS_REAL_ABS]], %[[INF]] : f32
+// CHECK: %[[LHS_IMAG_ABS:.*]] = absf %[[LHS_IMAG]] : f32
+// CHECK: %[[LHS_IMAG_INFINITE:.*]] = cmpf oeq, %[[LHS_IMAG_ABS]], %[[INF]] : f32
+// CHECK: %[[LHS_IS_INFINITE:.*]] = or %[[LHS_REAL_INFINITE]], %[[LHS_IMAG_INFINITE]] : i1
+// CHECK: %[[INF_NUM_FINITE_DENOM:.*]] = and %[[LHS_IS_INFINITE]], %[[RHS_IS_FINITE]] : i1
+// CHECK: %[[ONE:.*]] = constant 1.000000e+00 : f32
+// CHECK: %[[LHS_REAL_IS_INF:.*]] = select %[[LHS_REAL_INFINITE]], %[[ONE]], %[[ZERO]] : f32
+// CHECK: %[[LHS_REAL_IS_INF_WITH_SIGN:.*]] = copysign %[[LHS_REAL_IS_INF]], %[[LHS_REAL]] : f32
+// CHECK: %[[LHS_IMAG_IS_INF:.*]] = select %[[LHS_IMAG_INFINITE]], %[[ONE]], %[[ZERO]] : f32
+// CHECK: %[[LHS_IMAG_IS_INF_WITH_SIGN:.*]] = copysign %[[LHS_IMAG_IS_INF]], %[[LHS_IMAG]] : f32
+// CHECK: %[[LHS_REAL_IS_INF_WITH_SIGN_TIMES_RHS_REAL:.*]] = mulf %[[LHS_REAL_IS_INF_WITH_SIGN]], %[[RHS_REAL]] : f32
+// CHECK: %[[LHS_IMAG_IS_INF_WITH_SIGN_TIMES_RHS_IMAG:.*]] = mulf %[[LHS_IMAG_IS_INF_WITH_SIGN]], %[[RHS_IMAG]] : f32
+// CHECK: %[[INF_MULTIPLICATOR_1:.*]] = addf %[[LHS_REAL_IS_INF_WITH_SIGN_TIMES_RHS_REAL]], %[[LHS_IMAG_IS_INF_WITH_SIGN_TIMES_RHS_IMAG]] : f32
+// CHECK: %[[RESULT_REAL_3:.*]] = mulf %[[INF]], %[[INF_MULTIPLICATOR_1]] : f32
+// CHECK: %[[LHS_REAL_IS_INF_WITH_SIGN_TIMES_RHS_IMAG:.*]] = mulf %[[LHS_REAL_IS_INF_WITH_SIGN]], %[[RHS_IMAG]] : f32
+// CHECK: %[[LHS_IMAG_IS_INF_WITH_SIGN_TIMES_RHS_REAL:.*]] = mulf %[[LHS_IMAG_IS_INF_WITH_SIGN]], %[[RHS_REAL]] : f32
+// CHECK: %[[INF_MULTIPLICATOR_2:.*]] = subf %[[LHS_IMAG_IS_INF_WITH_SIGN_TIMES_RHS_REAL]], %[[LHS_REAL_IS_INF_WITH_SIGN_TIMES_RHS_IMAG]] : f32
+// CHECK: %[[RESULT_IMAG_3:.*]] = mulf %[[INF]], %[[INF_MULTIPLICATOR_2]] : f32
+
+// Case 3. Finite numerator, infinite denominator.
+// CHECK: %[[LHS_REAL_FINITE:.*]] = cmpf one, %[[LHS_REAL_ABS]], %[[INF]] : f32
+// CHECK: %[[LHS_IMAG_FINITE:.*]] = cmpf one, %[[LHS_IMAG_ABS]], %[[INF]] : f32
+// CHECK: %[[LHS_IS_FINITE:.*]] = and %[[LHS_REAL_FINITE]], %[[LHS_IMAG_FINITE]] : i1
+// CHECK: %[[RHS_REAL_INFINITE:.*]] = cmpf oeq, %[[RHS_REAL_ABS]], %[[INF]] : f32
+// CHECK: %[[RHS_IMAG_INFINITE:.*]] = cmpf oeq, %[[RHS_IMAG_ABS]], %[[INF]] : f32
+// CHECK: %[[RHS_IS_INFINITE:.*]] = or %[[RHS_REAL_INFINITE]], %[[RHS_IMAG_INFINITE]] : i1
+// CHECK: %[[FINITE_NUM_INFINITE_DENOM:.*]] = and %[[LHS_IS_FINITE]], %[[RHS_IS_INFINITE]] : i1
+// CHECK: %[[RHS_REAL_IS_INF:.*]] = select %[[RHS_REAL_INFINITE]], %[[ONE]], %[[ZERO]] : f32
+// CHECK: %[[RHS_REAL_IS_INF_WITH_SIGN:.*]] = copysign %[[RHS_REAL_IS_INF]], %[[RHS_REAL]] : f32
+// CHECK: %[[RHS_IMAG_IS_INF:.*]] = select %[[RHS_IMAG_INFINITE]], %[[ONE]], %[[ZERO]] : f32
+// CHECK: %[[RHS_IMAG_IS_INF_WITH_SIGN:.*]] = copysign %[[RHS_IMAG_IS_INF]], %[[RHS_IMAG]] : f32
+// CHECK: %[[RHS_REAL_IS_INF_WITH_SIGN_TIMES_LHS_REAL:.*]] = mulf %[[LHS_REAL]], %[[RHS_REAL_IS_INF_WITH_SIGN]] : f32
+// CHECK: %[[RHS_IMAG_IS_INF_WITH_SIGN_TIMES_LHS_IMAG:.*]] = mulf %[[LHS_IMAG]], %[[RHS_IMAG_IS_INF_WITH_SIGN]] : f32
+// CHECK: %[[ZERO_MULTIPLICATOR_1:.*]] = addf %[[RHS_REAL_IS_INF_WITH_SIGN_TIMES_LHS_REAL]], %[[RHS_IMAG_IS_INF_WITH_SIGN_TIMES_LHS_IMAG]] : f32
+// CHECK: %[[RESULT_REAL_4:.*]] = mulf %[[ZERO]], %[[ZERO_MULTIPLICATOR_1]] : f32
+// CHECK: %[[RHS_REAL_IS_INF_WITH_SIGN_TIMES_LHS_IMAG:.*]] = mulf %[[LHS_IMAG]], %[[RHS_REAL_IS_INF_WITH_SIGN]] : f32
+// CHECK: %[[RHS_IMAG_IS_INF_WITH_SIGN_TIMES_LHS_REAL:.*]] = mulf %[[LHS_REAL]], %[[RHS_IMAG_IS_INF_WITH_SIGN]] : f32
+// CHECK: %[[ZERO_MULTIPLICATOR_2:.*]] = subf %[[RHS_REAL_IS_INF_WITH_SIGN_TIMES_LHS_IMAG]], %[[RHS_IMAG_IS_INF_WITH_SIGN_TIMES_LHS_REAL]] : f32
+// CHECK: %[[RESULT_IMAG_4:.*]] = mulf %[[ZERO]], %[[ZERO_MULTIPLICATOR_2]] : f32
+
+// CHECK: %[[REAL_ABS_SMALLER_THAN_IMAG_ABS:.*]] = cmpf olt, %[[RHS_REAL_ABS]], %[[RHS_IMAG_ABS]] : f32
+// CHECK: %[[RESULT_REAL:.*]] = select %[[REAL_ABS_SMALLER_THAN_IMAG_ABS]], %[[RESULT_REAL_1]], %[[RESULT_REAL_2]] : f32
+// CHECK: %[[RESULT_IMAG:.*]] = select %[[REAL_ABS_SMALLER_THAN_IMAG_ABS]], %[[RESULT_IMAG_1]], %[[RESULT_IMAG_2]] : f32
+// CHECK: %[[RESULT_REAL_SPECIAL_CASE_3:.*]] = select %[[FINITE_NUM_INFINITE_DENOM]], %[[RESULT_REAL_4]], %[[RESULT_REAL]] : f32
+// CHECK: %[[RESULT_IMAG_SPECIAL_CASE_3:.*]] = select %[[FINITE_NUM_INFINITE_DENOM]], %[[RESULT_IMAG_4]], %[[RESULT_IMAG]] : f32
+// CHECK: %[[RESULT_REAL_SPECIAL_CASE_2:.*]] = select %[[INF_NUM_FINITE_DENOM]], %[[RESULT_REAL_3]], %[[RESULT_REAL_SPECIAL_CASE_3]] : f32
+// CHECK: %[[RESULT_IMAG_SPECIAL_CASE_2:.*]] = select %[[INF_NUM_FINITE_DENOM]], %[[RESULT_IMAG_3]], %[[RESULT_IMAG_SPECIAL_CASE_3]] : f32
+// CHECK: %[[RESULT_REAL_SPECIAL_CASE_1:.*]] = select %[[RESULT_IS_INFINITY]], %[[INFINITY_RESULT_REAL]], %[[RESULT_REAL_SPECIAL_CASE_2]] : f32
+// CHECK: %[[RESULT_IMAG_SPECIAL_CASE_1:.*]] = select %[[RESULT_IS_INFINITY]], %[[INFINITY_RESULT_IMAG]], %[[RESULT_IMAG_SPECIAL_CASE_2]] : f32
+// CHECK: %[[RESULT_REAL_IS_NAN:.*]] = cmpf uno, %[[RESULT_REAL]], %[[ZERO]] : f32
+// CHECK: %[[RESULT_IMAG_IS_NAN:.*]] = cmpf uno, %[[RESULT_IMAG]], %[[ZERO]] : f32
+// CHECK: %[[RESULT_IS_NAN:.*]] = and %[[RESULT_REAL_IS_NAN]], %[[RESULT_IMAG_IS_NAN]] : i1
+// CHECK: %[[RESULT_REAL_WITH_SPECIAL_CASES:.*]] = select %[[RESULT_IS_NAN]], %[[RESULT_REAL_SPECIAL_CASE_1]], %[[RESULT_REAL]] : f32
+// CHECK: %[[RESULT_IMAG_WITH_SPECIAL_CASES:.*]] = select %[[RESULT_IS_NAN]], %[[RESULT_IMAG_SPECIAL_CASE_1]], %[[RESULT_IMAG]] : f32
+// CHECK: %[[RESULT:.*]] = complex.create %[[RESULT_REAL_WITH_SPECIAL_CASES]], %[[RESULT_IMAG_WITH_SPECIAL_CASES]] : complex<f32>
+// CHECK: return %[[RESULT]] : complex<f32>
+
// CHECK-LABEL: func @complex_eq
// CHECK-SAME: %[[LHS:.*]]: complex<f32>, %[[RHS:.*]]: complex<f32>
func @complex_eq(%lhs: complex<f32>, %rhs: complex<f32>) -> i1 {
More information about the Mlir-commits
mailing list