This is an archive of the discontinued LLVM Phabricator instance.

[mips] Fix expanding `lw/sw $reg1, symbol($reg2)` instruction
ClosedPublic

Authored by atanasyan on Aug 28 2019, 9:54 AM.

Details

Summary

When a "base" in the lw/sw $reg1, symbol($reg2) instruction is a register and generated code is position independent, backend does not add the "base" value to the symbol address.

lw     $reg1, %got(symbol)($gp)
lw/sw  $reg1, 0($reg1)

This patch fixes the bug and adds the missed addu instruction by passing BaseReg into the loadAndAddSymbolAddress routine and handles the case when the BaseReg is the zero register to escape redundant move reg, reg instruction:

lw     $reg1, %got(symbol)($gp)
addu   $reg1, $reg1, $reg2
lw/sw  $reg1, 0($reg1)

Diff Detail

Event Timeline

atanasyan created this revision.Aug 28 2019, 9:54 AM
This revision is now accepted and ready to land.Aug 29 2019, 3:37 AM
This revision was automatically updated to reflect the committed changes.