Bug ID: 84527
           Summary: missed optimization for special ternary operation
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot
          Reporter: ktietz at gcc dot
  Target Milestone: ---

The following sample:

int foo(int a, int b)
  return a < b ? -1 : 1;

gets translated to

        xorl    %eax, %eax
        cmpl    %edx, %ecx
        setge   %al
        leal    -1(%rax,%rax), %eax

There would be instead a better representation for such kind of patterns as

... cmpl %ecx, %edx
    sbb  %eax, %eax
    orb  $1, %al

The missed patterns are 'result = COND ? -1 : VAL' and its permutations.

The same applies to the pattern 'result = COND ? VAL : 0' and its permuations,
which can be expressed as 'CMP a, b; SBB reg, reg; AND $VAL, reg;'

Reply via email to