View | Details | Return to bug 87859 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/gimple-ssa-store-merging.c.jj (-94 / +42 lines)
Lines 1372-1377 struct store_immediate_info Link Here
1372
  /* True if ops have been swapped and thus ops[1] represents
1372
  /* True if ops have been swapped and thus ops[1] represents
1373
     rhs1 of BIT_{AND,IOR,XOR}_EXPR and ops[0] represents rhs2.  */
1373
     rhs1 of BIT_{AND,IOR,XOR}_EXPR and ops[0] represents rhs2.  */
1374
  bool ops_swapped_p;
1374
  bool ops_swapped_p;
1375
  /* True if this has been already merged.  */
1376
  bool merged_p;
1375
  /* Operands.  For BIT_*_EXPR rhs_code both operands are used, otherwise
1377
  /* Operands.  For BIT_*_EXPR rhs_code both operands are used, otherwise
1376
     just the first one.  */
1378
     just the first one.  */
1377
  store_operand_info ops[2];
1379
  store_operand_info ops[2];
Lines 1397-1403 store_immediate_info::store_immediate_in Link Here
1397
					    const store_operand_info &op1r)
1399
					    const store_operand_info &op1r)
1398
  : bitsize (bs), bitpos (bp), bitregion_start (brs), bitregion_end (bre),
1400
  : bitsize (bs), bitpos (bp), bitregion_start (brs), bitregion_end (bre),
1399
    stmt (st), order (ord), rhs_code (rhscode), n (nr),
1401
    stmt (st), order (ord), rhs_code (rhscode), n (nr),
1400
    ins_stmt (ins_stmtp), bit_not_p (bitnotp), ops_swapped_p (false)
1402
    ins_stmt (ins_stmtp), bit_not_p (bitnotp), ops_swapped_p (false),
1403
    merged_p (false)
1401
#if __cplusplus >= 201103L
1404
#if __cplusplus >= 201103L
1402
    , ops { op0r, op1r }
1405
    , ops { op0r, op1r }
