llvm.org GIT mirror llvm / 5bd1dfa
[PowerPC] Fix problems with large code model (PR17169). Large code model on PPC64 requires creating and referencing TOC entries when using the addis/ld form of addressing. This was not being done in all cases. The changes in this patch to PPCAsmPrinter::EmitInstruction() fix this. Two test cases are also modified to reflect this requirement. Fast-isel was not creating correct code for loading floating-point constants using large code model. This also requires the addis/ld form of addressing. Previously we were using the addis/lfd shortcut which is only applicable to medium code model. One test case is modified to reflect this requirement. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190882 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Schmidt 6 years ago
5 changed file(s) with 34 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
412412 else if (MO.isJTI())
413413 MOSymbol = GetJTISymbol(MO.getIndex());
414414
415 if (IsExternal || IsFunction || IsCommon || IsAvailExt || MO.isJTI())
415 if (IsExternal || IsFunction || IsCommon || IsAvailExt || MO.isJTI() ||
416 TM.getCodeModel() == CodeModel::Large)
416417 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
417418
418419 const MCExpr *Exp =
437438
438439 if (MO.isJTI())
439440 MOSymbol = lookUpOrCreateTOCEntry(GetJTISymbol(MO.getIndex()));
440 else if (MO.isCPI())
441 else if (MO.isCPI()) {
441442 MOSymbol = GetCPISymbol(MO.getIndex());
443 if (TM.getCodeModel() == CodeModel::Large)
444 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
445 }
442446 else if (MO.isGlobal()) {
443447 const GlobalValue *GValue = MO.getGlobal();
444448 const GlobalAlias *GAlias = dyn_cast(GValue);
448452 const GlobalVariable *GVar = dyn_cast(RealGValue);
449453
450454 if (!GVar || !GVar->hasInitializer() || RealGValue->hasCommonLinkage() ||
451 RealGValue->hasAvailableExternallyLinkage())
455 RealGValue->hasAvailableExternallyLinkage() ||
456 TM.getCodeModel() == CodeModel::Large)
452457 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
453458 }
454459
485490 } else if (MO.isCPI())
486491 MOSymbol = GetCPISymbol(MO.getIndex());
487492
488 if (IsFunction || IsExternal)
493 if (IsFunction || IsExternal || TM.getCodeModel() == CodeModel::Large)
489494 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
490495
491496 const MCExpr *Exp =
18201820 // Otherwise we generate LF[SD](Idx[lo], ADDIStocHA(X2, Idx)).
18211821 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(PPC::ADDIStocHA),
18221822 TmpReg).addReg(PPC::X2).addConstantPoolIndex(Idx);
1823 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
1824 .addConstantPoolIndex(Idx, 0, PPCII::MO_TOC_LO)
1825 .addReg(TmpReg)
1826 .addMemOperand(MMO);
1823 // But for large code model, we must generate a LDtocL followed
1824 // by the LF[SD].
1825 if (CModel == CodeModel::Large) {
1826 unsigned TmpReg2 = createResultReg(&PPC::G8RC_and_G8RC_NOX0RegClass);
1827 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(PPC::LDtocL),
1828 TmpReg2).addConstantPoolIndex(Idx).addReg(TmpReg);
1829 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
1830 .addImm(0).addReg(TmpReg2);
1831 } else
1832 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
1833 .addConstantPoolIndex(Idx, 0, PPCII::MO_TOC_LO)
1834 .addReg(TmpReg)
1835 .addMemOperand(MMO);
18271836 }
18281837
18291838 return DestReg;
3030 ; LARGE: ld [[REG2:[0-9]+]], [[VAR]]@toc@l([[REG1]])
3131 ; LARGE: lwz {{[0-9]+}}, 0([[REG2]])
3232 ; LARGE: stw {{[0-9]+}}, 0([[REG2]])
33 ; LARGE: .type [[VAR]],@object
34 ; LARGE: .local [[VAR]]
35 ; LARGE: .comm [[VAR]],4,4
33 ; LARGE: [[VAR]]:
34 ; LARGE: .tc [[VAR2:[a-z0-9A-Z_.]+]][TC],[[VAR2]]
35 ; LARGE: .type [[VAR2]],@object
36 ; LARGE: .local [[VAR2]]
37 ; LARGE: .comm [[VAR2]],4,4
3638
3232 ; LARGE: ld [[REG2:[0-9]+]], [[VAR]]@toc@l([[REG1]])
3333 ; LARGE: lwz {{[0-9]+}}, 0([[REG2]])
3434 ; LARGE: stw {{[0-9]+}}, 0([[REG2]])
35 ; LARGE: .type [[VAR]],@object
35 ; LARGE: [[VAR]]:
36 ; LARGE: .tc [[VAR2:[a-z0-9A-Z_.]+]][TC],[[VAR2]]
37 ; LARGE: .type [[VAR2]],@object
3638 ; LARGE: .data
37 ; LARGE: .globl [[VAR]]
38 ; LARGE: [[VAR]]:
39 ; LARGE: .globl [[VAR2]]
40 ; LARGE: [[VAR2]]:
3941 ; LARGE: .long 5
4042
2121 ; LARGE: [[VAR:[a-z0-9A-Z_.]+]]:
2222 ; LARGE: .quad 4562098671269285104
2323 ; LARGE-LABEL: test_double_const:
24 ; LARGE: addis [[REG1:[0-9]+]], 2, [[VAR]]@toc@ha
25 ; LARGE: ld [[REG2:[0-9]+]], [[VAR]]@toc@l([[REG1]])
24 ; LARGE: addis [[REG1:[0-9]+]], 2, [[VAR2:[a-z0-9A-Z_.]+]]@toc@ha
25 ; LARGE: ld [[REG2:[0-9]+]], [[VAR2]]@toc@l([[REG1]])
2626 ; LARGE: lfd {{[0-9]+}}, 0([[REG2]])