Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: src/compiler/code-assembler.cc

Issue 2608433003: [csa] Re-introduce automatic constant folding for IntPtrAdd and IntPtrSub (Closed)
Patch Set: Review feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/code-assembler.h" 5 #include "src/compiler/code-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 IntPtrMatcher m(node); 203 IntPtrMatcher m(node);
204 if (m.HasValue()) { 204 if (m.HasValue()) {
205 out_value = Smi::cast(bit_cast<Object*>(m.Value())); 205 out_value = Smi::cast(bit_cast<Object*>(m.Value()));
206 return true; 206 return true;
207 } 207 }
208 return false; 208 return false;
209 } 209 }
210 210
211 bool CodeAssembler::ToIntPtrConstant(Node* node, intptr_t& out_value) { 211 bool CodeAssembler::ToIntPtrConstant(Node* node, intptr_t& out_value) {
212 if (node->opcode() == IrOpcode::kBitcastWordToTaggedSigned ||
213 node->opcode() == IrOpcode::kBitcastWordToTagged) {
214 node = node->InputAt(0);
215 }
212 IntPtrMatcher m(node); 216 IntPtrMatcher m(node);
213 if (m.HasValue()) out_value = m.Value(); 217 if (m.HasValue()) out_value = m.Value();
214 return m.HasValue(); 218 return m.HasValue();
215 } 219 }
216 220
217 Node* CodeAssembler::Parameter(int value) { 221 Node* CodeAssembler::Parameter(int value) {
218 return raw_assembler()->Parameter(value); 222 return raw_assembler()->Parameter(value);
219 } 223 }
220 224
221 void CodeAssembler::Return(Node* value) { 225 void CodeAssembler::Return(Node* value) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return raw_assembler()->LoadStackPointer(); 266 return raw_assembler()->LoadStackPointer();
263 } 267 }
264 268
265 #define DEFINE_CODE_ASSEMBLER_BINARY_OP(name) \ 269 #define DEFINE_CODE_ASSEMBLER_BINARY_OP(name) \
266 Node* CodeAssembler::name(Node* a, Node* b) { \ 270 Node* CodeAssembler::name(Node* a, Node* b) { \
267 return raw_assembler()->name(a, b); \ 271 return raw_assembler()->name(a, b); \
268 } 272 }
269 CODE_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_ASSEMBLER_BINARY_OP) 273 CODE_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_ASSEMBLER_BINARY_OP)
270 #undef DEFINE_CODE_ASSEMBLER_BINARY_OP 274 #undef DEFINE_CODE_ASSEMBLER_BINARY_OP
271 275
276 Node* CodeAssembler::IntPtrAdd(Node* left, Node* right) {
277 intptr_t left_constant;
278 bool is_left_constant = ToIntPtrConstant(left, left_constant);
279 intptr_t right_constant;
280 bool is_right_constant = ToIntPtrConstant(right, right_constant);
281 if (is_left_constant) {
282 if (is_right_constant) {
283 return IntPtrConstant(left_constant + right_constant);
284 }
285 if (left_constant == 0) {
286 return right;
287 }
288 } else if (is_right_constant) {
289 if (right_constant == 0) {
290 return left;
291 }
292 }
293 return raw_assembler()->IntPtrAdd(left, right);
294 }
295
296 Node* CodeAssembler::IntPtrSub(Node* left, Node* right) {
297 intptr_t left_constant;
298 bool is_left_constant = ToIntPtrConstant(left, left_constant);
299 intptr_t right_constant;
300 bool is_right_constant = ToIntPtrConstant(right, right_constant);
301 if (is_left_constant) {
302 if (is_right_constant) {
303 return IntPtrConstant(left_constant - right_constant);
304 }
305 } else if (is_right_constant) {
306 if (right_constant == 0) {
307 return left;
308 }
309 }
310 return raw_assembler()->IntPtrSub(left, right);
311 }
312
272 Node* CodeAssembler::WordShl(Node* value, int shift) { 313 Node* CodeAssembler::WordShl(Node* value, int shift) {
273 return (shift != 0) ? raw_assembler()->WordShl(value, IntPtrConstant(shift)) 314 return (shift != 0) ? raw_assembler()->WordShl(value, IntPtrConstant(shift))
274 : value; 315 : value;
275 } 316 }
276 317
277 Node* CodeAssembler::WordShr(Node* value, int shift) { 318 Node* CodeAssembler::WordShr(Node* value, int shift) {
278 return (shift != 0) ? raw_assembler()->WordShr(value, IntPtrConstant(shift)) 319 return (shift != 0) ? raw_assembler()->WordShr(value, IntPtrConstant(shift))
279 : value; 320 : value;
280 } 321 }
281 322
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 795 }
755 } 796 }
756 } 797 }
757 798
758 bound_ = true; 799 bound_ = true;
759 } 800 }
760 801
761 } // namespace compiler 802 } // namespace compiler
762 } // namespace internal 803 } // namespace internal
763 } // namespace v8 804 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/code-assembler.h ('k') | test/unittests/interpreter/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698