Creating a pattern detection pass for Mips backend

HI all,

I’m trying to add a new FunctionPas to Mips backend in order to recognise a specific loop and substitute it with an intrinsic. The pattern that I want to recognise is:

%7 = load i32, i32* %i, align 4
%arrayidx = getelementptr inbounds [1024 x i32], [1024 x i32]* %seq, i32 0, i32 %7
%8 = load i32, i32* %arrayidx, align 4
%9 = load i32, i32* %j, align 4
%mul = mul nsw i32 %9, 2
%shl = shl i32 3, %mul
%and = and i32 %8, %shl
%10 = load i32, i32* %j, align 4
%mul2 = mul nsw i32 %10, 2
%shr = ashr i32 %and, %mul2
%conv = trunc i32 %shr to i8
store i8 %conv, i8* %hn, align 1
%11 = load i8, i8* %hn, align 1
%conv3 = sext i8 %11 to i32
%cmp4 = icmp eq i32 %conv3, 2
br i1 %cmp4, label %12, label %14

; :12: ; preds = %6
%13 = load i32, i32* %cnt, align 4
%inc = add nsw i32 %13, 1
store i32 %inc, i32* %cnt, align 4
br label %14

How can I detect it? There is a similar thing in other backends that I can use for my purpose?

Thanks,

Catello

Please don't start a new thread with the same question; if the answers to your previous thread don't seem to answer your question, you can reply there and clarify what you're asking.

-Eli