reinstate r222872: Peephole optimization in switch table lookup: reuse the guarding...
authorErik Eckstein <eeckstein@apple.com>
Thu, 27 Nov 2014 15:13:14 +0000 (15:13 +0000)
committerErik Eckstein <eeckstein@apple.com>
Thu, 27 Nov 2014 15:13:14 +0000 (15:13 +0000)
commit0d86c7623f6d0a338366b6e0ebdf9bd78c616278
treed0f8ac56419136b8dbe4d80542ff101396d552ff
parent79121238933fbe7957a3a170730e579c9d1fccc0
reinstate r222872: Peephole optimization in switch table lookup: reuse the guarding table comparison if possible.

Fixed missing dominance check.
Original commit message:

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)
      ...
Jump threading will then eliminate the second if(cond).

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