[llvm] [PowerPC] using milicode call for strlen instead of lib call (PR #153600)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 09:24:34 PDT 2025


================
@@ -9050,6 +9050,42 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
   return TLI->LowerCallTo(CLI);
 }
 
+std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
+                                                    const SDLoc &dl,
+                                                    SDValue Src,
+                                                    const CallInst *CI) {
+  const char *LibCallName = TLI->getLibcallName(RTLIB::STRLEN);
+  if (!LibCallName)
+    return {};
+
+  // Emit a library call.
+  auto GetEntry = [](Type *Ty, SDValue &SDV) {
+    TargetLowering::ArgListEntry E;
+    E.Ty = Ty;
+    E.Node = SDV;
+    return E;
+  };
+
+  PointerType *PT = PointerType::getUnqual(*getContext());
+  TargetLowering::ArgListTy Args = {GetEntry(PT, Src)};
+
+  TargetLowering::CallLoweringInfo CLI(*this);
+  bool IsTailCall = false;
+  bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
+  IsTailCall = CI && CI->isTailCall() &&
+               isInTailCallPosition(*CI, getTarget(), ReturnsFirstArg);
+
+  CLI.setDebugLoc(dl)
+      .setChain(Chain)
+      .setLibCallee(
+          TLI->getLibcallCallingConv(RTLIB::STRLEN), CI->getType(),
+          getExternalSymbol(LibCallName, TLI->getPointerTy(getDataLayout())),
----------------
arsenm wrote:

```suggestion
          getExternalSymbol(LibCallName, TLI->getProgramPointerTy(getDataLayout())),
```

https://github.com/llvm/llvm-project/pull/153600


More information about the llvm-commits mailing list