This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Add commutative matchers for compares.
ClosedPublic

Authored by paquette on Oct 6 2022, 5:00 PM.

Details

Summary

This adds:

  • m_c_GICmp
  • m_c_GFCmp

These work the same way as the standard matchers, but will also try to commute the LHS and RHS of a compare to get a match.

E.g.

m_c_GICmp(m_Pred(...), m_GAdd(...), m_GSub(...))

Can match either of

icmp cc (add x, y), (sub a, b)
icmp swapped_cc (sub a, b), (add x, y)

Diff Detail

Event Timeline

paquette created this revision.Oct 6 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 5:00 PM
paquette requested review of this revision.Oct 6 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 5:00 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Oct 6 2022, 8:23 PM
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
659–667

The IR version has a separate m_c_ICmp from the regular m_ICmp for whether to bother commuting or not

paquette updated this revision to Diff 466156.Oct 7 2022, 12:33 PM
paquette retitled this revision from [GlobalISel] Make comparison matcher commutative for commutative predicates to [GlobalISel] Add commutative matchers for compares..
paquette edited the summary of this revision. (Show Details)

Match behaviour from IR pattern match

tschuett added inline comments.
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
692

You could put [[nodiscard]] here.

707

You could put [[nodiscard]] here.

paquette added inline comments.Oct 7 2022, 1:45 PM
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
707

Should we do this for all of the matchers?

In your favour, I would prefer lazy. I noticed your creative way of IIRC mi_matchin some diff.

In your favour, I would prefer lazy. I noticed your creative way of IIRC mi_matchin some diff.

I just tried adding it to mi_match and it seems to work. Found a couple places where it's being used in a similarly weird way. I'll put up a separate patch for that once the build is done and I fix the couple weird uses.

Sorry, I believe that it suffices to have the attribute on the mi_match.

Yep, did that in D135491. :)

arsenm accepted this revision.Oct 7 2022, 6:59 PM

LGTM

This revision is now accepted and ready to land.Oct 7 2022, 6:59 PM
This revision was automatically updated to reflect the committed changes.