Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCMC optimisation fails to kick in when in the presence of multi-specz #336

Open
jimbxb opened this issue Jun 20, 2022 · 1 comment
Open
Labels
bug Something isn't working performance Issues related to performance of generated code

Comments

@jimbxb
Copy link
Collaborator

jimbxb commented Jun 20, 2022

As the title says.

E.g., consider the following:

pub def list(ar:array(T)):list(T) = ls where {
    if { [?x | ?ar] = ar ::
        ?ls = list(ar)
        [x | ls] = ?ls 
       | else :: 
        ?ls = []
    }
}

The compiler generates the following:

list > public (1 calls)
0: opt.list<0>
list(ar##0:wybe.array(T), ?#result##0:wybe.list(T))<{}; {}>:
  AliasPairs: []
  InterestingCallProperties: [InterestingUnaliased 0]
  MultiSpeczDepInfo: [(0,(wybe.array.[|]<0>,fromList [NonAliasedParamCond 2 [0]])),(1,(opt.list<0>,fromList [NonAliasedParamCond 0 []]))]
    wybe.array.[|]<0>(?x##0:T, ?ar##1:wybe.array(T), ~ar##0:wybe.array(T), ?tmp#3##0:wybe.bool) #0 @opt:16:10
    case ~tmp#3##0:wybe.bool of
    0:
        foreign llvm move(0:wybe.list(T), ?#result##0:wybe.list(T)) @opt:15:5

    1:
        opt.list<0>[410bae77d3](~ar##1:wybe.array(T), ?tmp#0##0:wybe.list(T)) #1 @opt:17:15
        foreign lpvm alloc(16:wybe.int, ?tmp#6##0:wybe.list(T)) @list:9:27
        foreign lpvm mutate(~tmp#6##0:wybe.list(T), ?tmp#7##0:wybe.list(T), 0:wybe.int, 1:wybe.int, 16:wybe.int, 0:wybe.int, ~x##0:T) @list:9:27
        foreign lpvm mutate(~tmp#7##0:wybe.list(T), ?#result##0:wybe.list(T), 8:wybe.int, 1:wybe.int, 16:wybe.int, 0:wybe.int, ~tmp#0##0:wybe.list(T)) @list:9:27

However with -xno-multi-specz, the compiler can use the TCMC optimisation. The only difference is the multi-specz call in the body.

list > public (1 calls)
0: opt.list<0>
list(ar##0:wybe.array(T), outByReference #result##0:wybe.list(T))<{}; {}>:
  AliasPairs: []
  InterestingCallProperties: [InterestingUnaliased 0]
  MultiSpeczDepInfo: [(0,(wybe.array.[|]<0>,fromList [NonAliasedParamCond 2 [0]])),(1,(opt.list<0>,fromList [NonAliasedParamCond 0 []]))]
    wybe.array.[|]<0>(?x##0:T, ?ar##1:wybe.array(T), ~ar##0:wybe.array(T), ?tmp#3##0:wybe.bool) #0 @opt:16:10
    case ~tmp#3##0:wybe.bool of
    0:
        foreign llvm move(0:wybe.list(T), ?#result##0:wybe.list(T)) @opt:15:5

    1:
        foreign lpvm alloc(16:wybe.int, ?tmp#6##0:wybe.list(T)) @list:9:27
        foreign lpvm mutate(~tmp#6##0:wybe.list(T), ?tmp#7##0:wybe.list(T), 0:wybe.int, 1:wybe.int, 16:wybe.int, 0:wybe.int, ~x##0:T) @list:9:27
        opt.list<0>(~ar##1:wybe.array(T), outByReference tmp#0##0:wybe.list(T)) #1 @opt:17:15
        foreign lpvm mutate(~tmp#7##0:wybe.list(T), ?#result##0:wybe.list(T), 8:wybe.int, 1:wybe.int, 16:wybe.int, 0:wybe.int, ~takeReference tmp#0##0:wybe.list(T)) @list:9:27
@neon64
Copy link
Contributor

neon64 commented Jun 20, 2022

Hey, good pick up! I believe this behavior should be fixed in #316 (comment), I've done the rest of my uni exams now, so hopefully can look at polishing those changes

@jimbxb jimbxb added bug Something isn't working performance Issues related to performance of generated code labels Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance Issues related to performance of generated code
Projects
None yet
Development

No branches or pull requests

2 participants