[llvm] [SCEV] Fix incorrect NUW inference (PR #70521)

Daniil Suchkov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 09:38:16 PDT 2023


DaniilSuchkov wrote:

> Is the problem here that the nuw flag is just entirely incorrect, or that it is correct at that use, but we set it on the addrec in general?

It's entirely incorrect. In the test showing the miscompile have an exit condition that is an OR of two icmps with one being basically an inverse of the other, i.e. it's `if (!(cond || !cond)) break;`. Currently we infer NUW based on one of the icmps: we assume that if this comparison is false, we'll leave the loop and thus the AddRec won't reach overflow, but that assumption is just wrong.
Also, this exit check dominates the latch, so (in most cases?) whatever is correct for that check, should be as well correct for that AddRec in general.

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


More information about the llvm-commits mailing list