comparison gcc/tree-ssa-ifcombine.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents 855418dad1a3
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
106 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) 106 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
107 { 107 {
108 gimple stmt = gsi_stmt (gsi); 108 gimple stmt = gsi_stmt (gsi);
109 109
110 if (gimple_has_volatile_ops (stmt) 110 if (gimple_has_volatile_ops (stmt)
111 || !ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) 111 || gimple_vuse (stmt))
112 return false; 112 return false;
113 } 113 }
114 114
115 return true; 115 return true;
116 } 116 }
338 true, GSI_SAME_STMT); 338 true, GSI_SAME_STMT);
339 t2 = fold_build2 (BIT_AND_EXPR, TREE_TYPE (name1), name1, t); 339 t2 = fold_build2 (BIT_AND_EXPR, TREE_TYPE (name1), name1, t);
340 t2 = force_gimple_operand_gsi (&gsi, t2, true, NULL_TREE, 340 t2 = force_gimple_operand_gsi (&gsi, t2, true, NULL_TREE,
341 true, GSI_SAME_STMT); 341 true, GSI_SAME_STMT);
342 t = fold_build2 (EQ_EXPR, boolean_type_node, t2, t); 342 t = fold_build2 (EQ_EXPR, boolean_type_node, t2, t);
343 t = canonicalize_cond_expr_cond (t);
344 if (!t)
345 return false;
343 gimple_cond_set_condition_from_tree (inner_cond, t); 346 gimple_cond_set_condition_from_tree (inner_cond, t);
344 update_stmt (inner_cond); 347 update_stmt (inner_cond);
345 348
346 /* Leave CFG optimization to cfg_cleanup. */ 349 /* Leave CFG optimization to cfg_cleanup. */
347 gimple_cond_set_condition_from_tree (outer_cond, boolean_true_node); 350 gimple_cond_set_condition_from_tree (outer_cond, boolean_true_node);
354 fprintf (dump_file, " & T == T\nwith temporary T = (1 << "); 357 fprintf (dump_file, " & T == T\nwith temporary T = (1 << ");
355 print_generic_expr (dump_file, bit1, 0); 358 print_generic_expr (dump_file, bit1, 0);
356 fprintf (dump_file, ") | (1 << "); 359 fprintf (dump_file, ") | (1 << ");
357 print_generic_expr (dump_file, bit2, 0); 360 print_generic_expr (dump_file, bit2, 0);
358 fprintf (dump_file, ")\n"); 361 fprintf (dump_file, ")\n");
362 }
363
364 return true;
365 }
366
367 /* See if we have two comparisons that we can merge into one. */
368 else if (TREE_CODE_CLASS (gimple_cond_code (inner_cond)) == tcc_comparison
369 && TREE_CODE_CLASS (gimple_cond_code (outer_cond)) == tcc_comparison
370 && operand_equal_p (gimple_cond_lhs (inner_cond),
371 gimple_cond_lhs (outer_cond), 0)
372 && operand_equal_p (gimple_cond_rhs (inner_cond),
373 gimple_cond_rhs (outer_cond), 0))
374 {
375 enum tree_code code1 = gimple_cond_code (inner_cond);
376 enum tree_code code2 = gimple_cond_code (outer_cond);
377 tree t;
378
379 if (!(t = combine_comparisons (UNKNOWN_LOCATION,
380 TRUTH_ANDIF_EXPR, code1, code2,
381 boolean_type_node,
382 gimple_cond_lhs (outer_cond),
383 gimple_cond_rhs (outer_cond))))
384 return false;
385 t = canonicalize_cond_expr_cond (t);
386 if (!t)
387 return false;
388 gimple_cond_set_condition_from_tree (inner_cond, t);
389 update_stmt (inner_cond);
390
391 /* Leave CFG optimization to cfg_cleanup. */
392 gimple_cond_set_condition_from_tree (outer_cond, boolean_true_node);
393 update_stmt (outer_cond);
394
395 if (dump_file)
396 {
397 fprintf (dump_file, "optimizing two comparisons to ");
398 print_generic_expr (dump_file, t, 0);
399 fprintf (dump_file, "\n");
359 } 400 }
360 401
361 return true; 402 return true;
362 } 403 }
363 404
448 t = fold_build2 (BIT_AND_EXPR, TREE_TYPE (name1), name1, t); 489 t = fold_build2 (BIT_AND_EXPR, TREE_TYPE (name1), name1, t);
449 t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, 490 t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
450 true, GSI_SAME_STMT); 491 true, GSI_SAME_STMT);
451 t = fold_build2 (NE_EXPR, boolean_type_node, t, 492 t = fold_build2 (NE_EXPR, boolean_type_node, t,
452 build_int_cst (TREE_TYPE (t), 0)); 493 build_int_cst (TREE_TYPE (t), 0));
494 t = canonicalize_cond_expr_cond (t);
495 if (!t)
496 return false;
453 gimple_cond_set_condition_from_tree (inner_cond, t); 497 gimple_cond_set_condition_from_tree (inner_cond, t);
454 update_stmt (inner_cond); 498 update_stmt (inner_cond);
455 499
456 /* Leave CFG optimization to cfg_cleanup. */ 500 /* Leave CFG optimization to cfg_cleanup. */
457 gimple_cond_set_condition_from_tree (outer_cond, boolean_false_node); 501 gimple_cond_set_condition_from_tree (outer_cond, boolean_false_node);
481 && operand_equal_p (gimple_cond_rhs (inner_cond), 525 && operand_equal_p (gimple_cond_rhs (inner_cond),
482 gimple_cond_rhs (outer_cond), 0)) 526 gimple_cond_rhs (outer_cond), 0))
483 { 527 {
484 enum tree_code code1 = gimple_cond_code (inner_cond); 528 enum tree_code code1 = gimple_cond_code (inner_cond);
485 enum tree_code code2 = gimple_cond_code (outer_cond); 529 enum tree_code code2 = gimple_cond_code (outer_cond);
486 enum tree_code code;
487 tree t; 530 tree t;
488 531
489 #define CHK(a,b) ((code1 == a ## _EXPR && code2 == b ## _EXPR) \ 532 if (!(t = combine_comparisons (UNKNOWN_LOCATION,
490 || (code2 == a ## _EXPR && code1 == b ## _EXPR)) 533 TRUTH_ORIF_EXPR, code1, code2,
491 /* Merge the two condition codes if possible. */ 534 boolean_type_node,
492 if (code1 == code2) 535 gimple_cond_lhs (outer_cond),
493 code = code1; 536 gimple_cond_rhs (outer_cond))))
494 else if (CHK (EQ, LT)) 537 return false;
495 code = LE_EXPR;
496 else if (CHK (EQ, GT))
497 code = GE_EXPR;
498 else if (CHK (LT, LE))
499 code = LE_EXPR;
500 else if (CHK (GT, GE))
501 code = GE_EXPR;
502 else if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_cond_lhs (inner_cond)))
503 || flag_unsafe_math_optimizations)
504 {
505 if (CHK (LT, GT))
506 code = NE_EXPR;
507 else if (CHK (LT, NE))
508 code = NE_EXPR;
509 else if (CHK (GT, NE))
510 code = NE_EXPR;
511 else
512 return false;
513 }
514 /* We could check for combinations leading to trivial true/false. */
515 else
516 return false;
517 #undef CHK
518
519 /* Do it. */
520 t = fold_build2 (code, boolean_type_node, gimple_cond_lhs (outer_cond),
521 gimple_cond_rhs (outer_cond));
522 t = canonicalize_cond_expr_cond (t); 538 t = canonicalize_cond_expr_cond (t);
523 if (!t) 539 if (!t)
524 return false; 540 return false;
525 gimple_cond_set_condition_from_tree (inner_cond, t); 541 gimple_cond_set_condition_from_tree (inner_cond, t);
526 update_stmt (inner_cond); 542 update_stmt (inner_cond);
639 gate_ifcombine (void) 655 gate_ifcombine (void)
640 { 656 {
641 return 1; 657 return 1;
642 } 658 }
643 659
644 struct gimple_opt_pass pass_tree_ifcombine = 660 struct gimple_opt_pass pass_tree_ifcombine =
645 { 661 {
646 { 662 {
647 GIMPLE_PASS, 663 GIMPLE_PASS,
648 "ifcombine", /* name */ 664 "ifcombine", /* name */
649 gate_ifcombine, /* gate */ 665 gate_ifcombine, /* gate */