Index: lib/Target/Mips/MipsISelLowering.cpp =================================================================== --- lib/Target/Mips/MipsISelLowering.cpp +++ lib/Target/Mips/MipsISelLowering.cpp @@ -2412,7 +2412,13 @@ // R_MIPS_CALL* operators (emitted when non-internal functions are called // in PIC mode) allow symbols to be resolved via lazy binding. // The lazy binding stub requires GP to point to the GOT. - if (IsPICCall && !InternalLinkage) { + // Note that we don't need GP to point to the GOT for indirect calls + // (i.e. when GlobalOrExternal == false, or equivalently, when R_MIPS_CALL* + // is not used for the call) because Mips linker generates lazy binding stub + // for a function only when R_MIPS_CALL* are the only relocs used for the + // function (that is, Mips linker doesn't generate lazy binding stub for a + // function whose address is taken in the program). + if (IsPICCall && !InternalLinkage && GlobalOrExternal) { unsigned GPReg = Subtarget.isABI_N64() ? Mips::GP_64 : Mips::GP; EVT Ty = Subtarget.isABI_N64() ? MVT::i64 : MVT::i32; RegsToPass.push_back(std::make_pair(GPReg, getGlobalReg(CLI.DAG, Ty))); Index: test/CodeGen/Mips/gpreg-lazy-binding.ll =================================================================== --- test/CodeGen/Mips/gpreg-lazy-binding.ll +++ test/CodeGen/Mips/gpreg-lazy-binding.ll @@ -25,3 +25,11 @@ ret void } +define void @no_lazy(void (i32)* %pf) { + +; CHECK-LABEL: no_lazy +; CHECK-NOT: gp_disp + + tail call void %pf(i32 1) + ret void +} Index: test/CodeGen/Mips/prevent-hoisting.ll =================================================================== --- test/CodeGen/Mips/prevent-hoisting.ll +++ test/CodeGen/Mips/prevent-hoisting.ll @@ -10,16 +10,19 @@ ; CHECK-LABEL: readLumaCoeff8x8_CABAC -; The check for "addiu" instruction is added so that we can match the correct "b" instruction. +; The check for first "addiu" instruction is added so that we can match the correct "b" instruction. ; CHECK: addiu ${{[0-9]+}}, $zero, -1 ; CHECK: b $[[BB0:BB[0-9_]+]] +; CHECK-NEXT: addiu ${{[0-9]+}}, $zero, 0 -; Check that sll instruction that writes to $1 starts basic block. -; CHECK: {{BB[0-9_#]+}}: +; Check that at the start of a fallthrough block there is a instruction that writes to $1. +; CHECK-NEXT: {{BB[0-9_#]+}}: +; CHECK-NEXT: lw $[[R1:[0-9]+]], %got(assignSE2partition)($[[R2:[0-9]+]]) ; CHECK-NEXT: sll $1, $[[R0:[0-9]+]], 4 -; Check that identical sll instruction starts another basic block. +; Check that identical instructions are at the start of a target block. ; CHECK: [[BB0]]: +; CHECK-NEXT: lw $[[R1]], %got(assignSE2partition)($[[R2]]) ; CHECK-NEXT: sll $1, $[[R0]], 4