Using this pointer causes strange deoptimization in hot loop

前端 未结 3 1573
清酒与你
清酒与你 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条回答
  •  一向
    一向 (楼主)
    2020-12-07 12:39

    Pointer aliasing seems to be the problem, ironically between this and this->target. The compiler is taking into account the rather obscene possibility that you initialized:

    this->target = &this

    In that case, writing to this->target[0] would alter the contents of this (and thus, this->target).

    The memory aliasing problem is not restricted to the above. In principle, any use of this->target[XX] given an (in)appropriate value of XX might point to this.

    I am better versed in C, where this can be remedied by declaring pointer variables with the __restrict__ keyword.

提交回复
热议问题