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

            Bug ID: 96586
           Summary: suboptimal code generated for condition expression
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhongyunde at tom dot com
  Target Milestone: ---

For the following case, we can easy known the while loop will execute once, but
with newest gcc 10.2, it still generated suboptimal code with condition
expression.

void Proc_7 (int Int_Par_Ref);
void Proc_2 (int *Int_Par_Ref);

int main ()
{
    int       Int_1_Loc;
    int       Int_2_Loc;
    int       Int_3_Loc;

  /* Initializations */
    Int_1_Loc = 2;
    Int_2_Loc = 3;

    while (Int_1_Loc < Int_2_Loc)
    {
      Proc_7 (0);

      Int_1_Loc += 1;
    } /* while */

    Int_1_Loc = 1;
    Proc_2 (&Int_1_Loc);

  return 0;
}

============== the key assemble of the while loop ===========
.L2:
        .loc 1 18 7 view .LVU10
        .loc 1 20 7 view .LVU11
        .loc 1 20 14 is_stmt 0 view .LVU12
        mov     edi, 5
        call    Proc_7(int)
.LVL1:
        .loc 1 22 7 is_stmt 1 view .LVU13
        .loc 1 22 17 is_stmt 0 view .LVU14
        mov     eax, DWORD PTR [rsp+12]
        add     eax, 1
        mov     DWORD PTR [rsp+12], eax
        .loc 1 16 5 is_stmt 1 view .LVU15
        .loc 1 16 22 view .LVU16
        cmp     eax, 2
        jle     .L2

Reply via email to