Type-Based Alias Analysis
by Mark Mitchell

Example 1: 
int i;
int *ip1 = &i;
int *ip2 = &i;

Example 2: 
(a) 
void f (int ip1[], int ip2[]) {
  int i;
  for (i = 0; i < 9; ++i) {
    ip1[i + 1] = ip2[i] + ip2[i + 1];
  }
}

(b) 
LOAD r1, ip2[0]
LOAD r2, ip2[1]
ADD r3, r1, r2   # Add ip2[0] and ip2[1].
STORE ip1[1], r3 # Store result in ip1[1].
LOAD r1, ip2[2]
ADD r3, r1, r2   # Add ip2[1] and ip2[2].
STORE ip1[2], r3 # Store result in ip1[2].
LOAD r2, ip2[3]
ADD r3, r1, r2   # Add ip2[2] and ip2[3].
STORE ip1[3], r3 # Store result in ip1[3].
 ...

(c) 
LOAD r1, ip2[0]
LOAD r2, ip2[1]
ADD r3, r1, r2   # Add ip2[0] and ip2[1].
STORE ip1[1], r3 # Store result in ip1[1].
LOAD r1, ip2[1]
LOAD r2, ip2[2]
ADD r3, r1, r2   # Add ip2[1] and ip2[2].
STORE ip1[2], r3 # Store result in ip1[2].
LOAD r1, ip2[2]
LOAD r2, ip2[3]
ADD r3, r1, r2   # Add ip2[2] and ip2[3].
STORE ip1[3], r3 # Store result in ip1[3].
 ...

Example 3: 
void g () {
  int ia[10];
  ...
  f(ia, ia);
}

Example 4: 
int f() {
  int i;
  int j;
  int k;
  int *ip = &i;
  j = 2
  for (k = 0; k < 10; ++k) {
    g(ip);
    j += i;
  }
  return j;
}

Example 5: 

(a) 
void f(int* p) {
  for (int i = 0; i < 10; ++i) {
    g(p);
    h(*p);
  }
}

(b) 
void f(int* p) {
  int x = *p;
  for (int i = 0; i < 10; ++i)  {
    g(p);
    h(x);
  }
}


Example 6: 

(a) 
double d = 3.0;
int* ip = (int*) &d;
*ip = 7;

(b) 
double d = 3.0;
char* cp = (char*) &d;
*cp = 7;


Example 7: 
(a) 
double  u_m;
double  v_m;

typedef struct s {
  int     n_m;
  double* x_m;
  double* a_m;
  double* b_m;
} s;
void f(struct s* s)
{
  int i;
  for (i=0; i < s->n_m; ++i)
    s->x_m[i] = (u_m * s->a_m[i]) + (v_m * s->b_m[i]);
}

(b) 
 .L9:
      sll     $3,$5,3       # Multiply i by 8
      addu    $2,$3,$2      # Compute the address of s->a_m[i]
      l.d     $f1,0($2)     # Load s->a_m[i]
      mul.d   $f1,$f3,$f1   # Multiply u_m * s->a_m[i]
      lw      $2,12($4)     # Load s->b_m
      addu    $2,$3,$2      # Compute the address of s->b_m[i]
      l.d     $f0,0($2)     # Load s->b_m[i]
      mul.d   $f0,$f2,$f0   # Multiply v_m * s->b_m[i]
      lw      $2,4($4)      # Load s->x_m
      add.d   $f1,$f1,$f0   # Add (u_m * s->a_m[i]) + (v_m * s->b_m[i])
      addu    $3,$3,$2      # Compute the address of s->x_m[i]
      s.d     $f1,0($3)     # Store the sum into s->x_m[i]
      lw      $2,0($4)      # Load s->n_m
      addu    $5,$5,1       # Increment i
      slt     $2,$5,$2      # Subtract s->n_m from i
      bnel    $2,$0,.L9     # If i < s->n_m goto .L9
      lw      $2,8($4)      # Load s->a_m

(c) 
 .L6:
      l.d     $f1,0($4)    # Load s->a_m[i]
      mul.d   $f1,$f3,$f1  # Multiply u_m * s->a_m[i]
      l.d     $f0,0($3)    # Load s->b_m[i]
      mul.d   $f0,$f2,$f0  # Multiply v_m * s->b_m[i]
      add.d   $f1,$f1,$f0  # Add (u_m * s->a_m[i]) + (v_m * s->b_m[i])
      addu    $3,$3,8      # Increment pointer to s->b_m[i]
      addu    $4,$4,8      # Increment pointer to s->a_m[i]
      addu    $2,$2,-1     # Decrement i
      s.d     $f1,0($5)    # Store the sum into s->x_m[i]
      bne     $2,$0,.L6    # If i < s->n_m goto .L6
      addu    $5,$5,8      # Increment pointer to s->x_m[i]

Example 8: 
(a) 
double d = 2.0;
int *ip = (int*) &d;
*ip = 3;
d *= 2;

(b) 
double d = 2.0;
int *ip = (int*) &d;
d *= 2;
*ip = 3;

Example 9: 

(a) 
typedef struct list_node {
  void* data; /* The data itself.  */
  struct list_node* next; /* The next element in the list.  */
} list_node;

(b) 
if ((int) x->next->data > 7)
  y->next = y->next->next;
if ((int) x->next->data % 2 == 0)
  x->data = ((int) x->data) + 4;


Example 10: 
(a) 
template <typename T>
struct list_node {
  T* data; // The data itself.
  list_node* next; // The next element in the list.
};

(b) 
if (x->next->data > 7)
  y->next = y->next->next;
if (x->next->data % 2 == 0)
  x->data = x->data + 4;



4

