[PATCH] D27321: Fix LSR ImmCost calculation for profitable chains

Evgeny Stupachenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 6 18:55:40 PST 2017


evstupac added a comment.

> Looking a bit closer, I agree that the main problem is that we assume the fix ups are free for the profitable chain. Maybe we should change the profitability check for the chains altogether or have a different user for them, like one that only sums the immcost?

That is exactly what I'm trying to implement in the patch. Basically "avg Offset" will most likely be just Offset, because it is hard to imagine how there could be more than 1 fixup for profitable chain.

> In particular, the code below that line could use some refinement:
> 
>   // Incrementing by zero or some constant is neutral. We assume constants can
>   // be folded into an addressing mode or an add's immediate operand.

...

> Fixing that seems to fix your test case, but I may have overlooked something admittedly.

Yes it help with the test, but do not solve the problem.
Maybe we should this fix this as well as a part of another patch.

The following C example also suffers from incorrect immcost calculation (-fno-tree-vectorize required):
void foo(int n, char *x, char *y) {

  char *xx = x - 1024;
  char *yy = y - 2;
  for (int i = 0; i < 1024; i++) {
    ++*xx++;
    ++*yy++;
  }

}

Currently LLVM creates:

  movq    $-1024, %rax

.LBB0_1:

  incb    (%rsi,%rax)
  incb    1022(%rdx,%rax)
  incb    1(%rsi,%rax)
  incb    1023(%rdx,%rax)
  addq    $2, %rax
  testl   %eax, %eax
  jne     .LBB0_1

Assuming ImmCost(1022) < ImmCost(1024), but it should not as real ImmCost of the solution should be ImmCost(1022) + ImmCost(1023) which is > ImmCost(1024).

So the solution should look like:

  movq    $0, %rax
  addl    $-2, %rsi
  addl    $-1024, %rdx

.LBB0_1:

  incb    (%rsi,%rax)
  incb    (%rdx,%rax)
  incb    1(%rsi,%rax)
  incb    1(%rdx,%rax)
  addq    $2, %rax
  cmpq   $1024, %rax
  jne     .LBB0_1


Repository:
  rL LLVM

https://reviews.llvm.org/D27321





More information about the llvm-commits mailing list