<div dir="ltr">Dear all,<div><br></div><div>I have been working on a new LLVM backend. Some instructions, like sub, can take an positive constante, encoded into 5 bits thus lower than 32, and a register, as operands.<br></div><div>Unfortunately, DAGCombiner.cpp changes patterns like 'sub x, 5' into 'add x,-5'.</div><div><br></div><div><div><font face="arial, helvetica, sans-serif">Similarly, I found changes in someĀ IR to IR passes, with no clear gain (at least not clear to me), and even penalty for my specific ISA.</font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black">%add = add i32 %a, %b<br>%tobool = icmp eq i32 %add, 0</span><br></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black">becomes :</span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black"><br></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:10pt;color:black">%add = sub i32 0, %b<br>%tobool = icmp eq i32 %a, %</span></font></div></div><div><br></div><div>My question is not how to workaround those, but why such changes are done for all targets, in DAG selection or in IR passes.</div><div>AFAIK, there is no target which has some better encoding with a negative value than with a positive one.</div><div>And "sub" looks as costly as "add" to me.</div><div><br></div><div>Is there some other practical reason to perform this kind of change ?</div><div>Thanks for your highlights.</div><div><br></div><div>--</div><div>Frederic Heitzmann</div><div><br></div></div>