[llvm] [IndVarSimplify] Do not replace ExitValue if it contains Udiv with non-constant divisor (PR #109945)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 23:20:41 PDT 2024


ShivaChen wrote:

> Exit value replacement checks the cost of the expansion. If the expansion is high cost (which would be the case for udiv), then it is only performed if the loop can be deleted.
> 
> So the tradeoff here is replacing an entirely loop with a udiv. Unless the loop has very few iterations, this seems like a profitable replacement to make.
> 
> What's the motivating case here? Is it a loop that has very few iterations and gets replaced by a more expensive udiv?

It's motivated by a small loop in primecount https://github.com/embench/embench-iot/blob/master/src/primecount/primecount.c#L116.
Yes, it has few iterations and been replaced by a "sub, maxu, divu, add, mul, add".
There is a relative issue. https://github.com/llvm/llvm-project/issues/71424.
Would detect udiv with non-zero divisor too simplified? Is there better way to guard the case? Thanks.

https://github.com/llvm/llvm-project/pull/109945


More information about the llvm-commits mailing list