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

            Bug ID: 96572
           Summary: Failure to optimize out branch when it always results
                    in UB from dereferencing a pointer to an undefined
                    value set in there
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(int *p, bool cond)
{
  int i;
  int *q;
  if (cond)
    q = &i;
  else
    q = p;
  return *q + *p;
}

This can be optimized to `return (*p) * 2;`. This transformation is done by
LLVM, but not by GCC.

Reply via email to