Comment 11 for bug 637797

> Can we define a peephole2 here? or we can do something on tree level?

I believe a peephole optimization would work, if we set expand_divmod to always prefer the full divmod library call. We'd also need to either arrange for the divmod/div decision to be target specific, or else fix up any other affected backends.

However, a peephole wouldn't get to do anything until after register allocation, I think. Would that not make it suboptimal?

I'm not sure a tree level change would be appropriate. Apart from anything else, it might get rejected upstream simply because the existing system works (for most people). Presumably you'd want it to convert div+mod to a builtin function, or something, that would then be translated to the right backend function later?