Index: llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -7097,6 +7097,8 @@ case PPC::ADDItocL: Flags = PPCII::MO_TOC_LO; break; + case PPC::ADDItoc: + break; } SDValue ImmOpnd = Base.getOperand(1); @@ -7192,9 +7194,18 @@ } if (FirstOp == 1) // Store - (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd, - Base.getOperand(0), N->getOperand(3)); + if (Base.getMachineOpcode() == PPC::ADDItoc) + (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), + Base.getOperand(0), Base.getOperand(1), + N->getOperand(3)); + else + (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd, + Base.getOperand(0), N->getOperand(3)); else // Load + if (Base.getMachineOpcode() == PPC::ADDItoc) + (void)CurDAG->UpdateNodeOperands(N, Base.getOperand(0), + Base.getOperand(1), N->getOperand(2)); + else (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.getOperand(0), N->getOperand(2)); Index: llvm/lib/Target/PowerPC/PPCMCInstLower.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCMCInstLower.cpp +++ llvm/lib/Target/PowerPC/PPCMCInstLower.cpp @@ -42,6 +42,11 @@ Mangler::getNameWithPrefix(Name, MO.getSymbolName(), DL); } else { const GlobalValue *GV = MO.getGlobal(); + + if (const GlobalVariable *GVar = dyn_cast(GV)) + if (GVar->hasAttribute("toc-data")) + return AP.getSymbol(GV); + TM.getNameWithPrefix(Name, GV, Mang); } Index: llvm/test/CodeGen/PowerPC/toc-data.ll =================================================================== --- llvm/test/CodeGen/PowerPC/toc-data.ll +++ llvm/test/CodeGen/PowerPC/toc-data.ll @@ -14,12 +14,11 @@ ret void } ; CHECK: name: write_int -; CHECK: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @i, $r2 -; CHECK-NEXT: STW %{{[0-9]+}}, 0, killed %[[SCRATCH]] :: (store 4 into @i) +; CHECK: %[[SCRATCH:[0-9]+]]:gprc = COPY $r3 +; CHECK-NEXT: STW %{{[0-9]+}}, @i, $r2 :: (store 4 into @i) ; TEST: .write_int: -; TEST: la 4, i[TD](2) -; TEST-NEXT: stw 3, 0(4) +; TEST: stw 3, i[TD](2) define dso_local i64 @read_ll() { entry: @@ -40,12 +39,10 @@ ret float %0 } ; CHECK: name: read_float -; CHECK: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @f, $r2 -; CHECK: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]] :: (dereferenceable load 4 from @f) +; CHECK: %{{[0-9]+}}:f4rc = LFS @f, $r2 :: (dereferenceable load 4 from @f) ; TEST: .read_float: -; TEST: la 3, f[TD](2) -; TEST-NEXT: lfs 1, 0(3) +; TEST: lfs 1, f[TD](2) define dso_local void @write_double(double %in) { entry: