Skip to content

Commit

Permalink
Add -codegen-fuse-op-and-chk {false|true} compile-time flag
Browse files Browse the repository at this point in the history
It appears that GCC (and, to a lesser extent) Clang/LLVM do not always
successfully fuse adjacent `Word<N>_<op>` and
`Word{S,U}<N>_<op>CheckP` primitives.  The performance results
reported at MLton#273 and
MLton#292 suggest that this does not
always have significant impact, but a close look at the `md5`
benchmark shows that the native codegen significantly outperforms the
C codegen with gcc-9 due to redundant arithmetic computations (one for
`Word{S,U}<N>_<op>CheckP` and another for `Word<N>_<op>`).

This flag will be used to enable explicit fusing of adjacent
`Word<N>_<op>` and `Word{S,U}<N>_<op>CheckP` primitives in the
codegens.
  • Loading branch information
MatthewFluet committed Aug 8, 2019
1 parent d1df0de commit 6b738b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mlton/control/control-flags.sig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ signature CONTROL_FLAGS =
(* whether or not to use comments in codegen *)
val codegenComments: int ref

(* whether or not to fuse `op` and `opCheckP` primitives in codegen *)
val codegenFuseOpAndChk: bool ref

val contifyIntoMain: bool ref

(* Generate an executable with debugging info. *)
Expand Down
5 changes: 4 additions & 1 deletion mlton/control/control-flags.sml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ val codegen = control {name = "codegen",
val codegenComments = control {name = "codegen comments",
default = 0,
toString = Int.toString}


val codegenFuseOpAndChk = control {name = "fuse `op` and `opCheckP` primitives in codegen",
default = false,
toString = Bool.toString}

val contifyIntoMain = control {name = "contifyIntoMain",
default = false,
Expand Down
2 changes: 2 additions & 0 deletions mlton/main/main.fun
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ fun makeOptions {usage} =
| NONE => usage (concat ["invalid -codegen flag: ", s]))))),
(Expert, "codegen-comments", " <n>", "level of comments (0)",
intRef codegenComments),
(Expert, "codegen-fuse-op-and-chk", " {false|true}", "fuse `op` and `opCheckP` primitives in codegen",
boolRef codegenFuseOpAndChk),
(Normal, "const", " '<name> <value>'", "set compile-time constant",
SpaceString (fn s =>
case String.tokens (s, Char.isSpace) of
Expand Down

0 comments on commit 6b738b8

Please sign in to comment.