The optimizer at -O3 for x86_64 finds opportunities to generate the "adc" (add
with carry) instruction to avoid a conditional branch.  However, the dst of the
adc can only be in a register.  The optimizer misses a chance to use "adc" with
the destination in memory, and will instead use a conditional branch in a
straightforward manner.  The following program shows that foo1 uses adc, but
foo0 does not.

Although I haven't tested this, I'm sure that the other 3 possibilities in this
family (involving sbb and/or different literal values to add/subtract) will
also not find the opportunity to do a memory update with adc.

extern void consumep(int *);
extern void consume(int);
void foo0(unsigned a, unsigned b, int *victim)
{
  if (a > b) { (*victim)++; }
  consumep(victim);
}
void foo1(unsigned a, unsigned b, int victim)
{
  if (a > b) { victim++; }
  consume(victim);
}


-- 
           Summary: missed opportunity to use adc
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rrh at google dot com
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38544

Reply via email to