@@ -8977,14 +8977,16 @@ static SDValue getLargeExternalSymbol(ExternalSymbolSDNode *N, const SDLoc &DL,
89778977template <class NodeTy>
89788978SDValue RISCVTargetLowering::getAddr(NodeTy *N, EVT Ty, SelectionDAG &DAG,
89798979 bool IsLocal, bool CanDeriveFromPcc,
8980- bool IsExternWeak) const {
8980+ bool IsExternWeak,
8981+ const GlobalValue *GV) const {
89818982 SDLoc DL(N);
89828983
89838984 if (RISCVABI::isCheriPureCapABI(Subtarget.getTargetABI())) {
89848985 bool IsCheriot = Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT ||
89858986 Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT_BAREMETAL;
89868987 SDValue Addr = getTargetNode(N, DL, Ty, DAG, 0);
8987- if ((IsLocal && CanDeriveFromPcc) || IsCheriot) {
8988+ bool NotHighUseGV = !GV || GV->getNumUses() < 4;
8989+ if ((IsLocal && CanDeriveFromPcc) || (IsCheriot && NotHighUseGV)) {
89888990 // Use PC-relative addressing to access the symbol. This generates the
89898991 // pattern (PseudoCLLC sym), which expands to
89908992 // (cincoffsetimm (auipcc %pcrel_hi(sym)) %pcrel_lo(auipc)).
@@ -9121,7 +9123,7 @@ SDValue RISCVTargetLowering::lowerGlobalAddress(SDValue Op,
91219123 }
91229124
91239125 return getAddr(N, Ty, DAG, GV->isDSOLocal(), /*CanDeriveFromPcc=*/false,
9124- GV->hasExternalWeakLinkage());
9126+ GV->hasExternalWeakLinkage(), GV );
91259127}
91269128
91279129SDValue RISCVTargetLowering::lowerBlockAddress(SDValue Op,
0 commit comments