Overlapping ::matchAndRewrite

I have 2 fuse patterns:

  1. opB->opC => opX (OpRewritePattern<opC>)
  2. opA->opB->opC->opD => opX (OpRewritePattern<opD>)

In cases where pattern 2) would be best, pattern 1) is applied first, so to avoid this I added a hack to pattern 1): if opC has a opD user, then return mlir::failure() (to allow pattern 2) to “win”)
What is the proper way to avoid this overalp?

Ideally you would be able to have 2 match the IR after the application of 1.

1 Like

Thank you very much for the prompt feedback.
Your suggestion makes sense also seems doable.