The save into r8 should be a proper save, unless the compiler expects you to save r8 which you destroy. Hmmm.... I'm going need take a look at the code myself, you can send me the code if you wish so... If no time tomorrow though.

In the meantime, please compare a version with the "mod" defined as function in the program and when it is in the RTL. Can you see differences?