https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116307
--- Comment #2 from Kacper Michajłow <kasper93 at gmail dot com> --- (In reply to Andrew Pinski from comment #1) > Note I don't think the warning is not incorrect. Nor I don't think unrolling > by 3 is wrong either. Could you explain why unrolling by 3 is not wrong in this case? Technically it is not wrong, but why unrolling by 2 is not enough? > Note num can change after the call to get_val() too. The loop bound is > unknown due to the function call really and num being a global variable. This doesn't change anything, num is unknown before, during and after loop execution. The unroll count is based on the `a` array size, which is known at compile time. > Anyways I think this is really a dup of bug 104789 . Looks like the similar root cause indeed. Though I would argue in this (116307) case we know the exact unroll count, so it could be avoided by not doing one more iteration that triggers the warning and produces the code, that if there is no UB invoked would be dead.