OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.7 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../uclibc/pkg_patch/gcc/904-flatten-switch-stmt-00.patch
  5. # Copyright (C) 2009 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. Hi,
  17. The attached patch makes sure that we create smaller object code for
  18. simple switch statements. We just make sure to flatten the switch
  19. statement into an if-else chain, basically.
  20. This fixes a size-regression as compared to gcc-3.4, as can be seen
  21. below.
  22. 2007-04-15 Bernhard Fischer <..>
  23. * stmt.c (expand_case): Do not create a complex binary tree when
  24. optimizing for size but rather use the simple ordered list.
  25. (emit_case_nodes): do not emit jumps to the default_label when
  26. optimizing for size.
  27. Not regtested so far.
  28. Comments?
  29. Attached is the test switch.c mentioned below.
  30. $ for i in 2.95 3.3 3.4 4.0 4.1 4.2.orig-HEAD 4.3.orig-HEAD 4.3-HEAD;do
  31. gcc-$i -DCHAIN -Os -o switch-CHAIN-$i.o -c switch.c ;done
  32. $ for i in 2.95 3.3 3.4 4.0 4.1 4.2.orig-HEAD 4.3.orig-HEAD 4.3-HEAD;do
  33. gcc-$i -UCHAIN -Os -o switch-$i.o -c switch.c ;done
  34. $ size switch-*.o
  35. text data bss dec hex filename
  36. 169 0 0 169 a9 switch-2.95.o
  37. 115 0 0 115 73 switch-3.3.o
  38. 103 0 0 103 67 switch-3.4.o
  39. 124 0 0 124 7c switch-4.0.o
  40. 124 0 0 124 7c switch-4.1.o
  41. 124 0 0 124 7c switch-4.2.orig-HEAD.o
  42. 95 0 0 95 5f switch-4.3-HEAD.o
  43. 124 0 0 124 7c switch-4.3.orig-HEAD.o
  44. 166 0 0 166 a6 switch-CHAIN-2.95.o
  45. 111 0 0 111 6f switch-CHAIN-3.3.o
  46. 95 0 0 95 5f switch-CHAIN-3.4.o
  47. 95 0 0 95 5f switch-CHAIN-4.0.o
  48. 95 0 0 95 5f switch-CHAIN-4.1.o
  49. 95 0 0 95 5f switch-CHAIN-4.2.orig-HEAD.o
  50. 95 0 0 95 5f switch-CHAIN-4.3-HEAD.o
  51. 95 0 0 95 5f switch-CHAIN-4.3.orig-HEAD.o
  52. Content-Type: text/x-diff; charset=us-ascii
  53. Content-Disposition: attachment; filename="gcc-4.3.gcc-flatten-switch-stmt.00.diff"
  54. Index: gcc-4.2.0/gcc/stmt.c
  55. ===================================================================
  56. --- gcc-4.2.0.orig/gcc/stmt.c (revision 123843)
  57. +++ gcc-4.2.0/gcc/stmt.c (working copy)
  58. @@ -2517,7 +2517,11 @@ expand_case (tree exp)
  59. use_cost_table
  60. = (TREE_CODE (orig_type) != ENUMERAL_TYPE
  61. && estimate_case_costs (case_list));
  62. - balance_case_nodes (&case_list, NULL);
  63. + /* When optimizing for size, we want a straight list to avoid
  64. + jumps as much as possible. This basically creates an if-else
  65. + chain. */
  66. + if (!optimize_size)
  67. + balance_case_nodes (&case_list, NULL);
  68. emit_case_nodes (index, case_list, default_label, index_type);
  69. emit_jump (default_label);
  70. }
  71. @@ -3075,6 +3079,7 @@ emit_case_nodes (rtx index, case_node_pt
  72. {
  73. if (!node_has_low_bound (node, index_type))
  74. {
  75. + if (!optimize_size) /* don't jl to the .default_label. */
  76. emit_cmp_and_jump_insns (index,
  77. convert_modes
  78. (mode, imode,
  79. Content-Type: text/x-csrc; charset=us-ascii
  80. Content-Disposition: attachment; filename="switch.c"
  81. int
  82. commutative_tree_code (int code)
  83. {
  84. #define CASE(val, ret) case val:/* __asm__("# val="#val ",ret="#ret);*/ return ret;
  85. #ifndef CHAIN
  86. switch (code)
  87. {
  88. # if 1
  89. CASE(1,3)
  90. CASE(3,2)
  91. CASE(5,8)
  92. CASE(7,1)
  93. CASE(33,4)
  94. CASE(44,9)
  95. CASE(55,10)
  96. CASE(66,-1)
  97. CASE(77,99)
  98. CASE(666,0)
  99. # else
  100. case 1:
  101. return 3;
  102. case 3:
  103. return 2;
  104. case 5:
  105. return 8;
  106. case 7:
  107. return 1;
  108. case 33:
  109. return 4;
  110. case 44:
  111. return 9;
  112. case 55:
  113. return 10;
  114. case 66:
  115. return -1;
  116. case 77:
  117. return 99;
  118. case 666:
  119. return 0;
  120. # endif
  121. default:
  122. break;
  123. }
  124. return 4711;
  125. #else
  126. if (code == 1)
  127. return 3;
  128. else if (code == 3)
  129. return 2;
  130. else if (code == 5)
  131. return 8;
  132. else if (code == 7)
  133. return 1;
  134. else if (code == 33)
  135. return 4;
  136. else if (code == 44)
  137. return 9;
  138. else if (code == 55)
  139. return 10;
  140. else if (code == 66)
  141. return -1;
  142. else if (code == 77)
  143. return 99;
  144. else if (code == 666)
  145. return 0;
  146. else
  147. return 4711;
  148. #endif
  149. }
  150. --AhhlLboLdkugWU4S--