[cfe-dev] Loop optimised into div (?)

Joan Lluch via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 23 10:29:19 PDT 2019


Hi all,

For the following code 

int countHundred( int num )
{
  int count = 0;
  while ( num >= 100) { count++ ; num = num - 100; }
  return count;
}

the loop shown above is optimised away and replaced by ‘udiv’ instruction. 

This is undesirable for targets requiring libcalls for integer divisions, such as the MSP430. 

Where does that happen? Is there a way, to prevent this?

Thanks

John.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191023/821fb5e2/attachment.html>


More information about the cfe-dev mailing list