This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]Fix computation of offset in ivopt


Hi,
This patch fix two minor bugs when computing offset in IVOPT.
1) Considering below example:
#define MAX 100
struct tag
{
  int i;
  int j;
}
struct tag arr[MAX]

int foo (int len)
{
  int i = 0;
  for (; i < len; i++)
  {
    access arr[i].j;
  }
}

Without this patch, the offset computed by strip_offset_1 for address
arr[i].j is ZERO, which is apparently not.

2) Considering below example:
//...
  <bb 15>:
  KeyIndex_66 = KeyIndex_194 + 4294967295;
  if (KeyIndex_66 != 0)
    goto <bb 16>;
  else
    goto <bb 18>;

  <bb 16>:

  <bb 17>:
  # KeyIndex_194 = PHI <KeyIndex_66(16), KeyIndex_180(73)>
  _62 = KeyIndex_194 + 1073741823;
  _63 = _62 * 4;
  _64 = pretmp_184 + _63;
  _65 = *_64;
  if (_65 == 0)
    goto <bb 15>;
  else
    goto <bb 71>;
//...

There are iv use and candidate like:

use 1
  address
  in statement _65 = *_64;

  at position *_64
  type handletype *
  base pretmp_184 + ((sizetype) KeyIndex_180 + 1073741823) * 4
  step 4294967292
  base object (void *) pretmp_184
  related candidates 

candidate 6
  var_before ivtmp.16
  var_after ivtmp.16
  incremented before use 1
  type unsigned int
  base (unsigned int) (pretmp_184 + (sizetype) KeyIndex_180 * 4)
  step 4294967292
  base object (void *) pretmp_184
Candidate 6 is related to use 1

In function get_computation_cost_at for use 1 using cand 6, ubase and cbase
are:
pretmp_184 + ((sizetype) KeyIndex_180 + 1073741823) * 4
pretmp_184 + (sizetype) KeyIndex_180 * 4

The cstepi computed in HOST_WIDE_INT is :  0xfffffffffffffffc, while offset
computed in TYPE(utype) is : 0xfffffffc.  Though they both stand for value
"-4" in different precision, statement "offset -= ratio * cstepi" returns
0x100000000, which is wrong.

Tested on x86_64 and arm.  Is it OK?

Thanks.
bin


2013-09-24  Bin Cheng  <bin.cheng@arm.com>

	* tree-ssa-loop-ivopts.c (strip_offset_1): Count
	DECL_FIELD_BIT_OFFSET when computing offset for COMPONENT_REF.
	(get_computation_cost_at): Sign extend offset.

Attachment: 1-ivopt-offset-20130724.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]