Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | <!DOCTYPE html>\r |
2 | <html lang="en">\r | |
3 | <head>\r | |
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r | |
5 | <meta name="generator" content="AsciiDoc 8.6.9">\r | |
6 | <title>CombineConversions</title>\r | |
7 | <link rel="stylesheet" href="./asciidoc.css" type="text/css">\r | |
8 | <link rel="stylesheet" href="./pygments.css" type="text/css">\r | |
9 | \r | |
10 | \r | |
11 | <script type="text/javascript" src="./asciidoc.js"></script>\r | |
12 | <script type="text/javascript">\r | |
13 | /*<![CDATA[*/\r | |
14 | asciidoc.install();\r | |
15 | /*]]>*/\r | |
16 | </script>\r | |
17 | <link rel="stylesheet" href="./mlton.css" type="text/css">\r | |
18 | </head>\r | |
19 | <body class="article">\r | |
20 | <div id="banner">\r | |
21 | <div id="banner-home">\r | |
22 | <a href="./Home">MLton 20180207</a>\r | |
23 | </div>\r | |
24 | </div>\r | |
25 | <div id="header">\r | |
26 | <h1>CombineConversions</h1>\r | |
27 | </div>\r | |
28 | <div id="content">\r | |
29 | <div id="preamble">\r | |
30 | <div class="sectionbody">\r | |
31 | <div class="paragraph"><p><a href="CombineConversions">CombineConversions</a> is an optimization pass for the <a href="SSA">SSA</a>\r | |
32 | <a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="SSASimplify">SSASimplify</a>.</p></div>\r | |
33 | </div>\r | |
34 | </div>\r | |
35 | <div class="sect1">\r | |
36 | <h2 id="_description">Description</h2>\r | |
37 | <div class="sectionbody">\r | |
38 | <div class="paragraph"><p>This pass looks for and simplifies nested calls to (signed)\r | |
39 | extension/truncation.</p></div>\r | |
40 | </div>\r | |
41 | </div>\r | |
42 | <div class="sect1">\r | |
43 | <h2 id="_implementation">Implementation</h2>\r | |
44 | <div class="sectionbody">\r | |
45 | <div class="ulist"><ul>\r | |
46 | <li>\r | |
47 | <p>\r | |
48 | <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/combine-conversions.fun"><span class="monospaced">combine-conversions.fun</span></a>\r | |
49 | </p>\r | |
50 | </li>\r | |
51 | </ul></div>\r | |
52 | </div>\r | |
53 | </div>\r | |
54 | <div class="sect1">\r | |
55 | <h2 id="_details_and_notes">Details and Notes</h2>\r | |
56 | <div class="sectionbody">\r | |
57 | <div class="paragraph"><p>It processes each block in dfs order (visiting definitions before uses):</p></div>\r | |
58 | <div class="ulist"><ul>\r | |
59 | <li>\r | |
60 | <p>\r | |
61 | If the statement is not a <span class="monospaced">PrimApp</span> with <span class="monospaced">Word_extdToWord</span>, skip it.\r | |
62 | </p>\r | |
63 | </li>\r | |
64 | <li>\r | |
65 | <p>\r | |
66 | After processing a conversion, it tags the <span class="monospaced">Var</span> for subsequent use.\r | |
67 | </p>\r | |
68 | </li>\r | |
69 | <li>\r | |
70 | <p>\r | |
71 | When inspecting a conversion, check if the <span class="monospaced">Var</span> operand is also the\r | |
72 | result of a conversion. If it is, try to combine the two operations.\r | |
73 | Repeatedly simplify until hitting either a non-conversion <span class="monospaced">Var</span> or a\r | |
74 | case where the conversion cannot be simplified.\r | |
75 | </p>\r | |
76 | </li>\r | |
77 | </ul></div>\r | |
78 | <div class="paragraph"><p>The optimization rules are very simple:</p></div>\r | |
79 | <div class="listingblock">\r | |
80 | <div class="content monospaced">\r | |
81 | <pre>x1 = ...\r | |
82 | x2 = Word_extdToWord (W1, W2, {signed=s1}) x1\r | |
83 | x3 = Word_extdToWord (W2, W3, {signed=s2}) x2</pre>\r | |
84 | </div></div>\r | |
85 | <div class="ulist"><ul>\r | |
86 | <li>\r | |
87 | <p>\r | |
88 | If <span class="monospaced">W1 = W2</span>, then there is no conversions before <span class="monospaced">x_1</span>.\r | |
89 | </p>\r | |
90 | <div class="paragraph"><p>This is guaranteed because <span class="monospaced">W2 = W3</span> will always trigger optimization.</p></div>\r | |
91 | </li>\r | |
92 | <li>\r | |
93 | <p>\r | |
94 | Case <span class="monospaced">W1 <= W3 <= W2</span>:\r | |
95 | </p>\r | |
96 | <div class="listingblock">\r | |
97 | <div class="content monospaced">\r | |
98 | <pre>x3 = Word_extdToWord (W1, W3, {signed=s1}) x1</pre>\r | |
99 | </div></div>\r | |
100 | </li>\r | |
101 | <li>\r | |
102 | <p>\r | |
103 | Case <span class="monospaced">W1 < W2 < W3 AND ((NOT s1) OR s2)</span>:\r | |
104 | </p>\r | |
105 | <div class="listingblock">\r | |
106 | <div class="content monospaced">\r | |
107 | <pre>x3 = Word_extdToWord (W1, W3, {signed=s1}) x1</pre>\r | |
108 | </div></div>\r | |
109 | </li>\r | |
110 | <li>\r | |
111 | <p>\r | |
112 | Case <span class="monospaced">W1 = W2 < W3</span>:\r | |
113 | </p>\r | |
114 | <div class="paragraph"><p>unoptimized, because there are no conversions past <span class="monospaced">W1</span> and <span class="monospaced">x2 = x1</span></p></div>\r | |
115 | </li>\r | |
116 | <li>\r | |
117 | <p>\r | |
118 | Case <span class="monospaced">W3 <= W2 <= W1 OR W3 <= W1 <= W2</span>:\r | |
119 | </p>\r | |
120 | <div class="listingblock">\r | |
121 | <div class="content monospaced">\r | |
122 | <pre>x_3 = Word_extdToWord (W1, W3, {signed=_}) x1</pre>\r | |
123 | </div></div>\r | |
124 | <div class="paragraph"><p>because <span class="monospaced">W3 <= W1 && W3 <= W2</span>, just clip <span class="monospaced">x1</span></p></div>\r | |
125 | </li>\r | |
126 | <li>\r | |
127 | <p>\r | |
128 | Case <span class="monospaced">W2 < W1 <= W3 OR W2 < W3 <= W1</span>:\r | |
129 | </p>\r | |
130 | <div class="paragraph"><p>unoptimized, because <span class="monospaced">W2 < W1 && W2 < W3</span>, has truncation effect</p></div>\r | |
131 | </li>\r | |
132 | <li>\r | |
133 | <p>\r | |
134 | Case <span class="monospaced">W1 < W2 < W3 AND (s1 AND (NOT s2))</span>:\r | |
135 | </p>\r | |
136 | <div class="paragraph"><p>unoptimized, because each conversion affects the result separately</p></div>\r | |
137 | </li>\r | |
138 | </ul></div>\r | |
139 | </div>\r | |
140 | </div>\r | |
141 | </div>\r | |
142 | <div id="footnotes"><hr></div>\r | |
143 | <div id="footer">\r | |
144 | <div id="footer-text">\r | |
145 | </div>\r | |
146 | <div id="footer-badges">\r | |
147 | </div>\r | |
148 | </div>\r | |
149 | </body>\r | |
150 | </html>\r |