| 24 | using OpRewritePattern::OpRewritePattern; |
| 25 | |
| 26 | LogicalResult matchAndRewrite(cuda_tile::AddFOp op, |
| 27 | PatternRewriter &rewriter) const override { |
| 28 | Value c; |
| 29 | cuda_tile::MulFOp ab; |
| 30 | if ((ab = op.getLhs().getDefiningOp<cuda_tile::MulFOp>()) && |
| 31 | ab.getResult().hasOneUse()) { |
| 32 | c = op.getRhs(); |
| 33 | } else { |
| 34 | return rewriter.notifyMatchFailure(op, "no mulf op with one use"); |
| 35 | } |
| 36 | |
| 37 | Value a = ab.getLhs(); |
| 38 | Value b = ab.getRhs(); |
| 39 | |
| 40 | // Only fuse if rounding modes and modifiers are the same. |
| 41 | auto ftz = op.getFlushToZero(); |
| 42 | auto rm = op.getRoundingMode(); |
| 43 | |
| 44 | if (ftz != ab.getFlushToZero() || rm != ab.getRoundingMode()) |
| 45 | return rewriter.notifyMatchFailure( |
| 46 | op, "rounding modes and modifiers are not the same"); |
| 47 | |
| 48 | rewriter.replaceOpWithNewOp<cuda_tile::FmaOp>( |
| 49 | op, a, b, c, |
| 50 | cuda_tile::RoundingModeAttr::get(rewriter.getContext(), rm), |
| 51 | ftz ? rewriter.getUnitAttr() : nullptr); |
| 52 | rewriter.eraseOp(ab); // drop the now-dead multiplication |
| 53 | return success(); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | class MulSubPattern : public OpRewritePattern<cuda_tile::SubFOp> { |
nothing calls this directly
no outgoing calls
no test coverage detected