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

            Bug ID: 94543
           Summary: missed optimization with MIN and AND with type
                    promotion
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rth at gcc dot gnu.org
  Target Milestone: ---

unsigned f(unsigned short x) { return (x > 0xff ? 0xff : x) & 0xff; }

        cmpw    $255, %di
        movl    $255, %eax
        cmova   %eax, %edi
        movzwl  %di, %eax
        ret

The final AND is of course redundant.  The optimizer removes it
for wider types, but fails to do so when promoting from short.

Reply via email to