[LLVMbugs] [Bug 21370] New: Improve cost model for lengthens followed by truncates

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 24 06:53:09 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21370

            Bug ID: 21370
           Summary: Improve cost model for lengthens followed by truncates
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: james.molloy at arm.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The loop vectorizer does not have a model for sequences of
lengthen->arithmetic->truncate. These sequences are often generated due to
implicit int promotions when dealing with sub-int types, and the
lengthen/truncate can be elided.
One of the "obvious" solutions to this would be to question why the
lengthen/truncate sequence hadn't been removed in the first place. This has
been discussed on-list, and keeping it is deliberate. If the sequence is not
vectorized, the lengthens and truncates would have to be generated because most
architectures can't do scalar arithmetic on sub-word types. Only if it is
vectorized can we do 8-bit or 16-bit arithmetic. So the model for this needs to
be in the vectorizer.
In fact, if the vectorizer is forced to vectorize, it does actually remove the
lengthen/truncate in its generated code. It just doesn't account for this in
its cost model.

char arr[5000];
char arr2[5000];

void f() {
  for (int i = 0; i < 5000; ++i) {
    int a = arr[i] + 1;
    arr2[i] = a;
  }
}

./bin/clang -O3 -o - -S test-vec2.c -target arm64 -Rpass=loop-vectorize
-Rpass-analysis=loop-vectorize
test-vec2.c:5:3: remark: unrolled with interleaving factor 2 (vectorization not
      beneficial) [-Rpass=loop-vectorize]
  for (int i = 0; i < 5000; ++i) {
  ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141024/23f91869/attachment.html>


More information about the llvm-bugs mailing list