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

            Bug ID: 123476
           Summary: check for sqrt call not removed with loops
           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
            Blocks: 85316
  Target Milestone: ---
            Target: aarch64 x86_64

Take:
```
#include <cmath>

double CompareDistmats(const double* const distmat1,
 const double* const distmat2, int l){
    double RMSD = 0.0;
    for (int i=0; i<l; i++){
                RMSD += (distmat1[i]-distmat2[i])
                *(distmat1[i]-distmat2[i]);
    }
  return std::sqrt(RMSD);
}
```

For aarch64 and x86_64, we should be able to optimize away the check for RMSD
being less than 0 here. at both -O2 and -O3.

We do handle the case where l is a small number say 1 or 2 (4 on aarch64
because not vectoring the loop). But we should be able to detect the range of
RMSD is always positive (or NAN or +inf) which we don't currently.

Note unlike LLVM we handle the case where the loop unrolls (but only if we
don't vectorize the loop).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

Reply via email to