[PATCH] D39871: [arm] Fix Unnecessary reloads from GOT.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 15:26:30 PST 2017


eugenis added inline comments.


================
Comment at: llvm/lib/Target/ARM/ARMISelLowering.cpp:3168
     bool UseGOT_PREL = !TM.shouldAssumeDSOLocal(*GV->getParent(), GV);
-
-    MachineFunction &MF = DAG.getMachineFunction();
-    ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
-    unsigned ARMPCLabelIndex = AFI->createPICLabelUId();
-    EVT PtrVT = getPointerTy(DAG.getDataLayout());
-    SDLoc dl(Op);
-    unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
-    ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(
-        GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj,
-        UseGOT_PREL ? ARMCP::GOT_PREL : ARMCP::no_modifier,
-        /*AddCurrentAddress=*/UseGOT_PREL);
-    SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
-    CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
-    SDValue Result = DAG.getLoad(
-        PtrVT, dl, DAG.getEntryNode(), CPAddr,
-        MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
-    SDValue Chain = Result.getValue(1);
-    SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32);
-    Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
+    SDValue G = DAG.getTargetGlobalAddress(GV, dl, PtrVT);
+    SDValue Result = DAG.getNode(ARMISD::WrapperPIC, dl, PtrVT, G);
----------------
efriedma wrote:
> If I'm following correctly, whether "G" points to the global itself or the GOT entry is implicitly controlled by ARMSubtarget::getCPModifier?  That's awfully confusing... can we fix it to use target flags passed to getTargetGlobalAddress() to control it instead?
Yes... That's not ideal.

To make sure we are on the same page: I could add something like ARMII::MO_GOT to TargetGlobalAddress flags, and use to differentiate between LDRLIT_ga_pcrel and MOV_ga_pcrel. This would let us use movt/movw for dso-local globals, yay! 

I'm not sure how to access the flag in ARMExpandPseudoInsts, though. Is it copied to the operand's TargetFlags? I'll check.


Repository:
  rL LLVM

https://reviews.llvm.org/D39871





More information about the llvm-commits mailing list