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

            Bug ID: 118680
           Summary: (smaller_type)MAX_EXPR<(larger_type)a, (larger_type)b>
                    -> MAX_EXPR<a,b> where smaller_type is the same as a/b
                    types and smaller/larger type have the same sign
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Extracted from PR 118679:

```
#include <stdint.h> 
static inline uint64_t max_u64(uint64_t a, uint64_t b) {
    return a > b ? a : b;
}

uint32_t test2a(uint32_t a, uint32_t b) {
    return a > b ? a : b;
}

uint32_t test2b(uint32_t a, uint32_t b) {
    return (uint64_t)a > (uint64_t)b ? (uint64_t)a : (uint64_t)b;
}

uint32_t test2c(uint32_t a, uint32_t b) {
    return max_u64(a, b);
}
```

test2c we get:
  _1 = (long unsigned int) b_4(D);
  _2 = (long unsigned int) a_5(D);
  _7 = MAX_EXPR <_1, _2>;
  _8 = (uint32_t) _7;

Which is not handled to just:
MAX_EXPR <b_4(D), a_5(D)>

Reply via email to