MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / matchAndRewrite

Method matchAndRewrite

lib/Dialect/CudaTile/Transforms/FuseFMA.cpp:61–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 using OpRewritePattern::OpRewritePattern;
60
61 LogicalResult matchAndRewrite(cuda_tile::SubFOp op,
62 PatternRewriter &rewriter) const override {
63 Value c;
64 cuda_tile::MulFOp ab;
65 Location loc = op.getLoc();
66
67 if ((ab = op.getLhs().getDefiningOp<cuda_tile::MulFOp>()) &&
68 ab.getResult().hasOneUse()) {
69 c = rewriter.createOrFold<cuda_tile::NegFOp>(loc, op.getRhs());
70 } else {
71 return rewriter.notifyMatchFailure(op, "no mulf op on LHS with one use");
72 }
73
74 Value a = ab.getLhs();
75 Value b = ab.getRhs();
76
77 // Only fuse if rounding modes and modifiers are the same.
78 auto ftz = op.getFlushToZero();
79 auto rm = op.getRoundingMode();
80
81 if (ftz != ab.getFlushToZero() || rm != ab.getRoundingMode())
82 return rewriter.notifyMatchFailure(
83 op, "rounding modes and modifiers are not the same");
84
85 rewriter.replaceOpWithNewOp<cuda_tile::FmaOp>(
86 op, a, b, c,
87 cuda_tile::RoundingModeAttr::get(rewriter.getContext(), rm),
88 ftz ? rewriter.getUnitAttr() : nullptr);
89 rewriter.eraseOp(ab); // drop the now-dead multiplication
90 return success();
91 }
92};
93
94} // namespace

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected