Merge lp:~ams-codesourcery/gcc-linaro/widening-multiplies-4.6 into lp:gcc-linaro/4.6
- widening-multiplies-4.6
- Merge into 4.6
Status: | Superseded |
---|---|
Proposed branch: | lp:~ams-codesourcery/gcc-linaro/widening-multiplies-4.6 |
Merge into: | lp:gcc-linaro/4.6 |
Diff against target: |
1157 lines (+645/-134) (has conflicts) 17 files modified
ChangeLog.linaro (+105/-0) gcc/config/arm/arm.md (+1/-1) gcc/expr.c (+14/-15) gcc/genopinit.c (+24/-20) gcc/optabs.c (+56/-15) gcc/optabs.h (+52/-0) gcc/testsuite/gcc.target/arm/no-wmla-1.c (+11/-0) gcc/testsuite/gcc.target/arm/wmul-10.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-5.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-6.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-7.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-8.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-9.c (+10/-0) gcc/testsuite/gcc.target/arm/wmul-bitfield-1.c (+17/-0) gcc/testsuite/gcc.target/arm/wmul-bitfield-2.c (+17/-0) gcc/tree-cfg.c (+2/-2) gcc/tree-ssa-math-opts.c (+286/-81) Text conflict in ChangeLog.linaro |
To merge this branch: | bzr merge lp:~ams-codesourcery/gcc-linaro/widening-multiplies-4.6 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Hope | Needs Fixing | ||
Review via email: mp+68349@code.launchpad.net |
This proposal supersedes a proposal from 2011-07-15.
This proposal has been superseded by a proposal from 2011-07-22.
Commit message
Description of the change
Widening multiplies optimizations.
The first commit is not approved yet, but the rest are reviewed upstream, and read to commit.
http://<email address hidden>
UPDATE: Now with an extra bug-fix.
Linaro Toolchain Builder (cbuild) wrote : Posted in a previous version of this proposal | # |
Michael Hope (michaelh1) wrote : Posted in a previous version of this proposal | # |
cbuild had trouble building this on <proposals.Build instance at 0x2b85680>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: armv7l-
Michael Hope (michaelh1) wrote : Posted in a previous version of this proposal | # |
cbuild had trouble building this on <proposals.Build instance at 0x2141ea8>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: armv7l-
Michael Hope (michaelh1) wrote : Posted in a previous version of this proposal | # |
cbuild had trouble building this on <proposals.Build instance at 0x7fe8f501a050>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: i686-natty-
Michael Hope (michaelh1) wrote : Posted in a previous version of this proposal | # |
cbuild had trouble building this on <proposals.Build instance at 0x7fe8f5028ab8>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: x86_64-
Linaro Toolchain Builder (cbuild) wrote : | # |
cbuild has taken a snapshot of this branch at r106782 and queued it for build.
The snapshot is available at:
http://
and will be built on the following builders:
a9-builder armv5-builder i686 x86_64
You can track the build queue at:
http://
cbuild-snapshot: gcc-linaro-
cbuild-ancestor: lp:gcc-linaro/4.6+bzr106774
cbuild-state: check
Michael Hope (michaelh1) wrote : | # |
cbuild had trouble building this on <proposals.Build instance at 0x3fec710>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: i686-natty-
Michael Hope (michaelh1) wrote : | # |
cbuild had trouble building this on <proposals.Build instance at 0x2b08c68>.
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: x86_64-
Michael Hope (michaelh1) wrote : | # |
cbuild had trouble building this on armv7l-
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: armv7l-
Michael Hope (michaelh1) wrote : | # |
cbuild had trouble building this on armv7l-
See the *failed.txt logs under the build results at:
http://
The test suite results were not checked.
cbuild-checked: armv7l-
Preview Diff
1 | === modified file 'ChangeLog.linaro' | |||
2 | --- ChangeLog.linaro 2011-07-18 14:47:22 +0000 | |||
3 | +++ ChangeLog.linaro 2011-07-19 09:04:38 +0000 | |||
4 | @@ -1,3 +1,4 @@ | |||
5 | 1 | <<<<<<< TREE | ||
6 | 1 | 2011-07-18 Andrew Stubbs <ams@codesourcery.com> | 2 | 2011-07-18 Andrew Stubbs <ams@codesourcery.com> |
7 | 2 | 3 | ||
8 | 3 | gcc/ | 4 | gcc/ |
9 | @@ -83,6 +84,110 @@ | |||
10 | 83 | 84 | ||
11 | 84 | * gcc.c-torture/compile/20110401-1.c: New test. | 85 | * gcc.c-torture/compile/20110401-1.c: New test. |
12 | 85 | 86 | ||
13 | 87 | ======= | ||
14 | 88 | 2011-07-15 Andrew Stubbs <ams@codesourcery.com> | ||
15 | 89 | |||
16 | 90 | Backport from patches proposed for 4.7: | ||
17 | 91 | |||
18 | 92 | 2011-06-24 Andrew Stubbs <ams@codesourcery.com> | ||
19 | 93 | |||
20 | 94 | gcc/ | ||
21 | 95 | * tree-ssa-math-opts.c (convert_mult_to_widen): Better handle | ||
22 | 96 | unsigned inputs of different modes. | ||
23 | 97 | (convert_plusminus_to_widen): Likewise. | ||
24 | 98 | |||
25 | 99 | gcc/testsuite/ | ||
26 | 100 | * gcc.target/arm/wmul-9.c: New file. | ||
27 | 101 | * gcc.target/arm/wmul-bitfield-2.c: New file. | ||
28 | 102 | |||
29 | 103 | 2011-07-14 Andrew Stubbs <ams@codesourcery.com> | ||
30 | 104 | |||
31 | 105 | gcc/ | ||
32 | 106 | * tree-ssa-math-opts.c (is_widening_mult_rhs_p): Add new argument | ||
33 | 107 | 'type'. | ||
34 | 108 | Use 'type' from caller, not inferred from 'rhs'. | ||
35 | 109 | Don't reject non-conversion statements. Do return lhs in this case. | ||
36 | 110 | (is_widening_mult_p): Add new argument 'type'. | ||
37 | 111 | Use 'type' from caller, not inferred from 'stmt'. | ||
38 | 112 | Pass type to is_widening_mult_rhs_p. | ||
39 | 113 | (convert_mult_to_widen): Pass type to is_widening_mult_p. | ||
40 | 114 | (convert_plusminus_to_widen): Likewise. | ||
41 | 115 | |||
42 | 116 | gcc/testsuite/ | ||
43 | 117 | * gcc.target/arm/wmul-8.c: New file. | ||
44 | 118 | |||
45 | 119 | 2011-07-14 Andrew Stubbs <ams@codesourcery.com> | ||
46 | 120 | |||
47 | 121 | gcc/ | ||
48 | 122 | * tree-ssa-math-opts.c (is_widening_mult_p): Remove FIXME. | ||
49 | 123 | Ensure the the larger type is the first operand. | ||
50 | 124 | |||
51 | 125 | gcc/testsuite/ | ||
52 | 126 | * gcc.target/arm/wmul-7.c: New file. | ||
53 | 127 | |||
54 | 128 | 2011-07-14 Andrew Stubbs <ams@codesourcery.com> | ||
55 | 129 | |||
56 | 130 | gcc/ | ||
57 | 131 | * tree-ssa-math-opts.c (convert_mult_to_widen): Convert | ||
58 | 132 | unsupported unsigned multiplies to signed. | ||
59 | 133 | (convert_plusminus_to_widen): Likewise. | ||
60 | 134 | |||
61 | 135 | gcc/testsuite/ | ||
62 | 136 | * gcc.target/arm/wmul-6.c: New file. | ||
63 | 137 | |||
64 | 138 | 2011-07-14 Andrew Stubbs <ams@codesourcery.com> | ||
65 | 139 | |||
66 | 140 | gcc/ | ||
67 | 141 | * tree-ssa-math-opts.c (convert_plusminus_to_widen): Permit a single | ||
68 | 142 | conversion statement separating multiply-and-accumulate. | ||
69 | 143 | |||
70 | 144 | gcc/testsuite/ | ||
71 | 145 | * gcc.target/arm/wmul-5.c: New file. | ||
72 | 146 | * gcc.target/arm/no-wmla-1.c: New file. | ||
73 | 147 | |||
74 | 148 | 2011-07-14 Andrew Stubbs <ams@codesourcery.com> | ||
75 | 149 | |||
76 | 150 | gcc/ | ||
77 | 151 | * config/arm/arm.md (maddhidi4): Remove '*' from name. | ||
78 | 152 | * expr.c (expand_expr_real_2): Use find_widening_optab_handler. | ||
79 | 153 | * optabs.c (find_widening_optab_handler_and_mode): New function. | ||
80 | 154 | (expand_widen_pattern_expr): Use find_widening_optab_handler. | ||
81 | 155 | (expand_binop_directly): Likewise. | ||
82 | 156 | (expand_binop): Likewise. | ||
83 | 157 | * optabs.h (find_widening_optab_handler): New macro define. | ||
84 | 158 | (find_widening_optab_handler_and_mode): New prototype. | ||
85 | 159 | * tree-cfg.c (verify_gimple_assign_binary): Adjust WIDEN_MULT_EXPR | ||
86 | 160 | type precision rules. | ||
87 | 161 | (verify_gimple_assign_ternary): Likewise for WIDEN_MULT_PLUS_EXPR. | ||
88 | 162 | * tree-ssa-math-opts.c (build_and_insert_cast): New function. | ||
89 | 163 | (is_widening_mult_rhs_p): Allow widening by more than one mode. | ||
90 | 164 | Explicitly disallow mis-matched input types. | ||
91 | 165 | (convert_mult_to_widen): Use find_widening_optab_handler, and cast | ||
92 | 166 | input types to fit the new handler. | ||
93 | 167 | (convert_plusminus_to_widen): Likewise. | ||
94 | 168 | |||
95 | 169 | gcc/testsuite/ | ||
96 | 170 | * gcc.target/arm/wmul-bitfield-1.c: New file. | ||
97 | 171 | |||
98 | 172 | |||
99 | 173 | 2011-07-09 Andrew Stubbs <ams@codesourcery.com> | ||
100 | 174 | |||
101 | 175 | gcc/ | ||
102 | 176 | * expr.c (expand_expr_real_2): Use widening_optab_handler. | ||
103 | 177 | * genopinit.c (optabs): Use set_widening_optab_handler for $N. | ||
104 | 178 | (gen_insn): $N now means $a must be wider than $b, not consecutive. | ||
105 | 179 | * optabs.c (expand_widen_pattern_expr): Use widening_optab_handler. | ||
106 | 180 | (expand_binop_directly): Likewise. | ||
107 | 181 | (expand_binop): Likewise. | ||
108 | 182 | * optabs.h (widening_optab_handlers): New struct. | ||
109 | 183 | (optab_d): New member, 'widening'. | ||
110 | 184 | (widening_optab_handler): New function. | ||
111 | 185 | (set_widening_optab_handler): New function. | ||
112 | 186 | * tree-ssa-math-opts.c (convert_mult_to_widen): Use | ||
113 | 187 | widening_optab_handler. | ||
114 | 188 | (convert_plusminus_to_widen): Likewise. | ||
115 | 189 | |||
116 | 190 | >>>>>>> MERGE-SOURCE | ||
117 | 86 | 2011-07-13 Richard Sandiford <richard.sandiford@linaro.org> | 191 | 2011-07-13 Richard Sandiford <richard.sandiford@linaro.org> |
118 | 87 | 192 | ||
119 | 88 | Backport from mainline: | 193 | Backport from mainline: |
120 | 89 | 194 | ||
121 | === modified file 'gcc/config/arm/arm.md' | |||
122 | --- gcc/config/arm/arm.md 2011-06-28 12:02:27 +0000 | |||
123 | +++ gcc/config/arm/arm.md 2011-07-19 09:04:38 +0000 | |||
124 | @@ -1839,7 +1839,7 @@ | |||
125 | 1839 | (set_attr "predicable" "yes")] | 1839 | (set_attr "predicable" "yes")] |
126 | 1840 | ) | 1840 | ) |
127 | 1841 | 1841 | ||
129 | 1842 | (define_insn "*maddhidi4" | 1842 | (define_insn "maddhidi4" |
130 | 1843 | [(set (match_operand:DI 0 "s_register_operand" "=r") | 1843 | [(set (match_operand:DI 0 "s_register_operand" "=r") |
131 | 1844 | (plus:DI | 1844 | (plus:DI |
132 | 1845 | (mult:DI (sign_extend:DI | 1845 | (mult:DI (sign_extend:DI |
133 | 1846 | 1846 | ||
134 | === modified file 'gcc/expr.c' | |||
135 | --- gcc/expr.c 2011-06-02 12:12:00 +0000 | |||
136 | +++ gcc/expr.c 2011-07-19 09:04:38 +0000 | |||
137 | @@ -7658,18 +7658,16 @@ | |||
138 | 7658 | { | 7658 | { |
139 | 7659 | enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0)); | 7659 | enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0)); |
140 | 7660 | this_optab = usmul_widen_optab; | 7660 | this_optab = usmul_widen_optab; |
142 | 7661 | if (mode == GET_MODE_2XWIDER_MODE (innermode)) | 7661 | if (find_widening_optab_handler (this_optab, mode, innermode, 0) |
143 | 7662 | != CODE_FOR_nothing) | ||
144 | 7662 | { | 7663 | { |
155 | 7663 | if (optab_handler (this_optab, mode) != CODE_FOR_nothing) | 7664 | if (TYPE_UNSIGNED (TREE_TYPE (treeop0))) |
156 | 7664 | { | 7665 | expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, |
157 | 7665 | if (TYPE_UNSIGNED (TREE_TYPE (treeop0))) | 7666 | EXPAND_NORMAL); |
158 | 7666 | expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, | 7667 | else |
159 | 7667 | EXPAND_NORMAL); | 7668 | expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0, |
160 | 7668 | else | 7669 | EXPAND_NORMAL); |
161 | 7669 | expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0, | 7670 | goto binop3; |
152 | 7670 | EXPAND_NORMAL); | ||
153 | 7671 | goto binop3; | ||
154 | 7672 | } | ||
162 | 7673 | } | 7671 | } |
163 | 7674 | } | 7672 | } |
164 | 7675 | /* Check for a multiplication with matching signedness. */ | 7673 | /* Check for a multiplication with matching signedness. */ |
165 | @@ -7684,10 +7682,10 @@ | |||
166 | 7684 | optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab; | 7682 | optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab; |
167 | 7685 | this_optab = zextend_p ? umul_widen_optab : smul_widen_optab; | 7683 | this_optab = zextend_p ? umul_widen_optab : smul_widen_optab; |
168 | 7686 | 7684 | ||
171 | 7687 | if (mode == GET_MODE_2XWIDER_MODE (innermode) | 7685 | if (TREE_CODE (treeop0) != INTEGER_CST) |
170 | 7688 | && TREE_CODE (treeop0) != INTEGER_CST) | ||
172 | 7689 | { | 7686 | { |
174 | 7690 | if (optab_handler (this_optab, mode) != CODE_FOR_nothing) | 7687 | if (find_widening_optab_handler (this_optab, mode, innermode, 0) |
175 | 7688 | != CODE_FOR_nothing) | ||
176 | 7691 | { | 7689 | { |
177 | 7692 | expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, | 7690 | expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, |
178 | 7693 | EXPAND_NORMAL); | 7691 | EXPAND_NORMAL); |
179 | @@ -7695,7 +7693,8 @@ | |||
180 | 7695 | unsignedp, this_optab); | 7693 | unsignedp, this_optab); |
181 | 7696 | return REDUCE_BIT_FIELD (temp); | 7694 | return REDUCE_BIT_FIELD (temp); |
182 | 7697 | } | 7695 | } |
184 | 7698 | if (optab_handler (other_optab, mode) != CODE_FOR_nothing | 7696 | if (find_widening_optab_handler (other_optab, mode, innermode, 0) |
185 | 7697 | != CODE_FOR_nothing | ||
186 | 7699 | && innermode == word_mode) | 7698 | && innermode == word_mode) |
187 | 7700 | { | 7699 | { |
188 | 7701 | rtx htem, hipart; | 7700 | rtx htem, hipart; |
189 | 7702 | 7701 | ||
190 | === modified file 'gcc/genopinit.c' | |||
191 | --- gcc/genopinit.c 2011-05-05 15:43:06 +0000 | |||
192 | +++ gcc/genopinit.c 2011-07-19 09:04:38 +0000 | |||
193 | @@ -46,10 +46,12 @@ | |||
194 | 46 | used. $A and $B are replaced with the full name of the mode; $a and $b | 46 | used. $A and $B are replaced with the full name of the mode; $a and $b |
195 | 47 | are replaced with the short form of the name, as above. | 47 | are replaced with the short form of the name, as above. |
196 | 48 | 48 | ||
201 | 49 | If $N is present in the pattern, it means the two modes must be consecutive | 49 | If $N is present in the pattern, it means the two modes must be in |
202 | 50 | widths in the same mode class (e.g, QImode and HImode). $I means that | 50 | the same mode class, and $b must be greater than $a (e.g, QImode |
203 | 51 | only full integer modes should be considered for the next mode, and $F | 51 | and HImode). |
204 | 52 | means that only float modes should be considered. | 52 | |
205 | 53 | $I means that only full integer modes should be considered for the | ||
206 | 54 | next mode, and $F means that only float modes should be considered. | ||
207 | 53 | $P means that both full and partial integer modes should be considered. | 55 | $P means that both full and partial integer modes should be considered. |
208 | 54 | $Q means that only fixed-point modes should be considered. | 56 | $Q means that only fixed-point modes should be considered. |
209 | 55 | 57 | ||
210 | @@ -99,17 +101,17 @@ | |||
211 | 99 | "set_optab_handler (smulv_optab, $A, CODE_FOR_$(mulv$I$a3$))", | 101 | "set_optab_handler (smulv_optab, $A, CODE_FOR_$(mulv$I$a3$))", |
212 | 100 | "set_optab_handler (umul_highpart_optab, $A, CODE_FOR_$(umul$a3_highpart$))", | 102 | "set_optab_handler (umul_highpart_optab, $A, CODE_FOR_$(umul$a3_highpart$))", |
213 | 101 | "set_optab_handler (smul_highpart_optab, $A, CODE_FOR_$(smul$a3_highpart$))", | 103 | "set_optab_handler (smul_highpart_optab, $A, CODE_FOR_$(smul$a3_highpart$))", |
225 | 102 | "set_optab_handler (smul_widen_optab, $B, CODE_FOR_$(mul$a$b3$)$N)", | 104 | "set_widening_optab_handler (smul_widen_optab, $B, $A, CODE_FOR_$(mul$a$b3$)$N)", |
226 | 103 | "set_optab_handler (umul_widen_optab, $B, CODE_FOR_$(umul$a$b3$)$N)", | 105 | "set_widening_optab_handler (umul_widen_optab, $B, $A, CODE_FOR_$(umul$a$b3$)$N)", |
227 | 104 | "set_optab_handler (usmul_widen_optab, $B, CODE_FOR_$(usmul$a$b3$)$N)", | 106 | "set_widening_optab_handler (usmul_widen_optab, $B, $A, CODE_FOR_$(usmul$a$b3$)$N)", |
228 | 105 | "set_optab_handler (smadd_widen_optab, $B, CODE_FOR_$(madd$a$b4$)$N)", | 107 | "set_widening_optab_handler (smadd_widen_optab, $B, $A, CODE_FOR_$(madd$a$b4$)$N)", |
229 | 106 | "set_optab_handler (umadd_widen_optab, $B, CODE_FOR_$(umadd$a$b4$)$N)", | 108 | "set_widening_optab_handler (umadd_widen_optab, $B, $A, CODE_FOR_$(umadd$a$b4$)$N)", |
230 | 107 | "set_optab_handler (ssmadd_widen_optab, $B, CODE_FOR_$(ssmadd$a$b4$)$N)", | 109 | "set_widening_optab_handler (ssmadd_widen_optab, $B, $A, CODE_FOR_$(ssmadd$a$b4$)$N)", |
231 | 108 | "set_optab_handler (usmadd_widen_optab, $B, CODE_FOR_$(usmadd$a$b4$)$N)", | 110 | "set_widening_optab_handler (usmadd_widen_optab, $B, $A, CODE_FOR_$(usmadd$a$b4$)$N)", |
232 | 109 | "set_optab_handler (smsub_widen_optab, $B, CODE_FOR_$(msub$a$b4$)$N)", | 111 | "set_widening_optab_handler (smsub_widen_optab, $B, $A, CODE_FOR_$(msub$a$b4$)$N)", |
233 | 110 | "set_optab_handler (umsub_widen_optab, $B, CODE_FOR_$(umsub$a$b4$)$N)", | 112 | "set_widening_optab_handler (umsub_widen_optab, $B, $A, CODE_FOR_$(umsub$a$b4$)$N)", |
234 | 111 | "set_optab_handler (ssmsub_widen_optab, $B, CODE_FOR_$(ssmsub$a$b4$)$N)", | 113 | "set_widening_optab_handler (ssmsub_widen_optab, $B, $A, CODE_FOR_$(ssmsub$a$b4$)$N)", |
235 | 112 | "set_optab_handler (usmsub_widen_optab, $B, CODE_FOR_$(usmsub$a$b4$)$N)", | 114 | "set_widening_optab_handler (usmsub_widen_optab, $B, $A, CODE_FOR_$(usmsub$a$b4$)$N)", |
236 | 113 | "set_optab_handler (sdiv_optab, $A, CODE_FOR_$(div$a3$))", | 115 | "set_optab_handler (sdiv_optab, $A, CODE_FOR_$(div$a3$))", |
237 | 114 | "set_optab_handler (ssdiv_optab, $A, CODE_FOR_$(ssdiv$Q$a3$))", | 116 | "set_optab_handler (ssdiv_optab, $A, CODE_FOR_$(ssdiv$Q$a3$))", |
238 | 115 | "set_optab_handler (sdivv_optab, $A, CODE_FOR_$(div$V$I$a3$))", | 117 | "set_optab_handler (sdivv_optab, $A, CODE_FOR_$(div$V$I$a3$))", |
239 | @@ -304,7 +306,7 @@ | |||
240 | 304 | { | 306 | { |
241 | 305 | int force_float = 0, force_int = 0, force_partial_int = 0; | 307 | int force_float = 0, force_int = 0, force_partial_int = 0; |
242 | 306 | int force_fixed = 0; | 308 | int force_fixed = 0; |
244 | 307 | int force_consec = 0; | 309 | int force_wider = 0; |
245 | 308 | int matches = 1; | 310 | int matches = 1; |
246 | 309 | 311 | ||
247 | 310 | for (pp = optabs[pindex]; pp[0] != '$' || pp[1] != '('; pp++) | 312 | for (pp = optabs[pindex]; pp[0] != '$' || pp[1] != '('; pp++) |
248 | @@ -322,7 +324,7 @@ | |||
249 | 322 | switch (*++pp) | 324 | switch (*++pp) |
250 | 323 | { | 325 | { |
251 | 324 | case 'N': | 326 | case 'N': |
253 | 325 | force_consec = 1; | 327 | force_wider = 1; |
254 | 326 | break; | 328 | break; |
255 | 327 | case 'I': | 329 | case 'I': |
256 | 328 | force_int = 1; | 330 | force_int = 1; |
257 | @@ -391,7 +393,10 @@ | |||
258 | 391 | || mode_class[i] == MODE_VECTOR_FRACT | 393 | || mode_class[i] == MODE_VECTOR_FRACT |
259 | 392 | || mode_class[i] == MODE_VECTOR_UFRACT | 394 | || mode_class[i] == MODE_VECTOR_UFRACT |
260 | 393 | || mode_class[i] == MODE_VECTOR_ACCUM | 395 | || mode_class[i] == MODE_VECTOR_ACCUM |
262 | 394 | || mode_class[i] == MODE_VECTOR_UACCUM)) | 396 | || mode_class[i] == MODE_VECTOR_UACCUM) |
263 | 397 | && (! force_wider | ||
264 | 398 | || *pp == 'a' | ||
265 | 399 | || m1 < i)) | ||
266 | 395 | break; | 400 | break; |
267 | 396 | } | 401 | } |
268 | 397 | 402 | ||
269 | @@ -411,8 +416,7 @@ | |||
270 | 411 | } | 416 | } |
271 | 412 | 417 | ||
272 | 413 | if (matches && pp[0] == '$' && pp[1] == ')' | 418 | if (matches && pp[0] == '$' && pp[1] == ')' |
275 | 414 | && *np == 0 | 419 | && *np == 0) |
274 | 415 | && (! force_consec || (int) GET_MODE_WIDER_MODE(m1) == m2)) | ||
276 | 416 | break; | 420 | break; |
277 | 417 | } | 421 | } |
278 | 418 | 422 | ||
279 | 419 | 423 | ||
280 | === modified file 'gcc/optabs.c' | |||
281 | --- gcc/optabs.c 2011-07-04 14:03:49 +0000 | |||
282 | +++ gcc/optabs.c 2011-07-19 09:04:38 +0000 | |||
283 | @@ -225,6 +225,37 @@ | |||
284 | 225 | return 1; | 225 | return 1; |
285 | 226 | } | 226 | } |
286 | 227 | 227 | ||
287 | 228 | 228 | ||
288 | 229 | /* Find a widening optab even if it doesn't widen as much as we want. | ||
289 | 230 | E.g. if from_mode is HImode, and to_mode is DImode, and there is no | ||
290 | 231 | direct HI->SI insn, then return SI->DI, if that exists. | ||
291 | 232 | If PERMIT_NON_WIDENING is non-zero then this can be used with | ||
292 | 233 | non-widening optabs also. */ | ||
293 | 234 | |||
294 | 235 | enum insn_code | ||
295 | 236 | find_widening_optab_handler_and_mode (optab op, enum machine_mode to_mode, | ||
296 | 237 | enum machine_mode from_mode, | ||
297 | 238 | int permit_non_widening, | ||
298 | 239 | enum machine_mode *found_mode) | ||
299 | 240 | { | ||
300 | 241 | for (; (permit_non_widening || from_mode != to_mode) | ||
301 | 242 | && GET_MODE_SIZE (from_mode) <= GET_MODE_SIZE (to_mode) | ||
302 | 243 | && from_mode != VOIDmode; | ||
303 | 244 | from_mode = GET_MODE_WIDER_MODE (from_mode)) | ||
304 | 245 | { | ||
305 | 246 | enum insn_code handler = widening_optab_handler (op, to_mode, | ||
306 | 247 | from_mode); | ||
307 | 248 | |||
308 | 249 | if (handler != CODE_FOR_nothing) | ||
309 | 250 | { | ||
310 | 251 | if (found_mode) | ||
311 | 252 | *found_mode = from_mode; | ||
312 | 253 | return handler; | ||
313 | 254 | } | ||
314 | 255 | } | ||
315 | 256 | |||
316 | 257 | return CODE_FOR_nothing; | ||
317 | 258 | } | ||
318 | 259 | |||
319 | 229 | 260 | ||
320 | 230 | /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP | 261 | /* Widen OP to MODE and return the rtx for the widened operand. UNSIGNEDP |
321 | 231 | says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need | 262 | says whether OP is signed or unsigned. NO_EXTEND is nonzero if we need |
322 | 232 | not actually do a sign-extend or zero-extend, but can leave the | 263 | not actually do a sign-extend or zero-extend, but can leave the |
323 | @@ -517,8 +548,9 @@ | |||
324 | 517 | optab_for_tree_code (ops->code, TREE_TYPE (oprnd0), optab_default); | 548 | optab_for_tree_code (ops->code, TREE_TYPE (oprnd0), optab_default); |
325 | 518 | if (ops->code == WIDEN_MULT_PLUS_EXPR | 549 | if (ops->code == WIDEN_MULT_PLUS_EXPR |
326 | 519 | || ops->code == WIDEN_MULT_MINUS_EXPR) | 550 | || ops->code == WIDEN_MULT_MINUS_EXPR) |
329 | 520 | icode = (int) optab_handler (widen_pattern_optab, | 551 | icode = (int) find_widening_optab_handler (widen_pattern_optab, |
330 | 521 | TYPE_MODE (TREE_TYPE (ops->op2))); | 552 | TYPE_MODE (TREE_TYPE (ops->op2)), |
331 | 553 | tmode0, 0); | ||
332 | 522 | else | 554 | else |
333 | 523 | icode = (int) optab_handler (widen_pattern_optab, tmode0); | 555 | icode = (int) optab_handler (widen_pattern_optab, tmode0); |
334 | 524 | gcc_assert (icode != CODE_FOR_nothing); | 556 | gcc_assert (icode != CODE_FOR_nothing); |
335 | @@ -1389,7 +1421,9 @@ | |||
336 | 1389 | rtx target, int unsignedp, enum optab_methods methods, | 1421 | rtx target, int unsignedp, enum optab_methods methods, |
337 | 1390 | rtx last) | 1422 | rtx last) |
338 | 1391 | { | 1423 | { |
340 | 1392 | int icode = (int) optab_handler (binoptab, mode); | 1424 | enum machine_mode from_mode = GET_MODE (op0); |
341 | 1425 | int icode = (int) find_widening_optab_handler (binoptab, mode, | ||
342 | 1426 | from_mode, 1); | ||
343 | 1393 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | 1427 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; |
344 | 1394 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | 1428 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; |
345 | 1395 | enum machine_mode tmp_mode; | 1429 | enum machine_mode tmp_mode; |
346 | @@ -1546,7 +1580,8 @@ | |||
347 | 1546 | /* If we can do it with a three-operand insn, do so. */ | 1580 | /* If we can do it with a three-operand insn, do so. */ |
348 | 1547 | 1581 | ||
349 | 1548 | if (methods != OPTAB_MUST_WIDEN | 1582 | if (methods != OPTAB_MUST_WIDEN |
351 | 1549 | && optab_handler (binoptab, mode) != CODE_FOR_nothing) | 1583 | && find_widening_optab_handler (binoptab, mode, GET_MODE (op0), 1) |
352 | 1584 | != CODE_FOR_nothing) | ||
353 | 1550 | { | 1585 | { |
354 | 1551 | temp = expand_binop_directly (mode, binoptab, op0, op1, target, | 1586 | temp = expand_binop_directly (mode, binoptab, op0, op1, target, |
355 | 1552 | unsignedp, methods, last); | 1587 | unsignedp, methods, last); |
356 | @@ -1585,9 +1620,10 @@ | |||
357 | 1585 | takes operands of this mode and makes a wider mode. */ | 1620 | takes operands of this mode and makes a wider mode. */ |
358 | 1586 | 1621 | ||
359 | 1587 | if (binoptab == smul_optab | 1622 | if (binoptab == smul_optab |
363 | 1588 | && GET_MODE_WIDER_MODE (mode) != VOIDmode | 1623 | && GET_MODE_2XWIDER_MODE (mode) != VOIDmode |
364 | 1589 | && (optab_handler ((unsignedp ? umul_widen_optab : smul_widen_optab), | 1624 | && (widening_optab_handler ((unsignedp ? umul_widen_optab |
365 | 1590 | GET_MODE_WIDER_MODE (mode)) | 1625 | : smul_widen_optab), |
366 | 1626 | GET_MODE_2XWIDER_MODE (mode), mode) | ||
367 | 1591 | != CODE_FOR_nothing)) | 1627 | != CODE_FOR_nothing)) |
368 | 1592 | { | 1628 | { |
369 | 1593 | temp = expand_binop (GET_MODE_WIDER_MODE (mode), | 1629 | temp = expand_binop (GET_MODE_WIDER_MODE (mode), |
370 | @@ -1615,12 +1651,15 @@ | |||
371 | 1615 | wider_mode != VOIDmode; | 1651 | wider_mode != VOIDmode; |
372 | 1616 | wider_mode = GET_MODE_WIDER_MODE (wider_mode)) | 1652 | wider_mode = GET_MODE_WIDER_MODE (wider_mode)) |
373 | 1617 | { | 1653 | { |
375 | 1618 | if (optab_handler (binoptab, wider_mode) != CODE_FOR_nothing | 1654 | if (optab_handler (binoptab, wider_mode) |
376 | 1655 | != CODE_FOR_nothing | ||
377 | 1619 | || (binoptab == smul_optab | 1656 | || (binoptab == smul_optab |
378 | 1620 | && GET_MODE_WIDER_MODE (wider_mode) != VOIDmode | 1657 | && GET_MODE_WIDER_MODE (wider_mode) != VOIDmode |
382 | 1621 | && (optab_handler ((unsignedp ? umul_widen_optab | 1658 | && (find_widening_optab_handler ((unsignedp |
383 | 1622 | : smul_widen_optab), | 1659 | ? umul_widen_optab |
384 | 1623 | GET_MODE_WIDER_MODE (wider_mode)) | 1660 | : smul_widen_optab), |
385 | 1661 | GET_MODE_WIDER_MODE (wider_mode), | ||
386 | 1662 | mode, 0) | ||
387 | 1624 | != CODE_FOR_nothing))) | 1663 | != CODE_FOR_nothing))) |
388 | 1625 | { | 1664 | { |
389 | 1626 | rtx xop0 = op0, xop1 = op1; | 1665 | rtx xop0 = op0, xop1 = op1; |
390 | @@ -2043,8 +2082,8 @@ | |||
391 | 2043 | && optab_handler (add_optab, word_mode) != CODE_FOR_nothing) | 2082 | && optab_handler (add_optab, word_mode) != CODE_FOR_nothing) |
392 | 2044 | { | 2083 | { |
393 | 2045 | rtx product = NULL_RTX; | 2084 | rtx product = NULL_RTX; |
396 | 2046 | 2085 | if (widening_optab_handler (umul_widen_optab, mode, word_mode) | |
397 | 2047 | if (optab_handler (umul_widen_optab, mode) != CODE_FOR_nothing) | 2086 | != CODE_FOR_nothing) |
398 | 2048 | { | 2087 | { |
399 | 2049 | product = expand_doubleword_mult (mode, op0, op1, target, | 2088 | product = expand_doubleword_mult (mode, op0, op1, target, |
400 | 2050 | true, methods); | 2089 | true, methods); |
401 | @@ -2053,7 +2092,8 @@ | |||
402 | 2053 | } | 2092 | } |
403 | 2054 | 2093 | ||
404 | 2055 | if (product == NULL_RTX | 2094 | if (product == NULL_RTX |
406 | 2056 | && optab_handler (smul_widen_optab, mode) != CODE_FOR_nothing) | 2095 | && widening_optab_handler (smul_widen_optab, mode, word_mode) |
407 | 2096 | != CODE_FOR_nothing) | ||
408 | 2057 | { | 2097 | { |
409 | 2058 | product = expand_doubleword_mult (mode, op0, op1, target, | 2098 | product = expand_doubleword_mult (mode, op0, op1, target, |
410 | 2059 | false, methods); | 2099 | false, methods); |
411 | @@ -2144,7 +2184,8 @@ | |||
412 | 2144 | wider_mode != VOIDmode; | 2184 | wider_mode != VOIDmode; |
413 | 2145 | wider_mode = GET_MODE_WIDER_MODE (wider_mode)) | 2185 | wider_mode = GET_MODE_WIDER_MODE (wider_mode)) |
414 | 2146 | { | 2186 | { |
416 | 2147 | if (optab_handler (binoptab, wider_mode) != CODE_FOR_nothing | 2187 | if (find_widening_optab_handler (binoptab, wider_mode, mode, 1) |
417 | 2188 | != CODE_FOR_nothing | ||
418 | 2148 | || (methods == OPTAB_LIB | 2189 | || (methods == OPTAB_LIB |
419 | 2149 | && optab_libfunc (binoptab, wider_mode))) | 2190 | && optab_libfunc (binoptab, wider_mode))) |
420 | 2150 | { | 2191 | { |
421 | 2151 | 2192 | ||
422 | === modified file 'gcc/optabs.h' | |||
423 | --- gcc/optabs.h 2011-05-05 15:43:06 +0000 | |||
424 | +++ gcc/optabs.h 2011-07-19 09:04:38 +0000 | |||
425 | @@ -42,6 +42,11 @@ | |||
426 | 42 | int insn_code; | 42 | int insn_code; |
427 | 43 | }; | 43 | }; |
428 | 44 | 44 | ||
429 | 45 | struct widening_optab_handlers | ||
430 | 46 | { | ||
431 | 47 | struct optab_handlers handlers[NUM_MACHINE_MODES][NUM_MACHINE_MODES]; | ||
432 | 48 | }; | ||
433 | 49 | |||
434 | 45 | struct optab_d | 50 | struct optab_d |
435 | 46 | { | 51 | { |
436 | 47 | enum rtx_code code; | 52 | enum rtx_code code; |
437 | @@ -50,6 +55,7 @@ | |||
438 | 50 | void (*libcall_gen)(struct optab_d *, const char *name, char suffix, | 55 | void (*libcall_gen)(struct optab_d *, const char *name, char suffix, |
439 | 51 | enum machine_mode); | 56 | enum machine_mode); |
440 | 52 | struct optab_handlers handlers[NUM_MACHINE_MODES]; | 57 | struct optab_handlers handlers[NUM_MACHINE_MODES]; |
441 | 58 | struct widening_optab_handlers *widening; | ||
442 | 53 | }; | 59 | }; |
443 | 54 | typedef struct optab_d * optab; | 60 | typedef struct optab_d * optab; |
444 | 55 | 61 | ||
445 | @@ -799,6 +805,15 @@ | |||
446 | 799 | extern void emit_unop_insn (int, rtx, rtx, enum rtx_code); | 805 | extern void emit_unop_insn (int, rtx, rtx, enum rtx_code); |
447 | 800 | extern bool maybe_emit_unop_insn (int, rtx, rtx, enum rtx_code); | 806 | extern bool maybe_emit_unop_insn (int, rtx, rtx, enum rtx_code); |
448 | 801 | 807 | ||
449 | 808 | /* Find a widening optab even if it doesn't widen as much as we want. */ | ||
450 | 809 | #define find_widening_optab_handler(A,B,C,D) \ | ||
451 | 810 | find_widening_optab_handler_and_mode (A, B, C, D, NULL) | ||
452 | 811 | extern enum insn_code find_widening_optab_handler_and_mode (optab, | ||
453 | 812 | enum machine_mode, | ||
454 | 813 | enum machine_mode, | ||
455 | 814 | int, | ||
456 | 815 | enum machine_mode *); | ||
457 | 816 | |||
458 | 802 | /* An extra flag to control optab_for_tree_code's behavior. This is needed to | 817 | /* An extra flag to control optab_for_tree_code's behavior. This is needed to |
459 | 803 | distinguish between machines with a vector shift that takes a scalar for the | 818 | distinguish between machines with a vector shift that takes a scalar for the |
460 | 804 | shift amount vs. machines that take a vector for the shift amount. */ | 819 | shift amount vs. machines that take a vector for the shift amount. */ |
461 | @@ -874,6 +889,23 @@ | |||
462 | 874 | + (int) CODE_FOR_nothing); | 889 | + (int) CODE_FOR_nothing); |
463 | 875 | } | 890 | } |
464 | 876 | 891 | ||
465 | 892 | /* Like optab_handler, but for widening_operations that have a TO_MODE and | ||
466 | 893 | a FROM_MODE. */ | ||
467 | 894 | |||
468 | 895 | static inline enum insn_code | ||
469 | 896 | widening_optab_handler (optab op, enum machine_mode to_mode, | ||
470 | 897 | enum machine_mode from_mode) | ||
471 | 898 | { | ||
472 | 899 | if (to_mode == from_mode) | ||
473 | 900 | return optab_handler (op, to_mode); | ||
474 | 901 | |||
475 | 902 | if (op->widening) | ||
476 | 903 | return (enum insn_code) (op->widening->handlers[(int) to_mode][(int) from_mode].insn_code | ||
477 | 904 | + (int) CODE_FOR_nothing); | ||
478 | 905 | |||
479 | 906 | return CODE_FOR_nothing; | ||
480 | 907 | } | ||
481 | 908 | |||
482 | 877 | /* Record that insn CODE should be used to implement mode MODE of OP. */ | 909 | /* Record that insn CODE should be used to implement mode MODE of OP. */ |
483 | 878 | 910 | ||
484 | 879 | static inline void | 911 | static inline void |
485 | @@ -882,6 +914,26 @@ | |||
486 | 882 | op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing; | 914 | op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing; |
487 | 883 | } | 915 | } |
488 | 884 | 916 | ||
489 | 917 | /* Like set_optab_handler, but for widening operations that have a TO_MODE | ||
490 | 918 | and a FROM_MODE. */ | ||
491 | 919 | |||
492 | 920 | static inline void | ||
493 | 921 | set_widening_optab_handler (optab op, enum machine_mode to_mode, | ||
494 | 922 | enum machine_mode from_mode, enum insn_code code) | ||
495 | 923 | { | ||
496 | 924 | if (to_mode == from_mode) | ||
497 | 925 | set_optab_handler (op, to_mode, code); | ||
498 | 926 | else | ||
499 | 927 | { | ||
500 | 928 | if (op->widening == NULL) | ||
501 | 929 | op->widening = (struct widening_optab_handlers *) | ||
502 | 930 | xcalloc (1, sizeof (struct widening_optab_handlers)); | ||
503 | 931 | |||
504 | 932 | op->widening->handlers[(int) to_mode][(int) from_mode].insn_code | ||
505 | 933 | = (int) code - (int) CODE_FOR_nothing; | ||
506 | 934 | } | ||
507 | 935 | } | ||
508 | 936 | |||
509 | 885 | /* Return the insn used to perform conversion OP from mode FROM_MODE | 937 | /* Return the insn used to perform conversion OP from mode FROM_MODE |
510 | 886 | to mode TO_MODE; return CODE_FOR_nothing if the target does not have | 938 | to mode TO_MODE; return CODE_FOR_nothing if the target does not have |
511 | 887 | such an insn. */ | 939 | such an insn. */ |
512 | 888 | 940 | ||
513 | === added file 'gcc/testsuite/gcc.target/arm/no-wmla-1.c' | |||
514 | --- gcc/testsuite/gcc.target/arm/no-wmla-1.c 1970-01-01 00:00:00 +0000 | |||
515 | +++ gcc/testsuite/gcc.target/arm/no-wmla-1.c 2011-07-19 09:04:38 +0000 | |||
516 | @@ -0,0 +1,11 @@ | |||
517 | 1 | /* { dg-do compile } */ | ||
518 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
519 | 3 | |||
520 | 4 | int | ||
521 | 5 | foo (int a, short b, short c) | ||
522 | 6 | { | ||
523 | 7 | int bc = b * c; | ||
524 | 8 | return a + (short)bc; | ||
525 | 9 | } | ||
526 | 10 | |||
527 | 11 | /* { dg-final { scan-assembler "mul" } } */ | ||
528 | 0 | 12 | ||
529 | === added file 'gcc/testsuite/gcc.target/arm/wmul-10.c' | |||
530 | --- gcc/testsuite/gcc.target/arm/wmul-10.c 1970-01-01 00:00:00 +0000 | |||
531 | +++ gcc/testsuite/gcc.target/arm/wmul-10.c 2011-07-19 09:04:38 +0000 | |||
532 | @@ -0,0 +1,10 @@ | |||
533 | 1 | /* { dg-do compile } */ | ||
534 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
535 | 3 | |||
536 | 4 | unsigned long long | ||
537 | 5 | foo (unsigned short a, unsigned short *b, unsigned short *c) | ||
538 | 6 | { | ||
539 | 7 | return (unsigned)a + (unsigned long long)*b * (unsigned long long)*c; | ||
540 | 8 | } | ||
541 | 9 | |||
542 | 10 | /* { dg-final { scan-assembler "umlal" } } */ | ||
543 | 0 | 11 | ||
544 | === added file 'gcc/testsuite/gcc.target/arm/wmul-5.c' | |||
545 | --- gcc/testsuite/gcc.target/arm/wmul-5.c 1970-01-01 00:00:00 +0000 | |||
546 | +++ gcc/testsuite/gcc.target/arm/wmul-5.c 2011-07-19 09:04:38 +0000 | |||
547 | @@ -0,0 +1,10 @@ | |||
548 | 1 | /* { dg-do compile } */ | ||
549 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
550 | 3 | |||
551 | 4 | long long | ||
552 | 5 | foo (long long a, char *b, char *c) | ||
553 | 6 | { | ||
554 | 7 | return a + *b * *c; | ||
555 | 8 | } | ||
556 | 9 | |||
557 | 10 | /* { dg-final { scan-assembler "umlal" } } */ | ||
558 | 0 | 11 | ||
559 | === added file 'gcc/testsuite/gcc.target/arm/wmul-6.c' | |||
560 | --- gcc/testsuite/gcc.target/arm/wmul-6.c 1970-01-01 00:00:00 +0000 | |||
561 | +++ gcc/testsuite/gcc.target/arm/wmul-6.c 2011-07-19 09:04:38 +0000 | |||
562 | @@ -0,0 +1,10 @@ | |||
563 | 1 | /* { dg-do compile } */ | ||
564 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
565 | 3 | |||
566 | 4 | long long | ||
567 | 5 | foo (long long a, unsigned char *b, signed char *c) | ||
568 | 6 | { | ||
569 | 7 | return a + (long long)*b * (long long)*c; | ||
570 | 8 | } | ||
571 | 9 | |||
572 | 10 | /* { dg-final { scan-assembler "smlal" } } */ | ||
573 | 0 | 11 | ||
574 | === added file 'gcc/testsuite/gcc.target/arm/wmul-7.c' | |||
575 | --- gcc/testsuite/gcc.target/arm/wmul-7.c 1970-01-01 00:00:00 +0000 | |||
576 | +++ gcc/testsuite/gcc.target/arm/wmul-7.c 2011-07-19 09:04:38 +0000 | |||
577 | @@ -0,0 +1,10 @@ | |||
578 | 1 | /* { dg-do compile } */ | ||
579 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
580 | 3 | |||
581 | 4 | unsigned long long | ||
582 | 5 | foo (unsigned long long a, unsigned char *b, unsigned short *c) | ||
583 | 6 | { | ||
584 | 7 | return a + *b * *c; | ||
585 | 8 | } | ||
586 | 9 | |||
587 | 10 | /* { dg-final { scan-assembler "umlal" } } */ | ||
588 | 0 | 11 | ||
589 | === added file 'gcc/testsuite/gcc.target/arm/wmul-8.c' | |||
590 | --- gcc/testsuite/gcc.target/arm/wmul-8.c 1970-01-01 00:00:00 +0000 | |||
591 | +++ gcc/testsuite/gcc.target/arm/wmul-8.c 2011-07-19 09:04:38 +0000 | |||
592 | @@ -0,0 +1,10 @@ | |||
593 | 1 | /* { dg-do compile } */ | ||
594 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
595 | 3 | |||
596 | 4 | long long | ||
597 | 5 | foo (long long a, int *b, int *c) | ||
598 | 6 | { | ||
599 | 7 | return a + *b * *c; | ||
600 | 8 | } | ||
601 | 9 | |||
602 | 10 | /* { dg-final { scan-assembler "smlal" } } */ | ||
603 | 0 | 11 | ||
604 | === added file 'gcc/testsuite/gcc.target/arm/wmul-9.c' | |||
605 | --- gcc/testsuite/gcc.target/arm/wmul-9.c 1970-01-01 00:00:00 +0000 | |||
606 | +++ gcc/testsuite/gcc.target/arm/wmul-9.c 2011-07-19 09:04:38 +0000 | |||
607 | @@ -0,0 +1,10 @@ | |||
608 | 1 | /* { dg-do compile } */ | ||
609 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
610 | 3 | |||
611 | 4 | long long | ||
612 | 5 | foo (long long a, short *b, char *c) | ||
613 | 6 | { | ||
614 | 7 | return a + *b * *c; | ||
615 | 8 | } | ||
616 | 9 | |||
617 | 10 | /* { dg-final { scan-assembler "smlalbb" } } */ | ||
618 | 0 | 11 | ||
619 | === added file 'gcc/testsuite/gcc.target/arm/wmul-bitfield-1.c' | |||
620 | --- gcc/testsuite/gcc.target/arm/wmul-bitfield-1.c 1970-01-01 00:00:00 +0000 | |||
621 | +++ gcc/testsuite/gcc.target/arm/wmul-bitfield-1.c 2011-07-19 09:04:38 +0000 | |||
622 | @@ -0,0 +1,17 @@ | |||
623 | 1 | /* { dg-do compile } */ | ||
624 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
625 | 3 | |||
626 | 4 | struct bf | ||
627 | 5 | { | ||
628 | 6 | int a : 3; | ||
629 | 7 | int b : 15; | ||
630 | 8 | int c : 3; | ||
631 | 9 | }; | ||
632 | 10 | |||
633 | 11 | long long | ||
634 | 12 | foo (long long a, struct bf b, struct bf c) | ||
635 | 13 | { | ||
636 | 14 | return a + b.b * c.b; | ||
637 | 15 | } | ||
638 | 16 | |||
639 | 17 | /* { dg-final { scan-assembler "smlalbb" } } */ | ||
640 | 0 | 18 | ||
641 | === added file 'gcc/testsuite/gcc.target/arm/wmul-bitfield-2.c' | |||
642 | --- gcc/testsuite/gcc.target/arm/wmul-bitfield-2.c 1970-01-01 00:00:00 +0000 | |||
643 | +++ gcc/testsuite/gcc.target/arm/wmul-bitfield-2.c 2011-07-19 09:04:38 +0000 | |||
644 | @@ -0,0 +1,17 @@ | |||
645 | 1 | /* { dg-do compile } */ | ||
646 | 2 | /* { dg-options "-O2 -march=armv7-a" } */ | ||
647 | 3 | |||
648 | 4 | struct bf | ||
649 | 5 | { | ||
650 | 6 | int a : 3; | ||
651 | 7 | unsigned int b : 15; | ||
652 | 8 | int c : 3; | ||
653 | 9 | }; | ||
654 | 10 | |||
655 | 11 | long long | ||
656 | 12 | foo (long long a, struct bf b, struct bf c) | ||
657 | 13 | { | ||
658 | 14 | return a + b.b * c.c; | ||
659 | 15 | } | ||
660 | 16 | |||
661 | 17 | /* { dg-final { scan-assembler "smlalbb" } } */ | ||
662 | 0 | 18 | ||
663 | === modified file 'gcc/tree-cfg.c' | |||
664 | --- gcc/tree-cfg.c 2011-07-01 09:19:21 +0000 | |||
665 | +++ gcc/tree-cfg.c 2011-07-19 09:04:38 +0000 | |||
666 | @@ -3574,7 +3574,7 @@ | |||
667 | 3574 | case WIDEN_MULT_EXPR: | 3574 | case WIDEN_MULT_EXPR: |
668 | 3575 | if (TREE_CODE (lhs_type) != INTEGER_TYPE) | 3575 | if (TREE_CODE (lhs_type) != INTEGER_TYPE) |
669 | 3576 | return true; | 3576 | return true; |
671 | 3577 | return ((2 * TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (lhs_type)) | 3577 | return ((2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type)) |
672 | 3578 | || (TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type))); | 3578 | || (TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type))); |
673 | 3579 | 3579 | ||
674 | 3580 | case WIDEN_SUM_EXPR: | 3580 | case WIDEN_SUM_EXPR: |
675 | @@ -3667,7 +3667,7 @@ | |||
676 | 3667 | && !FIXED_POINT_TYPE_P (rhs1_type)) | 3667 | && !FIXED_POINT_TYPE_P (rhs1_type)) |
677 | 3668 | || !useless_type_conversion_p (rhs1_type, rhs2_type) | 3668 | || !useless_type_conversion_p (rhs1_type, rhs2_type) |
678 | 3669 | || !useless_type_conversion_p (lhs_type, rhs3_type) | 3669 | || !useless_type_conversion_p (lhs_type, rhs3_type) |
680 | 3670 | || 2 * TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (lhs_type) | 3670 | || 2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type) |
681 | 3671 | || TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type)) | 3671 | || TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type)) |
682 | 3672 | { | 3672 | { |
683 | 3673 | error ("type mismatch in widening multiply-accumulate expression"); | 3673 | error ("type mismatch in widening multiply-accumulate expression"); |
684 | 3674 | 3674 | ||
685 | === modified file 'gcc/tree-ssa-math-opts.c' | |||
686 | --- gcc/tree-ssa-math-opts.c 2011-03-11 16:36:16 +0000 | |||
687 | +++ gcc/tree-ssa-math-opts.c 2011-07-19 09:04:38 +0000 | |||
688 | @@ -1266,42 +1266,68 @@ | |||
689 | 1266 | } | 1266 | } |
690 | 1267 | }; | 1267 | }; |
691 | 1268 | 1268 | ||
693 | 1269 | /* Return true if RHS is a suitable operand for a widening multiplication. | 1269 | /* Build a gimple assignment to cast VAL to TARGET. Insert the statement |
694 | 1270 | prior to GSI's current position, and return the fresh SSA name. */ | ||
695 | 1271 | |||
696 | 1272 | static tree | ||
697 | 1273 | build_and_insert_cast (gimple_stmt_iterator *gsi, location_t loc, | ||
698 | 1274 | tree target, tree val) | ||
699 | 1275 | { | ||
700 | 1276 | tree result = make_ssa_name (target, NULL); | ||
701 | 1277 | gimple stmt = gimple_build_assign_with_ops (CONVERT_EXPR, result, val, NULL); | ||
702 | 1278 | gimple_set_location (stmt, loc); | ||
703 | 1279 | gsi_insert_before (gsi, stmt, GSI_SAME_STMT); | ||
704 | 1280 | return result; | ||
705 | 1281 | } | ||
706 | 1282 | |||
707 | 1283 | /* Return true if RHS is a suitable operand for a widening multiplication, | ||
708 | 1284 | assuming a target type of TYPE. | ||
709 | 1270 | There are two cases: | 1285 | There are two cases: |
710 | 1271 | 1286 | ||
713 | 1272 | - RHS makes some value twice as wide. Store that value in *NEW_RHS_OUT | 1287 | - RHS makes some value at least twice as wide. Store that value |
714 | 1273 | if so, and store its type in *TYPE_OUT. | 1288 | in *NEW_RHS_OUT if so, and store its type in *TYPE_OUT. |
715 | 1274 | 1289 | ||
716 | 1275 | - RHS is an integer constant. Store that value in *NEW_RHS_OUT if so, | 1290 | - RHS is an integer constant. Store that value in *NEW_RHS_OUT if so, |
717 | 1276 | but leave *TYPE_OUT untouched. */ | 1291 | but leave *TYPE_OUT untouched. */ |
718 | 1277 | 1292 | ||
719 | 1278 | static bool | 1293 | static bool |
721 | 1279 | is_widening_mult_rhs_p (tree rhs, tree *type_out, tree *new_rhs_out) | 1294 | is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out, |
722 | 1295 | tree *new_rhs_out) | ||
723 | 1280 | { | 1296 | { |
724 | 1281 | gimple stmt; | 1297 | gimple stmt; |
726 | 1282 | tree type, type1, rhs1; | 1298 | tree type1, rhs1; |
727 | 1283 | enum tree_code rhs_code; | 1299 | enum tree_code rhs_code; |
728 | 1284 | 1300 | ||
729 | 1285 | if (TREE_CODE (rhs) == SSA_NAME) | 1301 | if (TREE_CODE (rhs) == SSA_NAME) |
730 | 1286 | { | 1302 | { |
731 | 1287 | type = TREE_TYPE (rhs); | ||
732 | 1288 | stmt = SSA_NAME_DEF_STMT (rhs); | 1303 | stmt = SSA_NAME_DEF_STMT (rhs); |
733 | 1289 | if (!is_gimple_assign (stmt)) | 1304 | if (!is_gimple_assign (stmt)) |
744 | 1290 | return false; | 1305 | { |
745 | 1291 | 1306 | rhs1 = NULL; | |
746 | 1292 | rhs_code = gimple_assign_rhs_code (stmt); | 1307 | type1 = TREE_TYPE (rhs); |
747 | 1293 | if (TREE_CODE (type) == INTEGER_TYPE | 1308 | } |
748 | 1294 | ? !CONVERT_EXPR_CODE_P (rhs_code) | 1309 | else |
749 | 1295 | : rhs_code != FIXED_CONVERT_EXPR) | 1310 | { |
750 | 1296 | return false; | 1311 | rhs1 = gimple_assign_rhs1 (stmt); |
751 | 1297 | 1312 | type1 = TREE_TYPE (rhs1); | |
752 | 1298 | rhs1 = gimple_assign_rhs1 (stmt); | 1313 | } |
753 | 1299 | type1 = TREE_TYPE (rhs1); | 1314 | |
754 | 1300 | if (TREE_CODE (type1) != TREE_CODE (type) | 1315 | if (TREE_CODE (type1) != TREE_CODE (type) |
756 | 1301 | || TYPE_PRECISION (type1) * 2 != TYPE_PRECISION (type)) | 1316 | || TYPE_PRECISION (type1) * 2 > TYPE_PRECISION (type)) |
757 | 1302 | return false; | 1317 | return false; |
758 | 1303 | 1318 | ||
760 | 1304 | *new_rhs_out = rhs1; | 1319 | if (rhs1) |
761 | 1320 | { | ||
762 | 1321 | rhs_code = gimple_assign_rhs_code (stmt); | ||
763 | 1322 | if (TREE_CODE (type) == INTEGER_TYPE | ||
764 | 1323 | ? !CONVERT_EXPR_CODE_P (rhs_code) | ||
765 | 1324 | : rhs_code != FIXED_CONVERT_EXPR) | ||
766 | 1325 | *new_rhs_out = rhs; | ||
767 | 1326 | else | ||
768 | 1327 | *new_rhs_out = rhs1; | ||
769 | 1328 | } | ||
770 | 1329 | else | ||
771 | 1330 | *new_rhs_out = rhs; | ||
772 | 1305 | *type_out = type1; | 1331 | *type_out = type1; |
773 | 1306 | return true; | 1332 | return true; |
774 | 1307 | } | 1333 | } |
775 | @@ -1316,28 +1342,27 @@ | |||
776 | 1316 | return false; | 1342 | return false; |
777 | 1317 | } | 1343 | } |
778 | 1318 | 1344 | ||
784 | 1319 | /* Return true if STMT performs a widening multiplication. If so, | 1345 | /* Return true if STMT performs a widening multiplication, assuming the |
785 | 1320 | store the unwidened types of the operands in *TYPE1_OUT and *TYPE2_OUT | 1346 | output type is TYPE. If so, store the unwidened types of the operands |
786 | 1321 | respectively. Also fill *RHS1_OUT and *RHS2_OUT such that converting | 1347 | in *TYPE1_OUT and *TYPE2_OUT respectively. Also fill *RHS1_OUT and |
787 | 1322 | those operands to types *TYPE1_OUT and *TYPE2_OUT would give the | 1348 | *RHS2_OUT such that converting those operands to types *TYPE1_OUT |
788 | 1323 | operands of the multiplication. */ | 1349 | and *TYPE2_OUT would give the operands of the multiplication. */ |
789 | 1324 | 1350 | ||
790 | 1325 | static bool | 1351 | static bool |
792 | 1326 | is_widening_mult_p (gimple stmt, | 1352 | is_widening_mult_p (tree type, gimple stmt, |
793 | 1327 | tree *type1_out, tree *rhs1_out, | 1353 | tree *type1_out, tree *rhs1_out, |
794 | 1328 | tree *type2_out, tree *rhs2_out) | 1354 | tree *type2_out, tree *rhs2_out) |
795 | 1329 | { | 1355 | { |
796 | 1330 | tree type; | ||
797 | 1331 | |||
798 | 1332 | type = TREE_TYPE (gimple_assign_lhs (stmt)); | ||
799 | 1333 | if (TREE_CODE (type) != INTEGER_TYPE | 1356 | if (TREE_CODE (type) != INTEGER_TYPE |
800 | 1334 | && TREE_CODE (type) != FIXED_POINT_TYPE) | 1357 | && TREE_CODE (type) != FIXED_POINT_TYPE) |
801 | 1335 | return false; | 1358 | return false; |
802 | 1336 | 1359 | ||
804 | 1337 | if (!is_widening_mult_rhs_p (gimple_assign_rhs1 (stmt), type1_out, rhs1_out)) | 1360 | if (!is_widening_mult_rhs_p (type, gimple_assign_rhs1 (stmt), type1_out, |
805 | 1361 | rhs1_out)) | ||
806 | 1338 | return false; | 1362 | return false; |
807 | 1339 | 1363 | ||
809 | 1340 | if (!is_widening_mult_rhs_p (gimple_assign_rhs2 (stmt), type2_out, rhs2_out)) | 1364 | if (!is_widening_mult_rhs_p (type, gimple_assign_rhs2 (stmt), type2_out, |
810 | 1365 | rhs2_out)) | ||
811 | 1341 | return false; | 1366 | return false; |
812 | 1342 | 1367 | ||
813 | 1343 | if (*type1_out == NULL) | 1368 | if (*type1_out == NULL) |
814 | @@ -1354,6 +1379,18 @@ | |||
815 | 1354 | *type2_out = *type1_out; | 1379 | *type2_out = *type1_out; |
816 | 1355 | } | 1380 | } |
817 | 1356 | 1381 | ||
818 | 1382 | /* Ensure that the larger of the two operands comes first. */ | ||
819 | 1383 | if (TYPE_PRECISION (*type1_out) < TYPE_PRECISION (*type2_out)) | ||
820 | 1384 | { | ||
821 | 1385 | tree tmp; | ||
822 | 1386 | tmp = *type1_out; | ||
823 | 1387 | *type1_out = *type2_out; | ||
824 | 1388 | *type2_out = tmp; | ||
825 | 1389 | tmp = *rhs1_out; | ||
826 | 1390 | *rhs1_out = *rhs2_out; | ||
827 | 1391 | *rhs2_out = tmp; | ||
828 | 1392 | } | ||
829 | 1393 | |||
830 | 1357 | return true; | 1394 | return true; |
831 | 1358 | } | 1395 | } |
832 | 1359 | 1396 | ||
833 | @@ -1362,31 +1399,94 @@ | |||
834 | 1362 | value is true iff we converted the statement. */ | 1399 | value is true iff we converted the statement. */ |
835 | 1363 | 1400 | ||
836 | 1364 | static bool | 1401 | static bool |
838 | 1365 | convert_mult_to_widen (gimple stmt) | 1402 | convert_mult_to_widen (gimple stmt, gimple_stmt_iterator *gsi) |
839 | 1366 | { | 1403 | { |
841 | 1367 | tree lhs, rhs1, rhs2, type, type1, type2; | 1404 | tree lhs, rhs1, rhs2, type, type1, type2, tmp = NULL; |
842 | 1368 | enum insn_code handler; | 1405 | enum insn_code handler; |
843 | 1406 | enum machine_mode to_mode, from_mode, actual_mode; | ||
844 | 1407 | optab op; | ||
845 | 1408 | int actual_precision; | ||
846 | 1409 | location_t loc = gimple_location (stmt); | ||
847 | 1410 | bool from_unsigned1, from_unsigned2; | ||
848 | 1369 | 1411 | ||
849 | 1370 | lhs = gimple_assign_lhs (stmt); | 1412 | lhs = gimple_assign_lhs (stmt); |
850 | 1371 | type = TREE_TYPE (lhs); | 1413 | type = TREE_TYPE (lhs); |
851 | 1372 | if (TREE_CODE (type) != INTEGER_TYPE) | 1414 | if (TREE_CODE (type) != INTEGER_TYPE) |
852 | 1373 | return false; | 1415 | return false; |
853 | 1374 | 1416 | ||
855 | 1375 | if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2)) | 1417 | if (!is_widening_mult_p (type, stmt, &type1, &rhs1, &type2, &rhs2)) |
856 | 1376 | return false; | 1418 | return false; |
857 | 1377 | 1419 | ||
862 | 1378 | if (TYPE_UNSIGNED (type1) && TYPE_UNSIGNED (type2)) | 1420 | to_mode = TYPE_MODE (type); |
863 | 1379 | handler = optab_handler (umul_widen_optab, TYPE_MODE (type)); | 1421 | from_mode = TYPE_MODE (type1); |
864 | 1380 | else if (!TYPE_UNSIGNED (type1) && !TYPE_UNSIGNED (type2)) | 1422 | from_unsigned1 = TYPE_UNSIGNED (type1); |
865 | 1381 | handler = optab_handler (smul_widen_optab, TYPE_MODE (type)); | 1423 | from_unsigned2 = TYPE_UNSIGNED (type2); |
866 | 1424 | |||
867 | 1425 | if (from_unsigned1 && from_unsigned2) | ||
868 | 1426 | op = umul_widen_optab; | ||
869 | 1427 | else if (!from_unsigned1 && !from_unsigned2) | ||
870 | 1428 | op = smul_widen_optab; | ||
871 | 1382 | else | 1429 | else |
873 | 1383 | handler = optab_handler (usmul_widen_optab, TYPE_MODE (type)); | 1430 | op = usmul_widen_optab; |
874 | 1431 | |||
875 | 1432 | handler = find_widening_optab_handler_and_mode (op, to_mode, from_mode, | ||
876 | 1433 | 0, &actual_mode); | ||
877 | 1384 | 1434 | ||
878 | 1385 | if (handler == CODE_FOR_nothing) | 1435 | if (handler == CODE_FOR_nothing) |
883 | 1386 | return false; | 1436 | { |
884 | 1387 | 1437 | if (op != smul_widen_optab) | |
885 | 1388 | gimple_assign_set_rhs1 (stmt, fold_convert (type1, rhs1)); | 1438 | { |
886 | 1389 | gimple_assign_set_rhs2 (stmt, fold_convert (type2, rhs2)); | 1439 | /* We can use a signed multiply with unsigned types as long as |
887 | 1440 | there is a wider mode to use, or it is the smaller of the two | ||
888 | 1441 | types that is unsigned. Note that type1 >= type2, always. */ | ||
889 | 1442 | if ((TYPE_UNSIGNED (type1) | ||
890 | 1443 | && TYPE_PRECISION (type1) == GET_MODE_PRECISION (from_mode)) | ||
891 | 1444 | || (TYPE_UNSIGNED (type2) | ||
892 | 1445 | && TYPE_PRECISION (type2) == GET_MODE_PRECISION (from_mode))) | ||
893 | 1446 | { | ||
894 | 1447 | from_mode = GET_MODE_WIDER_MODE (from_mode); | ||
895 | 1448 | if (GET_MODE_SIZE (to_mode) <= GET_MODE_SIZE (from_mode)) | ||
896 | 1449 | return false; | ||
897 | 1450 | } | ||
898 | 1451 | |||
899 | 1452 | op = smul_widen_optab; | ||
900 | 1453 | handler = find_widening_optab_handler_and_mode (op, to_mode, | ||
901 | 1454 | from_mode, 0, | ||
902 | 1455 | &actual_mode); | ||
903 | 1456 | |||
904 | 1457 | if (handler == CODE_FOR_nothing) | ||
905 | 1458 | return false; | ||
906 | 1459 | |||
907 | 1460 | from_unsigned1 = from_unsigned2 = false; | ||
908 | 1461 | } | ||
909 | 1462 | else | ||
910 | 1463 | return false; | ||
911 | 1464 | } | ||
912 | 1465 | |||
913 | 1466 | /* Ensure that the inputs to the handler are in the correct precison | ||
914 | 1467 | for the opcode. This will be the full mode size. */ | ||
915 | 1468 | actual_precision = GET_MODE_PRECISION (actual_mode); | ||
916 | 1469 | if (actual_precision != TYPE_PRECISION (type1) | ||
917 | 1470 | || from_unsigned1 != TYPE_UNSIGNED (type1)) | ||
918 | 1471 | { | ||
919 | 1472 | tmp = create_tmp_var (build_nonstandard_integer_type | ||
920 | 1473 | (actual_precision, from_unsigned1), | ||
921 | 1474 | NULL); | ||
922 | 1475 | rhs1 = build_and_insert_cast (gsi, loc, tmp, rhs1); | ||
923 | 1476 | } | ||
924 | 1477 | if (actual_precision != TYPE_PRECISION (type2) | ||
925 | 1478 | || from_unsigned2 != TYPE_UNSIGNED (type2)) | ||
926 | 1479 | { | ||
927 | 1480 | /* Reuse the same type info, if possible. */ | ||
928 | 1481 | if (!tmp || from_unsigned1 != from_unsigned2) | ||
929 | 1482 | tmp = create_tmp_var (build_nonstandard_integer_type | ||
930 | 1483 | (actual_precision, from_unsigned2), | ||
931 | 1484 | NULL); | ||
932 | 1485 | rhs2 = build_and_insert_cast (gsi, loc, tmp, rhs2); | ||
933 | 1486 | } | ||
934 | 1487 | |||
935 | 1488 | gimple_assign_set_rhs1 (stmt, rhs1); | ||
936 | 1489 | gimple_assign_set_rhs2 (stmt, rhs2); | ||
937 | 1390 | gimple_assign_set_rhs_code (stmt, WIDEN_MULT_EXPR); | 1490 | gimple_assign_set_rhs_code (stmt, WIDEN_MULT_EXPR); |
938 | 1391 | update_stmt (stmt); | 1491 | update_stmt (stmt); |
939 | 1392 | return true; | 1492 | return true; |
940 | @@ -1403,11 +1503,17 @@ | |||
941 | 1403 | enum tree_code code) | 1503 | enum tree_code code) |
942 | 1404 | { | 1504 | { |
943 | 1405 | gimple rhs1_stmt = NULL, rhs2_stmt = NULL; | 1505 | gimple rhs1_stmt = NULL, rhs2_stmt = NULL; |
945 | 1406 | tree type, type1, type2; | 1506 | gimple conv1_stmt = NULL, conv2_stmt = NULL, conv_stmt; |
946 | 1507 | tree type, type1, type2, optype, tmp = NULL; | ||
947 | 1407 | tree lhs, rhs1, rhs2, mult_rhs1, mult_rhs2, add_rhs; | 1508 | tree lhs, rhs1, rhs2, mult_rhs1, mult_rhs2, add_rhs; |
948 | 1408 | enum tree_code rhs1_code = ERROR_MARK, rhs2_code = ERROR_MARK; | 1509 | enum tree_code rhs1_code = ERROR_MARK, rhs2_code = ERROR_MARK; |
949 | 1409 | optab this_optab; | 1510 | optab this_optab; |
950 | 1410 | enum tree_code wmult_code; | 1511 | enum tree_code wmult_code; |
951 | 1512 | enum insn_code handler; | ||
952 | 1513 | enum machine_mode to_mode, from_mode, actual_mode; | ||
953 | 1514 | location_t loc = gimple_location (stmt); | ||
954 | 1515 | int actual_precision; | ||
955 | 1516 | bool from_unsigned1, from_unsigned2; | ||
956 | 1411 | 1517 | ||
957 | 1412 | lhs = gimple_assign_lhs (stmt); | 1518 | lhs = gimple_assign_lhs (stmt); |
958 | 1413 | type = TREE_TYPE (lhs); | 1519 | type = TREE_TYPE (lhs); |
959 | @@ -1441,54 +1547,153 @@ | |||
960 | 1441 | else | 1547 | else |
961 | 1442 | return false; | 1548 | return false; |
962 | 1443 | 1549 | ||
992 | 1444 | if (code == PLUS_EXPR && rhs1_code == MULT_EXPR) | 1550 | /* Allow for one conversion statement between the multiply |
993 | 1445 | { | 1551 | and addition/subtraction statement. If there are more than |
994 | 1446 | if (!is_widening_mult_p (rhs1_stmt, &type1, &mult_rhs1, | 1552 | one conversions then we assume they would invalidate this |
995 | 1447 | &type2, &mult_rhs2)) | 1553 | transformation. If that's not the case then they should have |
996 | 1448 | return false; | 1554 | been folded before now. */ |
997 | 1449 | add_rhs = rhs2; | 1555 | if (CONVERT_EXPR_CODE_P (rhs1_code)) |
998 | 1450 | } | 1556 | { |
999 | 1451 | else if (rhs2_code == MULT_EXPR) | 1557 | conv1_stmt = rhs1_stmt; |
1000 | 1452 | { | 1558 | rhs1 = gimple_assign_rhs1 (rhs1_stmt); |
1001 | 1453 | if (!is_widening_mult_p (rhs2_stmt, &type1, &mult_rhs1, | 1559 | if (TREE_CODE (rhs1) == SSA_NAME) |
1002 | 1454 | &type2, &mult_rhs2)) | 1560 | { |
1003 | 1455 | return false; | 1561 | rhs1_stmt = SSA_NAME_DEF_STMT (rhs1); |
1004 | 1456 | add_rhs = rhs1; | 1562 | if (is_gimple_assign (rhs1_stmt)) |
1005 | 1457 | } | 1563 | rhs1_code = gimple_assign_rhs_code (rhs1_stmt); |
1006 | 1458 | else if (code == PLUS_EXPR && rhs1_code == WIDEN_MULT_EXPR) | 1564 | } |
1007 | 1459 | { | 1565 | else |
1008 | 1460 | mult_rhs1 = gimple_assign_rhs1 (rhs1_stmt); | 1566 | return false; |
1009 | 1461 | mult_rhs2 = gimple_assign_rhs2 (rhs1_stmt); | 1567 | } |
1010 | 1462 | type1 = TREE_TYPE (mult_rhs1); | 1568 | if (CONVERT_EXPR_CODE_P (rhs2_code)) |
1011 | 1463 | type2 = TREE_TYPE (mult_rhs2); | 1569 | { |
1012 | 1464 | add_rhs = rhs2; | 1570 | conv2_stmt = rhs2_stmt; |
1013 | 1465 | } | 1571 | rhs2 = gimple_assign_rhs1 (rhs2_stmt); |
1014 | 1466 | else if (rhs2_code == WIDEN_MULT_EXPR) | 1572 | if (TREE_CODE (rhs2) == SSA_NAME) |
1015 | 1467 | { | 1573 | { |
1016 | 1468 | mult_rhs1 = gimple_assign_rhs1 (rhs2_stmt); | 1574 | rhs2_stmt = SSA_NAME_DEF_STMT (rhs2); |
1017 | 1469 | mult_rhs2 = gimple_assign_rhs2 (rhs2_stmt); | 1575 | if (is_gimple_assign (rhs2_stmt)) |
1018 | 1470 | type1 = TREE_TYPE (mult_rhs1); | 1576 | rhs2_code = gimple_assign_rhs_code (rhs2_stmt); |
1019 | 1471 | type2 = TREE_TYPE (mult_rhs2); | 1577 | } |
1020 | 1472 | add_rhs = rhs1; | 1578 | else |
1021 | 1579 | return false; | ||
1022 | 1580 | } | ||
1023 | 1581 | |||
1024 | 1582 | /* If code is WIDEN_MULT_EXPR then it would seem unnecessary to call | ||
1025 | 1583 | is_widening_mult_p, but we still need the rhs returns. | ||
1026 | 1584 | |||
1027 | 1585 | It might also appear that it would be sufficient to use the existing | ||
1028 | 1586 | operands of the widening multiply, but that would limit the choice of | ||
1029 | 1587 | multiply-and-accumulate instructions. */ | ||
1030 | 1588 | if (code == PLUS_EXPR | ||
1031 | 1589 | && (rhs1_code == MULT_EXPR || rhs1_code == WIDEN_MULT_EXPR)) | ||
1032 | 1590 | { | ||
1033 | 1591 | if (!is_widening_mult_p (type, rhs1_stmt, &type1, &mult_rhs1, | ||
1034 | 1592 | &type2, &mult_rhs2)) | ||
1035 | 1593 | return false; | ||
1036 | 1594 | add_rhs = rhs2; | ||
1037 | 1595 | conv_stmt = conv1_stmt; | ||
1038 | 1596 | } | ||
1039 | 1597 | else if (rhs2_code == MULT_EXPR || rhs2_code == WIDEN_MULT_EXPR) | ||
1040 | 1598 | { | ||
1041 | 1599 | if (!is_widening_mult_p (type, rhs2_stmt, &type1, &mult_rhs1, | ||
1042 | 1600 | &type2, &mult_rhs2)) | ||
1043 | 1601 | return false; | ||
1044 | 1602 | add_rhs = rhs1; | ||
1045 | 1603 | conv_stmt = conv2_stmt; | ||
1046 | 1473 | } | 1604 | } |
1047 | 1474 | else | 1605 | else |
1048 | 1475 | return false; | 1606 | return false; |
1049 | 1476 | 1607 | ||
1052 | 1477 | if (TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2)) | 1608 | to_mode = TYPE_MODE (type); |
1053 | 1478 | return false; | 1609 | from_mode = TYPE_MODE (type1); |
1054 | 1610 | from_unsigned1 = TYPE_UNSIGNED (type1); | ||
1055 | 1611 | from_unsigned2 = TYPE_UNSIGNED (type2); | ||
1056 | 1612 | |||
1057 | 1613 | /* There's no such thing as a mixed sign madd yet, so use a wider mode. */ | ||
1058 | 1614 | if (from_unsigned1 != from_unsigned2) | ||
1059 | 1615 | { | ||
1060 | 1616 | /* We can use a signed multiply with unsigned types as long as | ||
1061 | 1617 | there is a wider mode to use, or it is the smaller of the two | ||
1062 | 1618 | types that is unsigned. Note that type1 >= type2, always. */ | ||
1063 | 1619 | if ((from_unsigned1 | ||
1064 | 1620 | && TYPE_PRECISION (type1) == GET_MODE_PRECISION (from_mode)) | ||
1065 | 1621 | || (from_unsigned2 | ||
1066 | 1622 | && TYPE_PRECISION (type2) == GET_MODE_PRECISION (from_mode))) | ||
1067 | 1623 | { | ||
1068 | 1624 | from_mode = GET_MODE_WIDER_MODE (from_mode); | ||
1069 | 1625 | if (GET_MODE_SIZE (from_mode) >= GET_MODE_SIZE (to_mode)) | ||
1070 | 1626 | return false; | ||
1071 | 1627 | } | ||
1072 | 1628 | |||
1073 | 1629 | from_unsigned1 = from_unsigned2 = false; | ||
1074 | 1630 | } | ||
1075 | 1631 | |||
1076 | 1632 | /* If there was a conversion between the multiply and addition | ||
1077 | 1633 | then we need to make sure it fits a multiply-and-accumulate. | ||
1078 | 1634 | The should be a single mode change which does not change the | ||
1079 | 1635 | value. */ | ||
1080 | 1636 | if (conv_stmt) | ||
1081 | 1637 | { | ||
1082 | 1638 | /* We use the original, unmodified data types for this. */ | ||
1083 | 1639 | tree from_type = TREE_TYPE (gimple_assign_rhs1 (conv_stmt)); | ||
1084 | 1640 | tree to_type = TREE_TYPE (gimple_assign_lhs (conv_stmt)); | ||
1085 | 1641 | int data_size = TYPE_PRECISION (type1) + TYPE_PRECISION (type2); | ||
1086 | 1642 | bool is_unsigned = TYPE_UNSIGNED (type1) && TYPE_UNSIGNED (type2); | ||
1087 | 1643 | |||
1088 | 1644 | if (TYPE_PRECISION (from_type) > TYPE_PRECISION (to_type)) | ||
1089 | 1645 | { | ||
1090 | 1646 | /* Conversion is a truncate. */ | ||
1091 | 1647 | if (TYPE_PRECISION (to_type) < data_size) | ||
1092 | 1648 | return false; | ||
1093 | 1649 | } | ||
1094 | 1650 | else if (TYPE_PRECISION (from_type) < TYPE_PRECISION (to_type)) | ||
1095 | 1651 | { | ||
1096 | 1652 | /* Conversion is an extend. Check it's the right sort. */ | ||
1097 | 1653 | if (TYPE_UNSIGNED (from_type) != is_unsigned | ||
1098 | 1654 | && !(is_unsigned && TYPE_PRECISION (from_type) > data_size)) | ||
1099 | 1655 | return false; | ||
1100 | 1656 | } | ||
1101 | 1657 | /* else convert is a no-op for our purposes. */ | ||
1102 | 1658 | } | ||
1103 | 1479 | 1659 | ||
1104 | 1480 | /* Verify that the machine can perform a widening multiply | 1660 | /* Verify that the machine can perform a widening multiply |
1105 | 1481 | accumulate in this mode/signedness combination, otherwise | 1661 | accumulate in this mode/signedness combination, otherwise |
1106 | 1482 | this transformation is likely to pessimize code. */ | 1662 | this transformation is likely to pessimize code. */ |
1109 | 1483 | this_optab = optab_for_tree_code (wmult_code, type1, optab_default); | 1663 | optype = build_nonstandard_integer_type (from_mode, from_unsigned1); |
1110 | 1484 | if (optab_handler (this_optab, TYPE_MODE (type)) == CODE_FOR_nothing) | 1664 | this_optab = optab_for_tree_code (wmult_code, optype, optab_default); |
1111 | 1665 | handler = find_widening_optab_handler_and_mode (this_optab, to_mode, | ||
1112 | 1666 | from_mode, 0, &actual_mode); | ||
1113 | 1667 | |||
1114 | 1668 | if (handler == CODE_FOR_nothing) | ||
1115 | 1485 | return false; | 1669 | return false; |
1116 | 1486 | 1670 | ||
1122 | 1487 | /* ??? May need some type verification here? */ | 1671 | /* Ensure that the inputs to the handler are in the correct precison |
1123 | 1488 | 1672 | for the opcode. This will be the full mode size. */ | |
1124 | 1489 | gimple_assign_set_rhs_with_ops_1 (gsi, wmult_code, | 1673 | actual_precision = GET_MODE_PRECISION (actual_mode); |
1125 | 1490 | fold_convert (type1, mult_rhs1), | 1674 | if (actual_precision != TYPE_PRECISION (type1) |
1126 | 1491 | fold_convert (type2, mult_rhs2), | 1675 | || from_unsigned1 != TYPE_UNSIGNED (type1)) |
1127 | 1676 | { | ||
1128 | 1677 | tmp = create_tmp_var (build_nonstandard_integer_type | ||
1129 | 1678 | (actual_precision, from_unsigned1), | ||
1130 | 1679 | NULL); | ||
1131 | 1680 | mult_rhs1 = build_and_insert_cast (gsi, loc, tmp, mult_rhs1); | ||
1132 | 1681 | } | ||
1133 | 1682 | if (actual_precision != TYPE_PRECISION (type2) | ||
1134 | 1683 | || from_unsigned2 != TYPE_UNSIGNED (type2)) | ||
1135 | 1684 | { | ||
1136 | 1685 | if (!tmp || from_unsigned1 != from_unsigned2) | ||
1137 | 1686 | tmp = create_tmp_var (build_nonstandard_integer_type | ||
1138 | 1687 | (actual_precision, from_unsigned2), | ||
1139 | 1688 | NULL); | ||
1140 | 1689 | mult_rhs2 = build_and_insert_cast (gsi, loc, tmp, mult_rhs2); | ||
1141 | 1690 | } | ||
1142 | 1691 | |||
1143 | 1692 | if (TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (add_rhs))) | ||
1144 | 1693 | add_rhs = build_and_insert_cast (gsi, loc, create_tmp_var (type, NULL), | ||
1145 | 1694 | add_rhs); | ||
1146 | 1695 | |||
1147 | 1696 | gimple_assign_set_rhs_with_ops_1 (gsi, wmult_code, mult_rhs1, mult_rhs2, | ||
1148 | 1492 | add_rhs); | 1697 | add_rhs); |
1149 | 1493 | update_stmt (gsi_stmt (*gsi)); | 1698 | update_stmt (gsi_stmt (*gsi)); |
1150 | 1494 | return true; | 1699 | return true; |
1151 | @@ -1696,7 +1901,7 @@ | |||
1152 | 1696 | switch (code) | 1901 | switch (code) |
1153 | 1697 | { | 1902 | { |
1154 | 1698 | case MULT_EXPR: | 1903 | case MULT_EXPR: |
1156 | 1699 | if (!convert_mult_to_widen (stmt) | 1904 | if (!convert_mult_to_widen (stmt, &gsi) |
1157 | 1700 | && convert_mult_to_fma (stmt, | 1905 | && convert_mult_to_fma (stmt, |
1158 | 1701 | gimple_assign_rhs1 (stmt), | 1906 | gimple_assign_rhs1 (stmt), |
1159 | 1702 | gimple_assign_rhs2 (stmt))) | 1907 | gimple_assign_rhs2 (stmt))) |
cbuild has taken a snapshot of this branch at r106781 and queued it for build.
The snapshot is available at: ex.seabright. co.nz/snapshots /gcc-linaro- 4.6+bzr106781~ ams-codesourcer y~widening- multiplies- 4.6.tar. xdelta3. xz
http://
and will be built on the following builders:
a9-builder armv5-builder i686 x86_64
You can track the build queue at: ex.seabright. co.nz/helpers/ scheduler
http://
cbuild-snapshot: gcc-linaro- 4.6+bzr106781~ ams-codesourcer y~widening- multiplies- 4.6
cbuild-ancestor: lp:gcc-linaro/4.6+bzr106774
cbuild-state: check