HomePhabricator

Optimize switch lookup tables with linear mapping.

Description

Optimize switch lookup tables with linear mapping.

This is a simple optimization for switch table lookup:
It computes the output value directly with an (optional) mul and add if there is a linear mapping between index and output.
Example:

int f1(int x) {

switch (x) {
  case 0: return 10;
  case 1: return 11;
  case 2: return 12;
  case 3: return 13;
}
return 0;

}

generates:

define i32 @f1(i32 %x) #0 {
entry:

%0 = icmp ult i32 %x, 4
br i1 %0, label %switch.lookup, label %return

switch.lookup:

%switch.offset = add i32 %x, 10
ret i32 %switch.offset

return:

ret i32 0

}

Details

Committed
eecksteinNov 17 2014, 1:13 AM
Parents
rL222120: Fix CR/LF line endings in test case.
Branches
Unknown
Tags
Unknown

Event Timeline