I created a struct array, and here is my source code.
#include <stdio.h>
#include <stdlib.h>
#define N 256
typedef struct arc {
int num;
} arc_t;
typedef double cost_t;
typedef struct basket {
arc_t *a;
cost_t cost;
} BASKET;
static BASKET basket[N];
static BASKET *perm[N];
int main() {
__asm__ ("########");
int j;
for ( j = 0; j < N; j++)
{
perm[j] = &(basket[j]) ;
}
__asm__ ("########");
printf("%d\n",perm[1]->a->num);
return 0;
}
At this point, I have defined an integer variable "j." When using the command gcc -O3 p.c -fdump-tree-vect-details -fopt-info-vec -S -mavx2
to print intermediate files, in the generated intermediate file at the location of my marker (asm ("########");), there is the following content:
<bb 2> [local count: 10737416]:
__asm__ __volatile__("########");
vect_cst__13 = { 8, 8, 8, 8, 8, 8, 8, 8 };
vect_cst__22 = { 16, 16, 16, 16, 16, 16, 16, 16 };
_27 = (long unsigned int) &basket;
vect_cst__28 = {_27, _27, _27, _27};
However, when I define "long j," it results in the following intermediate file:
<bb 2> [local count: 10737416]:
__asm__ __volatile__("########");
vect_cst__14 = { 4, 4, 4, 4 };
vect_cst__19 = { 16, 16, 16, 16 };
_23 = (long unsigned int) &basket;
vect_cst__24 = {_23, _23, _23, _23};
This is a part of the difference, but what confuses me the most is that, with Peter Cordes's assistance, we speculated that the difference in the intermediate code might be due to the distinct sizes of int and long data types.
But j
is just an array index, so why would its data type have this impact? I've printed the first four addresses of "basket[j]" in both cases of int j
and long j
, and they are the same. The gcc version is 10.3.0
Since there are differences in the intermediate files at this point, I suspect that different optimizations might have been applied by the front-end compiler. Where should I look for information related to this? How does GCC analyze struct arrays?