Using this pointer causes strange deoptimization in hot loop

前端 未结 3 1579
清酒与你
清酒与你 2020-12-07 11:55

I recently came across a strange deoptimization (or rather missed optimization opportunity).

Consider this function for efficient unpacking of arrays of 3-bit intege

3条回答
  •  旧时难觅i
    2020-12-07 12:39

    Strict aliasing rules allows char* to alias any other pointer. So this->target may alias with this, and in your code method, the first part of the code,

    target[0] = t & 0x7;
    target[1] = (t >> 3) & 0x7;
    target[2] = (t >> 6) & 0x7;
    

    is in fact

    this->target[0] = t & 0x7;
    this->target[1] = (t >> 3) & 0x7;
    this->target[2] = (t >> 6) & 0x7;
    

    as this may be modified when you modify this->target content.

    Once this->target is cached into a local variable, the alias is no longer possible with the local variable.

提交回复
热议问题