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

            Bug ID: 125788
           Summary: factor out from more than `a ? xyz : abc`
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
double f(double* expr1, double* expr2, double* expr3, double* c1, double* c2) {
    double t = 0.0;
    for (int i = 0; i < 1024; i++) {
        double distance = 0.0;
        if (c1[i] <= 0.0)
            distance = __builtin_sqrt(expr1[i]);
        else if (c2[i] <= c1[i])
            distance = __builtin_sqrt(expr2[i]);
        else
            distance = __builtin_sqrt(expr3[i]);
        t += distance;
    }
    return t;
}
```

At -Ofast, We should only get one sqrt. Currently the vectorized (with -mavx2
or -march=armv9-a both have masked loads) we get 3 sqrt; with a "fix" to phiopt
we can get 1. But we should be able to get 1 sqrt even in the scalar version.

Reply via email to