... | ... | @@ -300,7 +300,69 @@ else |
|
|
if (x >= 0) return 10;
|
|
|
else return 100;
|
|
|
```
|
|
|
That is a lot of code. Could we do better here? Can we use the fact that this function is returning only two values somehow? See below for a new approach.
|
|
|
That is a lot of code. Could we do better here? Can we use the fact that this function is returning only two values somehow? We describe our new approach below which now generates for following.
|
|
|
|
|
|
```
|
|
|
.Lc15M_info:
|
|
|
movq 7(%rbx),%rax
|
|
|
testq %rax,%rax
|
|
|
jl .Lc15X
|
|
|
.Lu166:
|
|
|
cmpq $61,%rax
|
|
|
jg .Lc15X
|
|
|
.Lu167:
|
|
|
movq $-1152920405094694900,%rbx
|
|
|
movq %rax,%rcx
|
|
|
shlq %cl,%rbx
|
|
|
testq %rbx,%rbx
|
|
|
jge .Lc15X
|
|
|
.Lu168:
|
|
|
movl $stg_INTLIKE_closure+417,%ebx -- return 10
|
|
|
addq $8,%rbp
|
|
|
jmp *(%rbp)
|
|
|
.Lc15X:
|
|
|
movl $stg_INTLIKE_closure+1857,%ebx -- return 100
|
|
|
addq $8,%rbp
|
|
|
jmp *(%rbp)
|
|
|
```
|
|
|
For comparison this is what is generated by ghc 8.10.7:
|
|
|
```
|
|
|
Foo_zdwf_info:
|
|
|
cmpq $45,%r14
|
|
|
jl .Lu1Fk
|
|
|
.Lu1Fq:
|
|
|
cmpq $61,%r14
|
|
|
jl .Lu1Fr
|
|
|
.Lu1Fs:
|
|
|
cmpq $62,%r14
|
|
|
jl .Lc1F9
|
|
|
.Lc1F8:
|
|
|
movl $100,%ebx
|
|
|
jmp *(%rbp)
|
|
|
.Lu1Fr:
|
|
|
cmpq $60,%r14
|
|
|
jl .Lc1F8
|
|
|
.Lc1F9:
|
|
|
movl $10,%ebx
|
|
|
jmp *(%rbp)
|
|
|
.Lu1Fk:
|
|
|
cmpq $4,%r14
|
|
|
jl .Lu1Fl
|
|
|
.Lu1Fo:
|
|
|
cmpq $44,%r14
|
|
|
jge .Lc1F9
|
|
|
.Lu1Fp:
|
|
|
cmpq $23,%r14
|
|
|
jne .Lc1F8
|
|
|
jmp .Lc1F9
|
|
|
.Lu1Fl:
|
|
|
cmpq $3,%r14
|
|
|
jge .Lc1F9
|
|
|
.Lu1Fm:
|
|
|
testq %r14,%r14
|
|
|
jl .Lc1F8
|
|
|
jmp .Lc1F9
|
|
|
```
|
|
|
|
|
|
4. Consider a function like the following:
|
|
|
```
|
... | ... | @@ -417,4 +479,4 @@ Compilation of Contiguous Regions Segment: |
|
|
We now go through the details of how Contiguous Regions are compiled. We deal with the the presence and absence of default label separately.
|
|
|
|
|
|
No-default case:
|
|
|
---------------- |
|
|
---------------- |
|
|
\ No newline at end of file |