Skip to content

[MooreToCore] Lowering to math.ipow? #8973

@cowardsa

Description

@cowardsa

Is there a strong reason to go from PowUOp to math.ipow as opposed to lowering to a sequence of multiplications?

Is there any existing lowering from math.ipow to the core dialects?

LogicalResult
matchAndRewrite(PowUOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type resultType = typeConverter->convertType(op.getResult().getType());
Location loc = op->getLoc();
Value zeroVal = hw::ConstantOp::create(rewriter, loc, APInt(1, 0));
// zero extend both LHS & RHS to ensure the unsigned integers are
// interpreted correctly when calculating power
auto lhs = comb::ConcatOp::create(rewriter, loc, zeroVal, adaptor.getLhs());
auto rhs = comb::ConcatOp::create(rewriter, loc, zeroVal, adaptor.getRhs());
// lower the exponentiation via MLIR's math dialect
auto pow = mlir::math::IPowIOp::create(rewriter, loc, lhs, rhs);
rewriter.replaceOpWithNewOp<comb::ExtractOp>(op, resultType, pow, 0);
return success();
}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions