[llvm] [InstCombine] Fold `sext(trunc nsw)` and `zext(trunc nuw)` (PR #88609)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 14 23:37:02 PDT 2024


nikic wrote:

Doing this fold is the whole purpose of the flags, so if we can't do it, we may as well drop them again :)

Looking at the diffs, I think it looks ok on average? Note that we already essentially do this fold just via computeKnownBits/ComputeNumSignBits, which is also why there is such a small number of diffs overall. I think the extra changes you see are due to interactions of IPSCCP and InstCombine or something like that. I think we would get some more interesting cases after https://github.com/llvm/llvm-project/pull/88686.

A general issue I see in the diffs is that we're not very good at narrowing i8 "booleans" down to i1 when loop phis are involved, as computeKnownBits() can't look through them. I think this issue accounts for most of the regressions, but it's also tricky to solve...

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


More information about the llvm-commits mailing list