Skip to content

Improve complex pattern match #1494

@bobzhang

Description

@bobzhang

OCaml's pattern match compiler generates very efficient code, however, it is not tweaked for code size,
see such example:

let f x =
   let y  = match x with a0::a1::a2::a3::a4::a5::a6::_ -> a0+a1+a2+a3+a4+a5+a6 | _ -> 0 in y  + 2 ;;

The common pattern is that for each pattern, we generate lots of temporay let match/id =a xx in if match/id

if we lift the definition to the toplevel.

var match/id
if (match/id = xx) 

Then we can simplify further

var match/id0, match/id1
if(match/id0 = xx0 && match/id1 = xx1){
   ..
} else {
 ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions