<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>I am having a problem with instruction selection with pattern fragments.<o:p></o:p></p><p class=MsoNormal>With my custom target, in order to simplify code generation patterns, I do not allow a constant to be used in an instruction(mainly because they have declare before use semantics).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Now the problem I am having is that I cannot get a instruction that contains pattern fragment that uses an immediate value to be selected before the immediate instruction itself.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>So, my question is this, is there anyway to force the ordering of how the instructions get selected.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>For example, take this pattern (A & B) | (C & ~B), I have the following PatFrag:<o:p></o:p></p><p class=MsoNormal>/// Pattern 1: (lhs & bitpat) | (rhs & ~bitpat)<o:p></o:p></p><p class=MsoNormal>def bfi_pat1 : PatFrag<(ops node:$lhs, node:$rhs, node:$bitpat),<o:p></o:p></p><p class=MsoNormal> (or <o:p></o:p></p><p class=MsoNormal> (and node:$lhs, node:$bitpat), <o:p></o:p></p><p class=MsoNormal> (and node:$rhs, (not node:$lhs)))>;<o:p></o:p></p><p class=MsoNormal>def BFI_i32 : ThreeInOneOut<IL_OP_BFI, (outs GPRI32:$dst),<o:p></o:p></p><p class=MsoNormal> (ins GPRI32:$lhs, GPRI32:$rhs, GPRI32:$bitpat),<o:p></o:p></p><p class=MsoNormal> !strconcat(IL_OP_BFI.Text, " $dst, $lhs, $rhs, $bitpat"),<o:p></o:p></p><p class=MsoNormal> [(set GPRI32:$dst, (bfi_pat1 GPRI32:$lhs, GPRI32:$rhs, GPRI32:$bitpat))]>;<o:p></o:p></p><p class=MsoNormal>and also this instruction:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> def LOADCONST_i32 : ILFormat<IL_OP_MOV, (outs GPRI32:$dst),<o:p></o:p></p><p class=MsoNormal> (ins i32imm:$val),<o:p></o:p></p><p class=MsoNormal> "mov $dst, $src", <o:p></o:p></p><p class=MsoNormal> [(set GPRI32:$dst, imm:$val)]>;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Now, what is happening with this code, (A & B) | (C & ~B), where B is an immedate and ~B is an inverse of it,<o:p></o:p></p><p class=MsoNormal>instead of getting <o:p></o:p></p><p class=MsoNormal>LOADCONST_i32 r0 B<o:p></o:p></p><p class=MsoNormal>BFI_i32 r1, A, C, r0<o:p></o:p></p><p class=MsoNormal>I am getting<o:p></o:p></p><p class=MsoNormal>LOADCONST_i32 r0, B<o:p></o:p></p><p class=MsoNormal>LOADCONST_i32 r1, ~B<o:p></o:p></p><p class=MsoNormal>AND_i32 r2, A, r0<o:p></o:p></p><p class=MsoNormal>AND_i32 r3, C, r1<o:p></o:p></p><p class=MsoNormal>OR_i32 r4, r2, r3<o:p></o:p></p><p class=MsoNormal>because the LOADCONST is getting matched before the bfi_pat1 pattern fragment.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I know I can write C++ code that will generate a pattern fragment and handle this issue, but I don't want to duplicate behavior if it already exists. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Any ideas?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal>Micah<o:p></o:p></p></div></body></html>