Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -2476,10 +2476,22 @@ TmpReg = ATReg; } - emitRX(Mips::LUi, TmpReg, MCOperand::createExpr(HiExpr), IDLoc, Instructions); - emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), IDLoc, - Instructions); - + const MCSymbol *Sym = getSingleMCSymbol(SymExpr); + + if (inPicMode()) { + const MCExpr *Got16RelocExpr = evaluateRelocExpr(SymExpr, "got"); + emitRRX(Mips::LW, TmpReg, Mips::GP, MCOperand::createExpr(Got16RelocExpr), + IDLoc, Instructions); + if(Sym->isInSection() && !Sym->isExternal()) + emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), + IDLoc, Instructions); + } else { + emitRX(Mips::LUi, TmpReg, MCOperand::createExpr(HiExpr), IDLoc, + Instructions); + emitRRX(Mips::ADDiu, TmpReg, TmpReg, MCOperand::createExpr(LoExpr), IDLoc, + Instructions); + } + if (UseSrcReg) emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, Instructions); else Index: test/MC/Mips/la.pic.s =================================================================== --- test/MC/Mips/la.pic.s +++ test/MC/Mips/la.pic.s @@ -0,0 +1,29 @@ +# RUN: llvm-mc %s -triple=mipsel-unknown-linux -mcpu=mips32 -show-encoding -relocation-model=pic | FileCheck %s -check-prefix=CHECK-PIC + +la $5, symbol # CHECK-PIC: lw $5, %got(symbol)($gp) # encoding: [A,A,0x85,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: symbol@GOT, kind: fixup_Mips_GOT_Local +la $5, symbol($6) # CHECK-PIC: lw $5, %got(symbol)($gp) # encoding: [A,A,0x85,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: symbol@GOT, kind: fixup_Mips_GOT_Local + # CHECK-PIC: addu $5, $5, $6 # encoding: [0x21,0x28,0xa6,0x00] +la $6, symbol($6) # CHECK-PIC: lw $1, %got(symbol)($gp) # encoding: [A,A,0x81,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: symbol@GOT, kind: fixup_Mips_GOT_Local + # CHECK-PIC: addu $6, $1, $6 # encoding: [0x21,0x30,0x26,0x00] +la $4, foo + # CHECK-PIC: lw $4, %got(foo)($gp) # encoding: [A,A,0x84,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: foo@GOT, kind: fixup_Mips_GOT_Local +dl: +la $5, + # CHECK-PIC: lw $5, %got(dl)($gp) # encoding: [A,A,0x85,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: dl@GOT, kind: fixup_Mips_GOT_Local + # CHECK-PIC: addiu $5, $5, %lo(dl) # encoding: [A,A,0xa5,0x24] + # CHECK-PIC: # fixup A - offset: 0, value: %lo(dl), kind: fixup_Mips_LO16 +.globl dg +dg: +la $5, dg + # CHECK-PIC: lw $5, %got(dg)($gp) # encoding: [A,A,0x85,0x8f] + # CHECK-PIC: # fixup A - offset: 0, value: dg@GOT, kind: fixup_Mips_GOT_Local + # CHECK-PIC: addiu $5, $5, %lo(dg) # encoding: [A,A,0xa5,0x24] + # CHECK-PIC: # fixup A - offset: 0, value: %lo(dg), kind: fixup_Mips_LO16 + + +