GAP Message - remark #30755: (DTRANS) Reordering the fields of the structure ...

Message

Reordering the fields of the structure 'str' will improve data locality. Suggested field order: 'a1, c1, e1'. [VERIFY] The suggestion is based on the field references in the current compilation. Please make sure that the restructured code satisfies the original program semantics.
Applies to C/C++ only

Description

You should reorder the fields of the class or structure type in the specified order. This should improve performance by better utilizing the processor cache. You must verify that the application code does not rely on the structure fields to be laid out in a specific order. For example, if the application code uses the address of a field to access other fields, it may stop working once the field reordering is applied. Note also that such code is not considered valid.

Example

//field_reord.c
struct str {
    int a1, b1, carr[100], c1, d1, e1;
};

extern struct str sp[];

int hot_func1() {
    int i, ret = 0;

    for (i = 0; i < 1000000; i++) {
        ret += sp[i].a1;
        ret += sp[i].c1;
    }
    return ret;
}

int hot_func2() {
    int ret = 0, i;
    for (i = 0; i < 100000; i++) {
        ret += sp[i].a1;
        ret -= sp[i].e1;
    }
    return ret;
}

int hot_func3() {
    int ret = 0, i;
    for (i = 0; i < 1000000; i++) {
        ret += sp[i].carr[10];
    }
    return ret + sp[0].b1 + sp[0].d1;
}

For the above example, the compiler generates the following advice with
'icl -Qguide -c field_reord.c'

 

field_reord.c(2): remark #30755: (DTRANS) Reordering the fields of the structure 'str' will improve data locality. Suggested field order: 'a1, c1, e1, carr, b1, d1'. [VERIFY] The suggestion is based on the field references in the current compilation. Please make sure that the restructured code satisfies the original program semantics.

 

For the above example, the only changes in field_reord.c to reorder fields of the structure 'str' as advised are the following:

//field_reord.c
struct str {
    int a1, c1, e1, carr[100], b1, d1;
};
...
...

Optimization Notice in English

Pour de plus amples informations sur les optimisations de compilation, consultez notre Avertissement concernant les optimisations.
Étiquettes: