https://bugs.llvm.org/show_bug.cgi?id=32320

            Bug ID: 32320
           Summary: [ppc] crandc of two cmps is much slower than two
                    cmp/br
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: PowerPC
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Compile following source code with options -mvsx -mcpu=power8 -O2


struct S{
  struct S* next;
};

struct S* foo(struct S* p, struct S* e)
{
  struct S* n;
  for (; (n = p->next) !=0 && n < e; p = n);
  return n;
}

LLVM generates:

foo:                                    # @foo
.Lfunc_begin0:
# BB#0:                                 # %entry
        .p2align        5
.LBB0_1:                                # %for.cond
                                        # =>This Inner Loop Header: Depth=1
        ld 3, 0(3)
        cmpdi    3, 0            // (n = p->next) !=0
        cmpld 1, 3, 4            // n < e
        crandc 20, 4, 2          //    &&
        bc 12, 20, .LBB0_1
# BB#2:                                 # %for.end
        blr


It uses crandc to combine the previous two cmp results, and then branch. It is
much slower than 2 simple cmp/br on power8, because crandc has data dependence
on previous cmp instructions, they have 5 cycles latency. In an internal
bigtable benchmark, the crandc version has only half of the performance of the
simple cmp/br version, with a similar code pattern.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to