1403
{
1406
{
Lines 1430-1436 struct merged_store_group Link Here
1430
  unsigned int last_order;
1433
  unsigned int last_order;
1431
  bool bit_insertion;
1434
  bool bit_insertion;
1432
  bool only_constants;
1435
  bool only_constants;
1433
  unsigned int first_nonmergeable_order;
1434
1436
1435
  auto_vec<store_immediate_info *> stores;
1437
  auto_vec<store_immediate_info *> stores;
1436
  /* We record the first and last original statements in the sequence because
1438
  /* We record the first and last original statements in the sequence because
Lines 1814-1819 sort_by_order (const void *x, const void Link Here
1814
1816
1815
merged_store_group::merged_store_group (store_immediate_info *info)
1817
merged_store_group::merged_store_group (store_immediate_info *info)
1816
{
1818
{
1819
  info->merged_p = true;
1817
  start = info->bitpos;
1820
  start = info->bitpos;
1818
  width = info->bitsize;
1821
  width = info->bitsize;
1819
  bitregion_start = info->bitregion_start;
1822
  bitregion_start = info->bitregion_start;
Lines 1824-1830 merged_store_group::merged_store_group ( Link Here
1824
  mask = NULL;
1827
  mask = NULL;
1825
  bit_insertion = false;
1828
  bit_insertion = false;
1826
  only_constants = info->rhs_code == INTEGER_CST;
1829
  only_constants = info->rhs_code == INTEGER_CST;
1827
  first_nonmergeable_order = ~0U;
1828
  unsigned HOST_WIDE_INT align_bitpos = 0;
1830
  unsigned HOST_WIDE_INT align_bitpos = 0;
1829
  get_object_alignment_1 (gimple_assign_lhs (info->stmt),
1831
  get_object_alignment_1 (gimple_assign_lhs (info->stmt),
1830
			  &align, &align_bitpos);
1832
			  &align, &align_bitpos);
Lines 1902-1907 merged_store_group::can_be_merged_into ( Link Here
1902
void
1904
void
1903
merged_store_group::do_merge (store_immediate_info *info)
1905
merged_store_group::do_merge (store_immediate_info *info)
1904
{
1906
{
1907
  info->merged_p = true;
1905
  bitregion_start = MIN (bitregion_start, info->bitregion_start);
1908
  bitregion_start = MIN (bitregion_start, info->bitregion_start);
1906
  bitregion_end = MAX (bitregion_end, info->bitregion_end);
1909
  bitregion_end = MAX (bitregion_end, info->bitregion_end);
1907
1910
Lines 2671-2677 imm_store_chain_info::coalesce_immediate Link Here
2671
2674
2672
  FOR_EACH_VEC_ELT (m_store_info, i, info)
2675
  FOR_EACH_VEC_ELT (m_store_info, i, info)
2673
    {
2676
    {
2674
      if (i <= ignore)
2677
      if (i <= ignore || info->merged_p)
2675
	goto done;
2678
	goto done;
2676
2679
2677
      /* First try to handle group of stores like:
2680
      /* First try to handle group of stores like:
Lines 2702-2726 imm_store_chain_info::coalesce_immediate Link Here
2702
	    }
2705
	    }
2703
	}
2706
	}
2704
2707
2705
      if (info->order >= merged_store->first_nonmergeable_order)
2706
	;
2707
2708
      /* |---store 1---|
2708
      /* |---store 1---|
2709
	       |---store 2---|
2709
	       |---store 2---|
2710
	 Overlapping stores.  */
2710
	 Overlapping stores.  */
2711
      else if (IN_RANGE (info->bitpos, merged_store->start,
2711
      if (IN_RANGE (info->bitpos, merged_store->start,
2712
			 merged_store->start + merged_store->width - 1))
2712
		    merged_store->start + merged_store->width - 1))
2713
	{
2713
	{
2714
	  /* Only allow overlapping stores of constants.  */
2714
	  /* Only allow overlapping stores of constants.  */
2715
	  if (info->rhs_code == INTEGER_CST && merged_store->only_constants)
2715
	  if (info->rhs_code == INTEGER_CST)
2716
	    {
2716
	    {
2717
	      bool only_constants = true;
2718
	      store_immediate_info *infoj;
2719
	      unsigned int j;
2720
	      FOR_EACH_VEC_ELT (merged_store->stores, j, infoj)
2721
		if (infoj->rhs_code != INTEGER_CST)
2722
		  {
2723
		    only_constants = false;
2724
		    break;
2725
		  }
2717
	      unsigned int last_order
2726
	      unsigned int last_order
2718
		= MAX (merged_store->last_order, info->order);
2727
		= MAX (merged_store->last_order, info->order);
2719
	      unsigned HOST_WIDE_INT end
2728
	      unsigned HOST_WIDE_INT end
2720
		= MAX (merged_store->start + merged_store->width,
2729
		= MAX (merged_store->start + merged_store->width,
2721
		       info->bitpos + info->bitsize);
2730
		       info->bitpos + info->bitsize);
2722
	      if (check_no_overlap (m_store_info, i, INTEGER_CST,
2731
	      if (only_constants
2723
				    last_order, end))
2732
		  && check_no_overlap (m_store_info, i, INTEGER_CST,
2733
				       last_order, end))
2724
		{
2734
		{
2725
		  /* check_no_overlap call above made sure there are no
2735
		  /* check_no_overlap call above made sure there are no
2726
		     overlapping stores with non-INTEGER_CST rhs_code
2736
		     overlapping stores with non-INTEGER_CST rhs_code
Lines 2740-2836 imm_store_chain_info::coalesce_immediate Link Here
2740
		     store_by_bitpos order it comes after the last store that
2750
		     store_by_bitpos order it comes after the last store that
2741
		     we can't merge with them.  We can merge the first 3 stores
2751
		     we can't merge with them.  We can merge the first 3 stores
2742
		     and keep the last store as is though.  */
2752
		     and keep the last store as is though.  */
2743
		  unsigned int len = m_store_info.length ();
2753
		  unsigned int len = m_store_info.length (), k = i;
2744
		  unsigned int try_order = last_order;
2754
		  for (unsigned int j = i + 1; j < len; ++j)
2745
		  unsigned int first_nonmergeable_order;
2746
		  unsigned int k;
2747
		  bool last_iter = false;
2748
		  int attempts = 0;
2749
		  do
2750
		    {
2755
		    {
2751
		      unsigned int max_order = 0;
2756
		      store_immediate_info *info2 = m_store_info[j];
2752
		      unsigned first_nonmergeable_int_order = ~0U;
2757
		      if (info2->bitpos >= end)
2753
		      unsigned HOST_WIDE_INT this_end = end;
2758
			break;
2754
		      k = i;
2759
		      if (info2->order < last_order)
2755
		      first_nonmergeable_order = ~0U;
2756
		      for (unsigned int j = i + 1; j < len; ++j)
2757
			{
2760
			{
2758
			  store_immediate_info *info2 = m_store_info[j];
2761
			  if (info2->rhs_code != INTEGER_CST)
2759
			  if (info2->bitpos >= this_end)
2760
			    break;
2761
			  if (info2->order < try_order)
2762
			    {
2762
			    {
2763
			      if (info2->rhs_code != INTEGER_CST)
2763
			      /* Normally check_no_overlap makes sure this
2764
				{
2764
				 doesn't happen, but if end grows below, then
2765
				  /* Normally check_no_overlap makes sure this
2765
				 we need to process more stores than
2766
				     doesn't happen, but if end grows below,
2766
				 check_no_overlap verified.  Example:
2767
				     then we need to process more stores than
2767
				    MEM[(int *)p_5] = 0;
2768
				     check_no_overlap verified.  Example:
2768
				    MEM[(short *)p_5 + 3B] = 1;
2769
				      MEM[(int *)p_5] = 0;
2769
				    MEM[(char *)p_5 + 4B] = _9;
2770
				      MEM[(short *)p_5 + 3B] = 1;
2770
				    MEM[(char *)p_5 + 2B] = 2;  */
2771
				      MEM[(char *)p_5 + 4B] = _9;
2771
			      k = 0;
2772
				      MEM[(char *)p_5 + 2B] = 2;  */
2772
			      break;
2773
				  k = 0;
2774
				  break;
2775
				}
2776
			      k = j;
2777
			      this_end = MAX (this_end,
2778
					      info2->bitpos + info2->bitsize);
2779
			    }
2773
			    }
2780
			  else if (info2->rhs_code == INTEGER_CST
2774
			  k = j;
2781
				   && !last_iter)
2775
			  end = MAX (end, info2->bitpos + info2->bitsize);
2782
			    {
2783
			      max_order = MAX (max_order, info2->order + 1);
2784
			      first_nonmergeable_int_order
2785
				= MIN (first_nonmergeable_int_order,
2786
				       info2->order);
2787
			    }
2788
			  else
2789
			    first_nonmergeable_order
2790
			      = MIN (first_nonmergeable_order, info2->order);
2791
			}
2776
			}
2792
		      if (k == 0)
2793
			{
2794
			  if (last_order == try_order)
2795
			    break;
2796
			  /* If this failed, but only because we grew
2797
			     try_order, retry with the last working one,
2798
			     so that we merge at least something.  */
2799
			  try_order = last_order;
2800
			  last_iter = true;
2801
			  continue;
2802
			}
2803
		      last_order = try_order;
2804
		      /* Retry with a larger try_order to see if we could
2805
			 merge some further INTEGER_CST stores.  */
2806
		      if (max_order
2807
			  && (first_nonmergeable_int_order
2808
			      < first_nonmergeable_order))
2809
			{
2810
			  try_order = MIN (max_order,
2811
					   first_nonmergeable_order);
2812
			  try_order
2813
			    = MIN (try_order,
2814
				   merged_store->first_nonmergeable_order);
2815
			  if (try_order > last_order && ++attempts < 16)
2816
			    continue;
2817
			}
2818
		      first_nonmergeable_order
2819
			= MIN (first_nonmergeable_order,
2820
			       first_nonmergeable_int_order);
2821
		      end = this_end;
2822
		      break;
2823
		    }
2777
		    }
2824
		  while (1);
2825
2778
2826
		  if (k != 0)
2779
		  if (k != 0)
2827
		    {
2780
		    {
2828
		      merged_store->merge_overlapping (info);
2781
		      merged_store->merge_overlapping (info);
2829
2782
2830
		      merged_store->first_nonmergeable_order
2831
			= MIN (merged_store->first_nonmergeable_order,
2832
			       first_nonmergeable_order);
2833
2834
		      for (unsigned int j = i + 1; j <= k; j++)
2783
		      for (unsigned int j = i + 1; j <= k; j++)
2835
			{
2784
			{
2836
			  store_immediate_info *info2 = m_store_info[j];
2785
			  store_immediate_info *info2 = m_store_info[j];
Lines 2838-2850 imm_store_chain_info::coalesce_immediate Link Here
2838
			  if (info2->order < last_order)
2787
			  if (info2->order < last_order)
2839
			    {
2788
			    {
2840
			      gcc_assert (info2->rhs_code == INTEGER_CST);
2789
			      gcc_assert (info2->rhs_code == INTEGER_CST);
2841
			      if (info != info2)
2790
			      if (info != info2 && !info2->merged_p)
2842
				merged_store->merge_overlapping (info2);
2791
				merged_store->merge_overlapping (info2);
2843
			    }
2792
			    }
2844
			  /* Other stores are kept and not merged in any
2793
			  /* Other stores are kept and not merged in any
2845
			     way.  */
2794
			     way.  */
2846
			}
2795
			}
2847
		      ignore = k;
2848
		      goto done;
2796
		      goto done;
2849
		    }
2797
		    }
2850
		}
2798
		}

Return to bug 87859