Skip to content

Instantly share code, notes, and snippets.

@chfast
Last active November 18, 2016 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chfast/1e9cd13c8db4bf5489dc7ac95b1d565d to your computer and use it in GitHub Desktop.
Save chfast/1e9cd13c8db4bf5489dc7ac95b1d565d to your computer and use it in GitHub Desktop.
LLVM switch for EVM
void f1(void);
void f2(void);
void f3(void);
void f4(void);
void f5(void);
void f6(void);
void f7(void);
void f8(void);
void switchA(int a) {
switch (a) {
case 0x6bcdef: return f1();
case 0x139243: return f2();
case 0x444444: return f3();
case 0x123aaa: return f4();
case 0x00ff00: return f5();
case 0x333333: return f6();
case 0x0011ee: return f7();
case 0x010101: return f8();
}
}
void switchB(int a) {
switch (a) {
case 15: return f1();
case 3: return f2();
case 7: return f3();
case 11: return f4();
case 1: return f5();
case 14: return f6();
case 4: return f7();
case 8: return f8();
}
}
; ModuleID = '/home/chfast/.ccache/tmp/switch.stdout.x53s.28861.alXCGU.i'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
; Function Attrs: nounwind uwtable
define void @switchA(i32 %a) #0 {
switch i32 %a, label %9 [
i32 7065071, label %1
i32 1282627, label %2
i32 4473924, label %3
i32 1194666, label %4
i32 65280, label %5
i32 3355443, label %6
i32 4590, label %7
i32 65793, label %8
]
; <label>:1 ; preds = %0
tail call void @f1() #2
br label %9
; <label>:2 ; preds = %0
tail call void @f2() #2
br label %9
; <label>:3 ; preds = %0
tail call void @f3() #2
br label %9
; <label>:4 ; preds = %0
tail call void @f4() #2
br label %9
; <label>:5 ; preds = %0
tail call void @f5() #2
br label %9
; <label>:6 ; preds = %0
tail call void @f6() #2
br label %9
; <label>:7 ; preds = %0
tail call void @f7() #2
br label %9
; <label>:8 ; preds = %0
tail call void @f8() #2
br label %9
; <label>:9 ; preds = %1, %2, %3, %4, %5, %6, %7, %8, %0
ret void
}
declare void @f1() #1
declare void @f2() #1
declare void @f3() #1
declare void @f4() #1
declare void @f5() #1
declare void @f6() #1
declare void @f7() #1
declare void @f8() #1
; Function Attrs: nounwind uwtable
define void @switchB(i32 %a) #0 {
switch i32 %a, label %9 [
i32 15, label %1
i32 3, label %2
i32 7, label %3
i32 11, label %4
i32 1, label %5
i32 14, label %6
i32 4, label %7
i32 8, label %8
]
; <label>:1 ; preds = %0
tail call void @f1() #2
br label %9
; <label>:2 ; preds = %0
tail call void @f2() #2
br label %9
; <label>:3 ; preds = %0
tail call void @f3() #2
br label %9
; <label>:4 ; preds = %0
tail call void @f4() #2
br label %9
; <label>:5 ; preds = %0
tail call void @f5() #2
br label %9
; <label>:6 ; preds = %0
tail call void @f6() #2
br label %9
; <label>:7 ; preds = %0
tail call void @f7() #2
br label %9
; <label>:8 ; preds = %0
tail call void @f8() #2
br label %9
; <label>:9 ; preds = %1, %2, %3, %4, %5, %6, %7, %8, %0
ret void
}
attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { nounwind }
!llvm.ident = !{!0}
!0 = !{!"clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)"}
.text
.file "/home/chfast/.ccache/tmp/switch.stdout.x53s.28788.cm14c2.i"
.globl switchA
.align 16, 0x90
.type switchA,@function
switchA: # @switchA
.cfi_startproc
# BB#0:
cmpl $1282626, %edi # imm = 0x139242
jg .LBB0_8
# BB#1:
cmpl $65792, %edi # imm = 0x10100
jg .LBB0_5
# BB#2:
cmpl $4590, %edi # imm = 0x11EE
je .LBB0_17
# BB#3:
cmpl $65280, %edi # imm = 0xFF00
jne .LBB0_19
# BB#4:
jmp f5 # TAILCALL
.LBB0_8:
cmpl $4473923, %edi # imm = 0x444443
jg .LBB0_12
# BB#9:
cmpl $1282627, %edi # imm = 0x139243
je .LBB0_15
# BB#10:
cmpl $3355443, %edi # imm = 0x333333
jne .LBB0_19
# BB#11:
jmp f6 # TAILCALL
.LBB0_5:
cmpl $65793, %edi # imm = 0x10101
je .LBB0_18
# BB#6:
cmpl $1194666, %edi # imm = 0x123AAA
jne .LBB0_19
# BB#7:
jmp f4 # TAILCALL
.LBB0_12:
cmpl $4473924, %edi # imm = 0x444444
je .LBB0_16
# BB#13:
cmpl $7065071, %edi # imm = 0x6BCDEF
jne .LBB0_19
# BB#14:
jmp f1 # TAILCALL
.LBB0_17:
jmp f7 # TAILCALL
.LBB0_15:
jmp f2 # TAILCALL
.LBB0_18:
jmp f8 # TAILCALL
.LBB0_16:
jmp f3 # TAILCALL
.LBB0_19:
retq
.Lfunc_end0:
.size switchA, .Lfunc_end0-switchA
.cfi_endproc
.globl switchB
.align 16, 0x90
.type switchB,@function
switchB: # @switchB
.cfi_startproc
# BB#0:
decl %edi
cmpl $14, %edi
ja .LBB1_10
# BB#1:
jmpq *.LJTI1_0(,%rdi,8)
.LBB1_6:
jmp f5 # TAILCALL
.LBB1_10:
retq
.LBB1_3:
jmp f2 # TAILCALL
.LBB1_8:
jmp f7 # TAILCALL
.LBB1_4:
jmp f3 # TAILCALL
.LBB1_9:
jmp f8 # TAILCALL
.LBB1_5:
jmp f4 # TAILCALL
.LBB1_7:
jmp f6 # TAILCALL
.LBB1_2:
jmp f1 # TAILCALL
.Lfunc_end1:
.size switchB, .Lfunc_end1-switchB
.cfi_endproc
.section .rodata,"a",@progbits
.align 8
.LJTI1_0:
.quad .LBB1_6
.quad .LBB1_10
.quad .LBB1_3
.quad .LBB1_8
.quad .LBB1_10
.quad .LBB1_10
.quad .LBB1_4
.quad .LBB1_9
.quad .LBB1_10
.quad .LBB1_10
.quad .LBB1_5
.quad .LBB1_10
.quad .LBB1_10
.quad .LBB1_7
.quad .LBB1_2
.ident "clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)"
.section ".note.GNU-stack","",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment