[llvm] [SCEV] Preserve divisibility info when creating UMax/SMax expressions. (PR #160012)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 13:11:12 PDT 2025
https://github.com/fhahn commented:
> The idea makes sense to me, but TBH I'm pretty lost in the code structure here. Why are we fixing this up after the fact rather than creating the umax/umin with the larger value from the start?
>
The benefit of delaying is that we can delay the re-write until we collected information from all loop guards, making the code independent of the order of guards.
We could have 3 guards, establishing
* umax(%a, %b) > 0
* %a multiple of 2
* %b multiple of 2
When we construct `umax(1, %a, %b)` for the first condition, we may not yet have the information available that %a and %b are multiple of 2.
But once we collected all information, we can rewrite `umax(1, %a, %b)` to something like `umax(1, 2 * %a / 2, 2* %b / 2)` and get the common multiple using the info from the guards.
Not sure if there's a nicer way to keep things independent of the guard order.
> Also would it make sense to do something more generic during SCEV construction here? Or do we expect this to only be useful for guards?
Hmm, I think the current code relies on the fact that the UMax/SMax with the constant is coming from a compare w/o the constant part on the left side.
Are there any particluar cases you are thinking of on construction?
https://github.com/llvm/llvm-project/pull/160012
More information about the llvm-commits
mailing list