Matching instruction patterns from a FunctionPass

Hi all,

I'm working on a pass that would need to match a pattern of instructions. In pseudo-IR:

%0 = sub %a, %b
%1 = xor %a, %b
%2 = xor %0, %a
%3 = and %1, %2

After this instruction sequence, %3's most significant bit tells whether the subtraction overflowed. I would like to find occurrences of this pattern from a FunctionPass.

However, this has a couple of possible permutations. And and Xor are both commutative, meaning that there are 8 valid ways to express this. Since I might not be the first person to run into this kind of issue, I was wondering if there is a common way to handle this.



Looks like llvm/IR/PatternMatch.h is what I'm looking for.