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

            Bug ID: 113423
           Summary: Missed Optimization: potential redundant load
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carnet at student dot ethz.ch
  Target Milestone: ---

https://godbolt.org/z/jbbEPePhv

Source Code:
int a;
int *b;
int c = 0;

void foo() {
  if (b)
    c = 3;
  a = c;
}


int bar(){
    return c;
}

foo:
        cmpq    $0, b(%rip)
        movl    c(%rip), %eax <========= eax is overwritten when the jump is
not taken, potentially redundant load
        je      .L3
        movl    $3, c(%rip) 
        movl    $3, %eax
.L3:
        movl    %eax, a(%rip)
        ret


%eax is written before the branch. If the branch is not taken, eax is
overwritten. Which makes the highlighted load potentially unnecessary.
  • [Bug tree-optimization/113423] ... carnet at student dot ethz.ch via Gcc-bugs

Reply via email to