https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118544

            Bug ID: 118544
           Summary: -fopt-info misreports unroll factor when using #pragma
                    GCC unroll
           Product: gcc
           Version: 15.0
               URL: https://godbolt.org/z/x1eb65jWf
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tiborgyri at gmail dot com
                CC: tiborgyri at gmail dot com
  Target Milestone: ---

Created attachment 60202
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60202&action=edit
Test case -Wall -Wextra -Ofast -std=c++20 -march=znver3 -gno-as-loc-support

Partially unrolling a loop with #pragma GCC unroll results in an "optimization
passed" message that misreports the unroll factor.
For example #pragma GCC unroll(2) results in this message "loop unrolled 1
times". This is misleading since GCC has correctly unrolled the loop by a
factor of 2, as requested by the user. The number reported in the opt-info
message is consistently 1 lower than the requested (and actual) unroll factor.

Another manifestation of this, is when the requested unroll factor is 1 lower
than the loop iteration count. For example, if a loop has 6 iterations, #pragma
GCC unroll(5) results in the following message:
"loop with 5 iterations completely unrolled"
This is confusing, given that the the loop has 6 iterations, not 5.

The only time this opt-info message is correct, is when the requested unroll
factor is >= the total number of iterations, in which case GCC correctly
reports that the loop was completely unrolled.

I imagine that some other pass that does not emit opt-info messages unrolls 1
iteration, hence the confusing messages.
See: https://godbolt.org/z/x1eb65jWf

Reply via email to