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

            Bug ID: 125484
           Summary: `(double)us1 < (double)us0` simplifying to `us1 < us0`
                    sometimes gets in the way of detecting min/max
           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: 26163
  Target Milestone: ---

Take:
```
typedef unsigned short Quantum;
static const double QuantumScale = 1.0/65535.0;
void ConvertRGBToHSB(Quantum red, Quantum green, Quantum blue,
                     double *hue, double *saturation, double *brightness) {
  double b, delta, g, max, min, r;
  *hue=0.0; *saturation=0.0; *brightness=0.0;
  r=(double) red; g=(double) green; b=(double) blue;
  min=r < g ? r : g; if (b < min) min=b;
  max=r > g ? r : g; if (b > max) max=b;
  if (max == 0.0) return;
  delta=max-min;
  *saturation=delta/max;
  *brightness=QuantumScale*max;
  if (delta == 0.0) return;
  if (r == max) *hue=(g-b)/delta;
  else if (g == max) *hue=2.0+(b-r)/delta;
  else *hue=4.0+(r-g)/delta;
  *hue/=6.0;
  if (*hue < 0.0) *hue+=1.0;
}
```

Which is extracted from imagic. We change `r < g` and `r < g` to use red/green
directly and that produces slightly better code but then we miss that this
should have been min/max. and then lowered.

Even `r == max` should be improved.
So should `delta == 0.0` (but that is related to PR 124571)

I am not sure match patterns will help here.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2026, 2k17, 2k and 2k6 and
95)

Reply via email to