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

Michael Kruse via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 25 15:36:29 PDT 2019


Am Mi., 23. Okt. 2019 um 12:29 Uhr schrieb Joan Lluch via cfe-dev
<cfe-dev at lists.llvm.org>:
> 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?

Is is a capability of ScalarEvolution and may happen by e.g.
LoopStrengthReducePass.


Michael



More information about the cfe-dev mailing list