llvm-6502/test
Jim Grosbach dc2dc390f6 LowerSwitch: track bounding range for the condition tree.
When LowerSwitch transforms a switch instruction into a tree of ifs it
is actually performing a binary search into the various case ranges, to
see if the current value falls into one cases range of values.

So, if we have a program with something like this:

switch (a) {
case 0:
  do0();
  break;
case 1:
  do1();
  break;
case 2:
  do2();
  break;
default:
  break;
}

the code produced is something like this:

  if (a < 1) {
    if (a == 0) {
      do0();
    }
  } else {
    if (a < 2) {
      if (a == 1) {
        do1();
      }
    } else {
      if (a == 2) {
        do2();
      }
    }
  }

This code is inefficient because the check (a == 1) to execute do1() is
not needed.

The reason is that because we already checked that (a >= 1) initially by
checking that also  (a < 2) we basically already inferred that (a == 1)
without the need of an extra basic block spawned to check if actually (a
== 1).

The patch addresses this problem by keeping track of already
checked bounds in the LowerSwitch algorithm, so that when the time
arrives to produce a Leaf Block that checks the equality with the case
value / range the algorithm can decide if that block is really needed
depending on the already checked bounds .

For example, the above with "a = 1" would work like this:

the bounds start as LB: NONE , UB: NONE
as (a < 1) is emitted the bounds for the else path become LB: 1 UB:
NONE. This happens because by failing the test (a < 1) we know that the
value "a" cannot be smaller than 1 if we enter the else branch.
After the emitting the check (a < 2) the bounds in the if branch become
LB: 1 UB: 1. This is because by checking that "a" is smaller than 2 then
the upper bound becomes 2 - 1 = 1.

When it is time to emit the leaf block for "case 1:" we notice that 1
can be squeezed exactly in between the LB and UB, which means that if we
arrived to that block there is no need to emit a block that checks if (a
== 1).

Patch by: Marcello Maggioni <hayarms@gmail.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211038 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-16 16:55:20 +00:00
..
Analysis Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
Assembler Canonicalize addrspacecast ConstExpr between different pointer types 2014-06-15 21:40:57 +00:00
Bindings Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
Bitcode IR: add "cmpxchg weak" variant to support permitted failure. 2014-06-13 14:24:07 +00:00
BugPoint
CodeGen Hook up vector int_ctlz for AVX512. 2014-06-16 14:12:28 +00:00
DebugInfo PR20038: DebugInfo missing DIEs for some concrete variables. 2014-06-15 19:34:26 +00:00
ExecutionEngine Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
Feature Move test for r210734 to Feature/aliases.ll. 2014-06-12 21:37:30 +00:00
FileCheck
Instrumentation Remove top-level Clang -fsanitize= flags for optional ASan features. 2014-06-13 17:53:44 +00:00
Integer
JitListener
Linker Allow aliases to be unnamed_addr. 2014-06-06 01:20:28 +00:00
LTO Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
MC [mips][mips64r6] ssnop is deprecated on MIPS32r6/MIPS64r6 2014-06-16 13:25:35 +00:00
Object Fix pr17056. 2014-06-16 16:41:00 +00:00
Other Canonicalize addrspacecast ConstExpr between different pointer types 2014-06-15 21:40:57 +00:00
TableGen Fix error in tablegen when either operand of !if is an empty list. 2014-06-10 20:10:08 +00:00
tools Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
Transforms LowerSwitch: track bounding range for the condition tree. 2014-06-16 16:55:20 +00:00
Unit
Verifier Move test for r210734 to Feature/aliases.ll. 2014-06-12 21:37:30 +00:00
YAMLParser
.clang-format
CMakeLists.txt
lit.cfg Reduce verbiage of lit.local.cfg files 2014-06-09 22:42:55 +00:00
lit.site.cfg.in
Makefile lld test for configure & make 2014-06-06 09:06:25 +00:00
Makefile.tests
TestRunner.sh