Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

238 rindas
11KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Insn Canonicalizations (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Insn Canonicalizations (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Insn Canonicalizations (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
  30. <link href="Expander-Definitions.html#Expander-Definitions" rel="next" title="Expander Definitions">
  31. <link href="Looping-Patterns.html#Looping-Patterns" rel="prev" title="Looping Patterns">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Insn-Canonicalizations"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Expander-Definitions.html#Expander-Definitions" accesskey="n" rel="next">Expander Definitions</a>, Previous: <a href="Looping-Patterns.html#Looping-Patterns" accesskey="p" rel="prev">Looping Patterns</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Canonicalization-of-Instructions"></a>
  68. <h3 class="section">17.14 Canonicalization of Instructions</h3>
  69. <a name="index-canonicalization-of-instructions"></a>
  70. <a name="index-insn-canonicalization"></a>
  71. <p>There are often cases where multiple RTL expressions could represent an
  72. operation performed by a single machine instruction. This situation is
  73. most commonly encountered with logical, branch, and multiply-accumulate
  74. instructions. In such cases, the compiler attempts to convert these
  75. multiple RTL expressions into a single canonical form to reduce the
  76. number of insn patterns required.
  77. </p>
  78. <p>In addition to algebraic simplifications, following canonicalizations
  79. are performed:
  80. </p>
  81. <ul>
  82. <li> For commutative and comparison operators, a constant is always made the
  83. second operand. If a machine only supports a constant as the second
  84. operand, only patterns that match a constant in the second operand need
  85. be supplied.
  86. </li><li> For associative operators, a sequence of operators will always chain
  87. to the left; for instance, only the left operand of an integer <code>plus</code>
  88. can itself be a <code>plus</code>. <code>and</code>, <code>ior</code>, <code>xor</code>,
  89. <code>plus</code>, <code>mult</code>, <code>smin</code>, <code>smax</code>, <code>umin</code>, and
  90. <code>umax</code> are associative when applied to integers, and sometimes to
  91. floating-point.
  92. </li><li> <a name="index-neg_002c-canonicalization-of"></a>
  93. <a name="index-not_002c-canonicalization-of"></a>
  94. <a name="index-mult_002c-canonicalization-of"></a>
  95. <a name="index-plus_002c-canonicalization-of"></a>
  96. <a name="index-minus_002c-canonicalization-of"></a>
  97. For these operators, if only one operand is a <code>neg</code>, <code>not</code>,
  98. <code>mult</code>, <code>plus</code>, or <code>minus</code> expression, it will be the
  99. first operand.
  100. </li><li> In combinations of <code>neg</code>, <code>mult</code>, <code>plus</code>, and
  101. <code>minus</code>, the <code>neg</code> operations (if any) will be moved inside
  102. the operations as far as possible. For instance,
  103. <code>(neg (mult A B))</code> is canonicalized as <code>(mult (neg A) B)</code>, but
  104. <code>(plus (mult (neg B) C) A)</code> is canonicalized as
  105. <code>(minus A (mult B C))</code>.
  106. </li><li> <a name="index-compare_002c-canonicalization-of"></a>
  107. For the <code>compare</code> operator, a constant is always the second operand
  108. if the first argument is a condition code register or <code>(cc0)</code>.
  109. </li><li> For instructions that inherently set a condition code register, the
  110. <code>compare</code> operator is always written as the first RTL expression of
  111. the <code>parallel</code> instruction pattern. For example,
  112. <div class="smallexample">
  113. <pre class="smallexample">(define_insn &quot;&quot;
  114. [(set (reg:CCZ FLAGS_REG)
  115. (compare:CCZ
  116. (plus:SI
  117. (match_operand:SI 1 &quot;register_operand&quot; &quot;%r&quot;)
  118. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;))
  119. (const_int 0)))
  120. (set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
  121. (plus:SI (match_dup 1) (match_dup 2)))]
  122. &quot;&quot;
  123. &quot;addl %0, %1, %2&quot;)
  124. </pre></div>
  125. </li><li> An operand of <code>neg</code>, <code>not</code>, <code>mult</code>, <code>plus</code>, or
  126. <code>minus</code> is made the first operand under the same conditions as
  127. above.
  128. </li><li> <code>(ltu (plus <var>a</var> <var>b</var>) <var>b</var>)</code> is converted to
  129. <code>(ltu (plus <var>a</var> <var>b</var>) <var>a</var>)</code>. Likewise with <code>geu</code> instead
  130. of <code>ltu</code>.
  131. </li><li> <code>(minus <var>x</var> (const_int <var>n</var>))</code> is converted to
  132. <code>(plus <var>x</var> (const_int <var>-n</var>))</code>.
  133. </li><li> Within address computations (i.e., inside <code>mem</code>), a left shift is
  134. converted into the appropriate multiplication by a power of two.
  135. </li><li> <a name="index-ior_002c-canonicalization-of"></a>
  136. <a name="index-and_002c-canonicalization-of"></a>
  137. <a name="index-De-Morgan_0027s-law"></a>
  138. De Morgan&rsquo;s Law is used to move bitwise negation inside a bitwise
  139. logical-and or logical-or operation. If this results in only one
  140. operand being a <code>not</code> expression, it will be the first one.
  141. <p>A machine that has an instruction that performs a bitwise logical-and of one
  142. operand with the bitwise negation of the other should specify the pattern
  143. for that instruction as
  144. </p>
  145. <div class="smallexample">
  146. <pre class="smallexample">(define_insn &quot;&quot;
  147. [(set (match_operand:<var>m</var> 0 &hellip;)
  148. (and:<var>m</var> (not:<var>m</var> (match_operand:<var>m</var> 1 &hellip;))
  149. (match_operand:<var>m</var> 2 &hellip;)))]
  150. &quot;&hellip;&quot;
  151. &quot;&hellip;&quot;)
  152. </pre></div>
  153. <p>Similarly, a pattern for a &ldquo;NAND&rdquo; instruction should be written
  154. </p>
  155. <div class="smallexample">
  156. <pre class="smallexample">(define_insn &quot;&quot;
  157. [(set (match_operand:<var>m</var> 0 &hellip;)
  158. (ior:<var>m</var> (not:<var>m</var> (match_operand:<var>m</var> 1 &hellip;))
  159. (not:<var>m</var> (match_operand:<var>m</var> 2 &hellip;))))]
  160. &quot;&hellip;&quot;
  161. &quot;&hellip;&quot;)
  162. </pre></div>
  163. <p>In both cases, it is not necessary to include patterns for the many
  164. logically equivalent RTL expressions.
  165. </p>
  166. </li><li> <a name="index-xor_002c-canonicalization-of"></a>
  167. The only possible RTL expressions involving both bitwise exclusive-or
  168. and bitwise negation are <code>(xor:<var>m</var> <var>x</var> <var>y</var>)</code>
  169. and <code>(not:<var>m</var> (xor:<var>m</var> <var>x</var> <var>y</var>))</code>.
  170. </li><li> The sum of three items, one of which is a constant, will only appear in
  171. the form
  172. <div class="smallexample">
  173. <pre class="smallexample">(plus:<var>m</var> (plus:<var>m</var> <var>x</var> <var>y</var>) <var>constant</var>)
  174. </pre></div>
  175. </li><li> <a name="index-zero_005fextract_002c-canonicalization-of"></a>
  176. <a name="index-sign_005fextract_002c-canonicalization-of"></a>
  177. Equality comparisons of a group of bits (usually a single bit) with zero
  178. will be written using <code>zero_extract</code> rather than the equivalent
  179. <code>and</code> or <code>sign_extract</code> operations.
  180. </li><li> <a name="index-mult_002c-canonicalization-of-1"></a>
  181. <code>(sign_extend:<var>m1</var> (mult:<var>m2</var> (sign_extend:<var>m2</var> <var>x</var>)
  182. (sign_extend:<var>m2</var> <var>y</var>)))</code> is converted to <code>(mult:<var>m1</var>
  183. (sign_extend:<var>m1</var> <var>x</var>) (sign_extend:<var>m1</var> <var>y</var>))</code>, and likewise
  184. for <code>zero_extend</code>.
  185. </li><li> <code>(sign_extend:<var>m1</var> (mult:<var>m2</var> (ashiftrt:<var>m2</var>
  186. <var>x</var> <var>s</var>) (sign_extend:<var>m2</var> <var>y</var>)))</code> is converted
  187. to <code>(mult:<var>m1</var> (sign_extend:<var>m1</var> (ashiftrt:<var>m2</var>
  188. <var>x</var> <var>s</var>)) (sign_extend:<var>m1</var> <var>y</var>))</code>, and likewise for
  189. patterns using <code>zero_extend</code> and <code>lshiftrt</code>. If the second
  190. operand of <code>mult</code> is also a shift, then that is extended also.
  191. This transformation is only applied when it can be proven that the
  192. original operation had sufficient precision to prevent overflow.
  193. </li></ul>
  194. <p>Further canonicalization rules are defined in the function
  195. <code>commutative_operand_precedence</code> in <samp>gcc/rtlanal.c</samp>.
  196. </p>
  197. <hr>
  198. <div class="header">
  199. <p>
  200. Next: <a href="Expander-Definitions.html#Expander-Definitions" accesskey="n" rel="next">Expander Definitions</a>, Previous: <a href="Looping-Patterns.html#Looping-Patterns" accesskey="p" rel="prev">Looping Patterns</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  201. </div>
  202. </body>
  203. </html>