HomePhabricator

[mips] Reduce number of instructions used for loading a global symbol's value

Description

[mips] Reduce number of instructions used for loading a global symbol's value

Now lw/sw $reg, sym+offset pseudo instructions for global symbol sym
are lowering into the following three instructions.

lw     $reg, %got(symbol)($gp)
addiu  $reg, $reg, offset
lw/sw  $reg, 0($reg)

It's possible to reduce the number of instructions by taking the offset
in account in the final lw/sw command. This patch implements that
optimization.

lw     $reg, %got(symbol)($gp)
lw/sw  $reg, offset($reg)

Differential Revision: https://reviews.llvm.org/D66553