llvm-project/llvm/lib
Andrew Trick 768b917dc8 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
2013-10-18 23:43:53 +00:00
..
Analysis SCEV should use NSW to get trip count for positive nonunit stride loops. 2013-10-18 23:43:53 +00:00
AsmParser Add a GlobalAlias::isValidLinkage to reduce code duplication. 2013-10-09 16:07:32 +00:00
Bitcode Update comment list of GLOBALVAR modifiers in BitcodeWriter to include externally_initialized. 2013-10-14 22:36:51 +00:00
CodeGen Debug Info: add a newly-created DIE to a parent in the same function. 2013-10-18 21:14:19 +00:00
DebugInfo Correct log message typo: ended ad -> ended at 2013-10-18 13:01:33 +00:00
ExecutionEngine Adding oprofile support for MCJIT. 2013-10-16 16:32:47 +00:00
IR Changing DebugInfoFinder to iterate over all the compile units. 2013-10-17 10:27:12 +00:00
IRReader Add 'const' qualifiers to static const char* variables. 2013-07-16 01:17:10 +00:00
LTO Add a 'deleteModule' method to the Linker class. 2013-10-16 08:59:57 +00:00
Linker Add a 'deleteModule' method to the Linker class. 2013-10-16 08:59:57 +00:00
MC MC asm parser: allow ?'s in symbol names, and handle @'s in names in MS asm 2013-10-18 20:46:28 +00:00
Object Path: Recognize Windows compiled resource file. 2013-10-15 22:45:38 +00:00
Option Fix another mistake in r190442. 2013-09-10 23:22:56 +00:00
Support Can we move to C++11 already? 2013-10-18 23:07:01 +00:00
TableGen Add an error check for a typo I accidentally made in a td file that caused an assert to fire. 2013-08-20 04:22:09 +00:00
Target Mark some command line flags as hidden 2013-10-18 23:38:13 +00:00
Transforms Mark some command line flags as hidden 2013-10-18 23:38:13 +00:00
CMakeLists.txt Move LTO support library to a component, allowing it to be tested 2013-09-24 23:52:22 +00:00
LLVMBuild.txt Move LTO support library to a component, allowing it to be tested 2013-09-24 23:52:22 +00:00
Makefile Move LTO support library to a component, allowing it to be tested 2013-09-24 23:52:22 +00:00