[llvm] [IndVars] Mark truncs as nuw/nsw (PR #88686)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 10:30:03 PDT 2024


preames wrote:

> > One of the thoughts I'd had when seeing this langref proposal was that it might allow us to simplify this code significantly. I believe one of the things which makes this code complex is that we have to "commit" to our signed or unsigned interpretation by performing all rewrites at once since we couldn't materialize a wide IV + truncate and preserve the information about the choice. With this IR change, we now have that possibility. This might not fully work out - there's other reasons for complexity in this code - but mentioning it in case it inspires you. :)
> 
> Right. What IV widening conceptually does is to zext/sext the IV and then add trunc nuw/nsw at all uses -- and then implement a whole bunch of combines to get rid of that trunc again. That last part is no longer strictly necessary, but I suspect that we do need it in practice for phase ordering reasons: We probably can't leave these truncs around until the next InstCombine run that eliminates them, especially considering interleaved loop passes.

Oh, I hadn't meant anything that radical.  If nothing else, we have a bunch of SCEV based reasoning in the widening code which InstCombine can't handle.

I'd simply meant that we could separate widening into two "passes" inside IndVarSimplify.  Step 1 - Decide how to widen, insert the trunc nsw/nuw in the trivial position.  Step 2 - Eliminate the trunc if possible.  

One advantage of this approach is that it gives us a lot more confidence that the elimination code is correct because we can write specific tests which don't involving the widening strategy heuristics.  

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


More information about the llvm-commits mailing list