pattern matching order

It seems that patterns are matched in the order that they appear in the td file.

Is this something we can rely on?

def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;

the immSExt8 will only match a 8 bit signed value.

I want it to try the first pattern and then the second, if it fails.

  AddiuRxRxImm16 --- 16 bit instruction
  AddiuRxRxXImm16 -- 32 bit instruction

It is by design but it is the last resort for ordering, and it is very fragile to depend on that.

It is better to use AddedComplexity to control pattern ordering when required.


Jakob Stoklund Olesen <> writes:

I'm not defending the name, but here's the reason:

Isel builds a set of candidate patterns that can match, and orders them by priority: it wants to match the largest pattern (most nodes covered by the pattern -> most "complex") at the minimum cost. AddedComplexity is saying that the pattern is higher value because it covers more notes, and is considered to be more complicated (and therefore, valuable) compared to other candidates.