From 6b738b8719dc71499b557ce7c8c8066e7d8b81e7 Mon Sep 17 00:00:00 2001 From: Matthew Fluet Date: Thu, 8 Aug 2019 15:08:31 -0400 Subject: [PATCH] Add `-codegen-fuse-op-and-chk {false|true}` compile-time flag It appears that GCC (and, to a lesser extent) Clang/LLVM do not always successfully fuse adjacent `Word_` and `Word{S,U}_CheckP` primitives. The performance results reported at https://github.com/MLton/mlton/pull/273 and https://github.com/MLton/mlton/pull/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}_CheckP` and another for `Word_`). This flag will be used to enable explicit fusing of adjacent `Word_` and `Word{S,U}_CheckP` primitives in the codegens. --- mlton/control/control-flags.sig | 3 +++ mlton/control/control-flags.sml | 5 ++++- mlton/main/main.fun | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mlton/control/control-flags.sig b/mlton/control/control-flags.sig index 45ad6b429d..6f25b31343 100644 --- a/mlton/control/control-flags.sig +++ b/mlton/control/control-flags.sig @@ -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. *) diff --git a/mlton/control/control-flags.sml b/mlton/control/control-flags.sml index 85b635c49b..df383ce86e 100644 --- a/mlton/control/control-flags.sml +++ b/mlton/control/control-flags.sml @@ -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, diff --git a/mlton/main/main.fun b/mlton/main/main.fun index f7b6e2ec62..b9bc10a16c 100644 --- a/mlton/main/main.fun +++ b/mlton/main/main.fun @@ -332,6 +332,8 @@ fun makeOptions {usage} = | NONE => usage (concat ["invalid -codegen flag: ", s]))))), (Expert, "codegen-comments", " ", "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", " ' '", "set compile-time constant", SpaceString (fn s => case String.tokens (s, Char.isSpace) of