rodrigo rocha university of edinburgh function merging · merging functions. production compilers:...
TRANSCRIPT
http://rcor.meRodrigo Rocha University of Edinburgh
by
SEQUENCE ALIGNMENT
FUNCTION MERGING
DOES SIZE MATTER?
YESDOES SIZE MATTER?
...
EMBEDDED
SYSTEMS
YESDOES SIZE MATTER?
BIN0101110110
10 01 1
0
1
01
0
11
SAVINGS IN CODE
Smaller Memories
COST SAVINGS
HOW TO REDUCE SIZE?
Similar or Identical
MERGE
FUNCTIONS
HOW TO REDUCE SIZE?
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
MERGING FUNCTIONS
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Identical Code
MERGING FUNCTIONS
merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Identical Code
MERGING FUNCTIONS
merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
, int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Selecting Different Operands
MERGING FUNCTIONS
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Branching to Distinct CFG
MERGING FUNCTIONS
if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Branching to Distinct CFG
MERGING FUNCTIONS
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Branching to Distinct CFG
MERGING FUNCTIONS
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Combining the Return Value
MERGING FUNCTIONS
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Combining the Return Value
MERGING FUNCTIONS
int
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Combining the Return Value
MERGING FUNCTIONS
return result;}
int
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Combining the Return Value
MERGING FUNCTIONS
return result;}
int
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
Reduces Code Size!
MERGING FUNCTIONS
return result;}
int
if (func_id==2) if (result==0) printf("result is zero\n");
term; b ; 10 : int term = (func_id==1)? , int func_id) { merged(int a, int b
int var = a*b + int result = foo(var); printf("result: %d\n", result);
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
However...
State of the Art FAILS
MERGING FUNCTIONS
Production compilers:
LLVM, GCC, MSVC
WHAT WE HAVE
Only Identical Functions
Production compilers:
LLVM, GCC, MSVC
WHAT WE HAVE
The state of the art
WHAT WE HAVE
significant improvement but...
The state of the art
WHAT WE HAVE
MUST HAVE IDENTICAL
significant improvement but...
The state of the art
WHAT WE HAVE
CFGs
MUST HAVE IDENTICAL
significant improvement but...
The state of the art
WHAT WE HAVE
Return typesCFGs
MUST HAVE IDENTICAL
significant improvement but...
The state of the art
WHAT WE HAVE
Lists of parametersReturn typesCFGs
MUST HAVE IDENTICAL
significant improvement but...
The state of the art
WHAT WE HAVE
Number of instructions Lists of parametersReturn typesCFGs
MUST HAVE IDENTICAL
significant improvement but...
The state of the art
WHAT WE HAVE
WHAT WE WANT
Merge ANY two functions
WHAT WE WANT
Merge ANY two functions
CHOOSE when to do it
and
Merge ANY two functions
WHAT WE WANT
int f1(int a, int b) { int var = a*b + 10; int result = foo(var); printf("result: %d\n", result); return result;}
void f2(int a, int b) { int var = a*b + b; int result = foo(var); printf("result: %d\n", result); if (result==0) printf("result is zero\n");}
HOW WE DO IT
label: entry
%r0 = mul %a, %b%r1 = add %r0, 10%r2 = call foo(%r1)%r3 = call printf(@str,%r2)ret %r2
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
label: entry
%x0 = mul %a, %b%x1 = add %x0, %b%x2 = call foo(%x1)%x3 = call printf(@str,%x2)%x4 = icmp eq %x2, 0br %x4, %if.then, %if.end
IR L
evel
HOW WE DO IT
label: entry
%r0 = mul %a, %b%r1 = add %r0, 10%r2 = call foo(%r1)%r3 = call printf(@str,%r2)ret %r2
label: entry
%x0 = mul %a, %b%x1 = add %x0, %b%x2 = call foo(%x1)%x3 = call printf(@str,%x2)%x4 = icmp eq %x2, 0br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
HOW WE DO IT
label: entry
%r0 = mul %a, %b%r1 = add %r0, 10%r2 = call foo(%r1)%r3 = call printf(@str,%r2)ret %r2
label: entry
%x0 = mul %a, %b%x1 = add %x0, %b%x2 = call foo(%x1)%x3 = call printf(@str,%x2)%x4 = icmp eq %x2, 0br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
LINEARIZATION
label: entry
%x0 = mul %a, %b%x1 = add %x0, %b%x2 = call foo(%x1)%x3 = call printf(@str,%x2)%x4 = icmp eq %x2, 0br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
LINEARIZATION
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b%x1 = add %x0, %b%x2 = call foo(%x1)%x3 = call printf(@str,%x2)%x4 = icmp eq %x2, 0br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
LINEARIZATION
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)br %if.end
label: if.end
ret void
LINEARIZATION
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
LINEARIZATION
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
LINEARIZATION
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
IDENTIFY WHAT TO MERGE
label: entry
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
label: entry
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Match
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
Mismatch
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
IDENTIFY WHAT TO MERGE
G C A T - G C U
G - A T T A C A
Bioinformatics
SEQUENCE ALIGNMENT
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
SEQUENCE ALIGNMENT
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
-1 -1 = -2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
-1 -1 = -2 -1 -1 = -2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
-1 -1 = -2 -1 -1 = -2 0 + 2 = 2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
-1 -1 = -2 -1 -1 = -2 0 + 2 = 2
2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
2 -1 = 1 -2 -1 = -3 -1 -1 = -2
2
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1 -2 -3 -12-11-10-9-8-7-6-5-4
-1
-2
-3
-5
-6
-4
2 -1 = 1 -2 -1 = -3 -1 -1 = -2
2 1
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1
-1
-2
-2
-3
-3
-12-11-10-9
-9
-8
-8
-7
-7
-6
-6
-6
-5
-5
-6
-4
-4
2 1 0 -1 -2 -3 -5-4
-5-4-3-2-1012341
0
-1
-2
-3 0
1 4
5
56
663 6
6
3
2
4 3 2 1 0 -1 -2 -3
012345678
345789107
9 89 7 5 4
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1
-1
-2
-2
-3
-3
-12-11-10-9
-9
-8
-8
-7
-7
-6
-6
-6
-5
-5
-6
-4
-4
2 1 0 -1 -2 -3 -5-4
-5-4-3-2-1012341
0
-1
-2
-3 0
1 4
5
56
663 6
6
3
2
4 3 2 1 0 -1 -2 -3
012345678
345789107
9 89 7 5 4
SEQUENCE ALIGNMENT
Gap: -
1
Mis
matc
h: -1
Matc
h: +2
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1
-1
-2
-2
-3
-3
-12-11-10-9
-9
-8
-8
-7
-7
-6
-6
-6
-5
-5
-6
-4
-4
2 1 0 -1 -2 -3 -5-4
-5-4-3-2-1012341
0
-1
-2
-3 0
1 4
5
56
663 6
6
3
2
4 3 2 1 0 -1 -2 -3
012345678
345789107
9 89 7 5 4
SEQUENCE ALIGNMENT
mul
add
call foo
call printf
ret
mul
add
call foo
call printf
icmp eq
br label
call
br label
ret
label
label
0 -1
-1
-2
-2
-3
-3
-12-11-10-9
-9
-8
-8
-7
-7
-6
-6
-6
-5
-5
-6
-4
-4
2 1 0 -1 -2 -3 -5-4
-5-4-3-2-1012341
0
-1
-2
-3 0
1 4
5
56
663 6
6
3
2
4 3 2 1 0 -1 -2 -3
012345678
345789107
9 89 7 5 4
SEQUENCE ALIGNMENT
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: entrylabel: entry
CODE GENERATION
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1entry b1
Renaming TableCODE GENERATION
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1entry b1
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul
%r0 = mul %a, %b %x0 = mul %a, %b
entry b1
Renaming TableCODE GENERATION
%r0 = mul %a, %b
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x0 = mul %a, %b
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b
entry b1
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%m1 = add
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%m1 = add
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%m1 = add %m0,
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%m1 = add %m0,
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r1 = add %r0, 10
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x1 = add %x0, %b
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0,
entry b1r0 m0x0 m0
Renaming TableCODE GENERATION
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0
entry b1r0 m0x0 m0r1 m1x1 m1
Renaming TableCODE GENERATION
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0
entry b1r0 m0x0 m0r1 m1x1 m1
Renaming TableCODE GENERATION
%r2 = call foo(%r1)
%r3 = call printf(@str,%r2)
ret %r2
%x2 = call foo(%x1)
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)
entry b1r0 m0x0 m0r1 m1x1 m1
Renaming TableCODE GENERATION
%r3 = call printf(@str,%r2)
ret %r2
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2
Renaming TableCODE GENERATION
%r3 = call printf(@str,%r2)
ret %r2
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2
Renaming TableCODE GENERATION
%r3 = call printf(@str,%r2)
ret %r2
%x3 = call printf(@str,%x2)
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2
Renaming TableCODE GENERATION
ret %r2
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
%x4 = icmp eq %x2, 0
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
br %x4, %if.then, %if.end
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
%x5 = call printf(@str)
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
br %if.end
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
ret %r2
label: if.then
label: if.end
ret void
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
label: if.then
label: if.end
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
label: b4
br %b4
br %b4
ret %r2 ret void
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
label: b4
ret %r2 ret void
label: if.then
label: if.end
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
br %b4
br %b4
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
label: if.endbr %b4
label: if.then
label: b1%m0 = mul %a, %b%t0 = select %0, 10, %b%m1 = add %m0, %t0%m2 = call foo(%m1)%m3 = call printf(@str,%m2)br %0, %b2, %b3
label: b3label: b2%x4 = icmp eq %m2, 0br %x4, %if.then, %if.end
%x5 = call printf(@str)br %if.end
label: b4
br %b4
ret %m2
entry b1r0 m0x0 m0r1 m1x1 m1r2 m2x2 m2r3 m3x3 m3
Renaming TableCODE GENERATION
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
i32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
floati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
doublefloati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
doublefloati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
floatdoublefloati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
floatdoublefloati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
floatdoublefloati32*i32i1i1FuncID
i1 i32 i32* float
double float float i32 i32*
Function 1
Function 2
MERGING PARAMETERS
WHAT WE CAN HANDLE
CFGsInstructions
Return Types
List of Parameters
Operands
Number of Instructions
LLVM's
Identic
al Only
State
of A
rt Our
Technique
(FM
SA)Allowed
Differe
nces
WHAT WE CAN HANDLE
PROFITABLE MERGES
Brute Force
PROFITABLE MERGES
Brute ForceBrute Force: Infeasible
PROFITABLE MERGES
PROFITABLE MERGES
Precompute Fingerprints
PROFITABLE MERGES
Precompute Fingerprintsaddbr
call...
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
Ranking Candidates EstimatedUpper-BoundReduction
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
Ranking Candidates
PROFITABLE MERGES
MiBenchSPEC 2006
Benchmark Suite:
LTO with -Os
SOA: State of the Art
LLVM: Identical Only
FMSA: Our Technique
EVALUATION SETUP
1
2
3
4
5
6
%
LLVMSOA
FMSA
CO
DE
SIZ
E
RE
DU
CT
ION
AVERAGE ON SPEC'06
0.1
1.5
2
%
LLVMSOA
FMSA
CO
DE
SIZ
E
RE
DU
CT
ION
1
0.5
AVERAGE ON MIBENCH
1
2
3
4
5
6
%
LLVMSOA
FMSA
CO
DE
SIZ
E
RE
DU
CT
ION
2
4
6
8
10
12
%
LLVMSOA
FMSA
C Programs C++ Programs
AVERAGE ON SPEC'06
1
1.2
LLVM
SOA
FMSA
NORM
ALIZ
ED
RU
NT
IME
0.5
1.02
AVERAGE ON SPEC'06
1
1.2
LLVM
SOA
FMSA
NORM
ALIZ
ED
CO
MP
ILE
TIM
E
0.5
1.15
AVERAGE ON SPEC'06
Efficient Exploration Mechanism
NOVEL and POWERFUL Technique
for Merging ANY Pair of Functions
CONCLUSION
https://groups.google.com/d/msg/llvm-dev/HQRg58ZCXsM/N7fbgvZgBQAJ
LLVM Dev RFC:
https://github.com/rcorcs/fmsa
Source Code:
LINKS
https://reviews.llvm.org/D59442
LLVM Patch:
https://doi.org/10.1109/CGO.2019.8661174
Paper (CGO'19 ):
Rodrigo Rocha
Pavlos Petoumenos Zheng Wang Murray Cole Hugh Leather
Function Merging by Sequence Alignment
400.perlbench
401.bzip2
403.gcc
429.mcf
433.milc
444.namd
445.gobmk
447.dealII
450.soplex
453.povray
456.hmmer
458.sjeng
462.libquantum
464.h264ref
470.lbm
471.omnetpp
473.astar
482.sphinx3
Mean
20
40
60
80
100
Com
pil
ati
on
Tim
e (
%)
Fingerprinting
Ranking
Linearization
Alignment
Code-Gen
Updating Calls
Compilation Breakdown
Future Work:
Use a greedy sequence alignment
Avoid wasteful merges
400.perlbench
401.bzip2
403.gcc
429.mcf
433.milc
444.namd
445.gobmk
447.dealII
450.soplex
453.povray
456.hmmer
458.sjeng
462.libquantum
464.h264ref
470.lbm
471.omnetpp
473.astar
482.sphinx3
483.xalancbmkMean
0
5
10
15
20
25
Red
uct
ion
(%
)
1.4 2.
56.
0 6.2
6.2
6.3
Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle]
CRC32FFT
adpcm_c
adpcm_d
basicmath
bitcount
blowfish_d
blowfish_e
cjpeg
dijkstr
adjpeg
ghostscrip
tgsm
ispell
patricia pgp
qsort
rijndael
rsynth sha
stringsearch
susan
typesetMean
0
1
2
3
4
5
Red
uct
ion
(%
)
0.00.
1
1.71.
71.
71.
7
Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle]
IntelSPEC 2006
MiBench
400.perlbench
401.bzip2
403.gcc
429.mcf
433.milc
444.namd
445.gobmk
447.dealII
450.soplex
453.povray
456.hmmer
458.sjeng
462.libquantum
464.h264ref
470.lbm
471.omnetpp
473.astar
482.sphinx3
483.xalancbmkMean
0
5
10
15
20
25
30
Red
uct
ion
(%
)
1.8 3.
05.
75.
96.
06.
1
Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10] FMSA [oracle]
ARMSPEC 2006
Compilation Time
400.perlbench
401.bzip2
403.gcc
429.mcf
433.milc
444.namd
445.gobmk
447.dealII
450.soplex
453.povray
456.hmmer
458.sjeng
462.libquantum
464.h264ref
470.lbm
471.omnetpp
473.astar
482.sphinx3
483.xalancbmkMean
0
1
2
3
4
Norm
ali
zed
Tim
e
1.0 1.
01.
151.
471.74
Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10]
SPEC 2006
Runtime Overhead
400.perlbench
401.bzip2
403.gcc
429.mcf
433.milc
444.namd
445.gobmk
447.dealII
450.soplex
453.povray
456.hmmer
458.sjeng
462.libquantum
464.h264ref
470.lbm
471.omnetpp
473.astar
482.sphinx3
483.xalancbmkMean
0.8
0.9
1.0
1.1
1.2
Norm
ali
zed
Ru
nti
me
1.0 1.
0 1.021.
031.
03
Identical SOA FMSA [t=1] FMSA [t=5] FMSA [t=10]
SPEC 2006
Profile-Guided Results
0
1
2
3
4
5
Red
uct
ion
(%
)
0.50
0.75
1.00
1.10
1.20
Norm
ali
zed
Ru
nti
me
SoA
FMSA [NO-PG]
FMSA [PG-V1]
FMSA [PG-V2]
SPEC 2006: 433.milc
Example: State of the Art
Example of Identical Functions
template <int dim>unsigned int PolynomialSpace<dim>::compute_n_pols (const unsigned int n) {unsigned int n_pols = n;for (unsigned int i=1; i<dim; ++i) {n _pols *= (n+i);n _pols /= (i+ 1);}return n_pols;
}
unsigned int PolynomialSpace<1>::compute_n_pols(const unsigned int n) {return n;
}
template <int dim> inlineunsigned int TensorProductPolynomials<dim>::x_to_the_dim (const unsigned int x) {unsigned int y = 1;for (unsigned int d=0; d<dim; ++d) {
y *= x;}return y;
}
unsigned int TensorProductPolynomials<1>::x_to_the_dim(const unsigned int x) {return x;
}
After template specialization and applying optimizations:
Compilation Pipeline
.c
.c
.c
...opt
...
FEFE
FE
opt
opt
link optFM BE .o
FunctionMerging
LTO
IR
} BackEnd
FrontEnd
...