[llvm] [InstCombine] Handle ceil division idiom (PR #100977)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 9 04:00:13 PST 2025
dtcxzyw wrote:
> provided that I'm not missing anything within the AssumptionCache or other ways to query the no overflow guarantee
Currently we don't infer no overflow from overflow checking idioms (e.g., `extract (uadd_overflow x, y), 1 <-> ~x <u y`: https://alive2.llvm.org/ce/z/w5sc2k).
> Shouldn't we emit an assume in the form of x+y < uint_max true instead?
Agree that we should emit overflow checking idioms instead of `!(extract (uadd_overflow x, y), 1)`, if we only care about the overflow flag. However, for the rustc case handled by https://github.com/llvm/llvm-project/pull/84016, both the result and the overflow flag are used.
To address the motivating case in https://github.com/llvm/llvm-project/issues/95652, we should:
1. convert `extract (xxx_overflow x, y), 1` into canonical forms
2. identify these idioms and add them into DomConditionCache
3. handle these idioms in computeOverflowForXXX
As @nikic pointed out, we have yet to encounter a case for `divideCeil(A, B)` where A+B doesn't overflow. So I don't know if this patch has real-world usefulness :(
https://github.com/llvm/llvm-project/pull/100977
More information about the llvm-commits
mailing list