[llvm-commits] [llvm] r77259 - in /llvm/trunk: docs/LangRef.html include/llvm/Bitcode/LLVMBitCodes.h include/llvm/Operator.h lib/AsmParser/LLLexer.cpp lib/AsmParser/LLParser.cpp lib/AsmParser/LLToken.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bit

Eli Friedman eli.friedman at gmail.com
Wed Jul 29 12:49:42 PDT 2009


2009/7/29 Török Edwin <edwintorok at gmail.com>:
> Its better if I give an example (in C, its easier that way):
>
> void foo(unsigned x)
> {
>     unsigned i;
>    char *a = malloc(10);
>    for (i=0;i<10;i++)
>       if (x < 10)
>            bar(a[x]);
> }
>
> LICM can move the a+x computation before the loop, and thus not guarded
> by the if.
> If you compute (a+x) before the loop, it may or may not be out of
> bounds, BUT when it is dereferenced
> inside the if, it is guaranteed that x<10, thus it is inbounds.

Exactly... and we consider the LICM transformation safe because the
GEP is not used in any context where the undefined result translates
into undefined behavior.  Again, it's the same way we treat an
undefined shift; the computation doesn't lead to undefined behavior.
Essentially, in the undefined cases, the result is equivalent to
"undef".

-Eli




More information about the llvm-commits mailing list