Peephole optimization in switch table lookup: reuse the guarding table comparison...
authorErik Eckstein <eeckstein@apple.com>
Thu, 27 Nov 2014 08:33:51 +0000 (08:33 +0000)
committerErik Eckstein <eeckstein@apple.com>
Thu, 27 Nov 2014 08:33:51 +0000 (08:33 +0000)
commite73e308ab965058c311d0239a6a43fd576917fd3
tree4ef0a4e8e3a9274d63964e3380608f9ace94adc8
parent40157d5c4db4a75ebc845022961a89661c728fea
Peephole optimization in switch table lookup: reuse the guarding table comparison if possible.

This optimization tries to reuse the generated compare instruction, if there is a comparison against the default value after the switch.
Example:
    if (idx < tablesize)
       r = table[idx]; // table does not contain default_value
    else
       r = default_value;
    if (r != default_value)
       ...
Is optimized to:
    cond = idx < tablesize;
    if (cond)
       r = table[idx];
    else
       r = default_value;
    if (cond)
       ...
\endcode
Jump threading will then eliminate the second if(cond).

llvm-svn: 222872
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll