summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2013-10-18 23:43:53 +0000
committerAndrew Trick <atrick@apple.com>2013-10-18 23:43:53 +0000
commit768b917dc888a823f5bcad8eb9073e31dd64ec46 (patch)
tree99f14e2bc2cdc35a7a23ecae11289d68514bab31 /llvm/lib/Analysis/MemoryBuiltins.cpp
parent5cc9084dd775ab7f05131043b40bc043450715ff (diff)
downloadbcm5719-llvm-768b917dc888a823f5bcad8eb9073e31dd64ec46.tar.gz
bcm5719-llvm-768b917dc888a823f5bcad8eb9073e31dd64ec46.zip
SCEV should use NSW to get trip count for positive nonunit stride loops.
SCEV currently fails to compute loop counts for nonunit stride loops. This comes up frequently. It prevents loop optimization and forces vectorization to insert extra loop checks. For example: void foo(int n, int *x) { for (int i = 0; i < n; i += 3) { x[i] = i; x[i+1] = i+1; x[i+2] = i+2; } } We need to properly handle the case in which limit > INT_MAX-stride. In the above case: n > INT_MAX-3. In this case the loop counter will step beyond the limit and overflow at the same time. However, knowing that signed integer overlow in undefined, we can assume the loop test behavior is arbitrary after overflow. This obeys both C undefined behavior rules, and the more strict LLVM poison value rules. I'm finally fixing this in response to Hal Finkel's persistence. The most probable reason that we never optimized this before is that we were being careful to handle case where the developer expected a side-effect free infinite loop relying on overflow: for (int i = 0; i < n; i += s) { ++j; } return j; If INT_MAX+1 is a multiple of s and n > INT_MAX-s, then we might expect an infinite loop. However there are plenty of ways to achieve this effect without relying on undefined behavior of signed overflow. llvm-svn: 193015
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
0 files changed, 0 insertions, 0 deletions
OpenPOWER on IntegriCloud