Skip to content

PowerPC: Stop reporting memcpy as an alias of memmove on AIX #143836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3572,6 +3572,8 @@ class LLVM_ABI TargetLoweringBase {
return Libcalls.getLibcallName(Call);
}

const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }

/// Override the default CondCode to be used to test the result of the
/// comparison libcall against zero.
/// FIXME: This should be removed
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ struct RuntimeLibcallsInfo {
SoftFloatCompareLibcallPredicates[Call] = Pred;
}

/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
/// unsupported.
const char *getMemcpyName() const {
if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
return Memcpy;

// Fallback to memmove if memcpy isn't available.
return getLibcallName(RTLIB::MEMMOVE);
}

private:
/// Stores the name each libcall.
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr};
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,26 +672,30 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
RTLIB::Libcall RTLibcall;
unsigned Opc = MI.getOpcode();
const char *Name;
switch (Opc) {
case TargetOpcode::G_BZERO:
RTLibcall = RTLIB::BZERO;
Name = TLI.getLibcallName(RTLibcall);
break;
case TargetOpcode::G_MEMCPY:
RTLibcall = RTLIB::MEMCPY;
Name = TLI.getMemcpyName();
Args[0].Flags[0].setReturned();
break;
case TargetOpcode::G_MEMMOVE:
RTLibcall = RTLIB::MEMMOVE;
Name = TLI.getLibcallName(RTLibcall);
Args[0].Flags[0].setReturned();
break;
case TargetOpcode::G_MEMSET:
RTLibcall = RTLIB::MEMSET;
Name = TLI.getLibcallName(RTLibcall);
Args[0].Flags[0].setReturned();
break;
default:
llvm_unreachable("unsupported opcode");
}
const char *Name = TLI.getLibcallName(RTLibcall);

// Unsupported libcall on the target.
if (!Name) {
Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ static bool canEmitLibcall(const TargetMachine *TM, Function *F,
return TLI->getLibcallName(LC) != nullptr;
}

static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
// TODO: Should this consider the address space of the memcpy?
if (!TM)
return true;
const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
return TLI->getMemcpyName() != nullptr;
}

// Return a value appropriate for use with the memset_pattern16 libcall, if
// possible and if we know how. (Adapted from equivalent helper in
// LoopIdiomRecognize).
Expand Down Expand Up @@ -300,8 +308,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
Function *ParentFunc = Memcpy->getFunction();
const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
if (UseMemIntrinsicLibFunc &&
canEmitLibcall(TM, ParentFunc, RTLIB::MEMCPY))
if (UseMemIntrinsicLibFunc && canEmitMemcpy(TM, ParentFunc))
break;

// TODO: For optsize, emit the loop into a separate function
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8776,11 +8776,12 @@ SDValue SelectionDAG::getMemcpy(
// FIXME: pass in SDLoc
TargetLowering::CallLoweringInfo CLI(*this);
bool IsTailCall = false;
const char *MemCpyName = TLI->getMemcpyName();

if (OverrideTailCall.has_value()) {
IsTailCall = *OverrideTailCall;
} else {
bool LowersToMemcpy =
TLI->getLibcallName(RTLIB::MEMCPY) == StringRef("memcpy");
bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy");
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
IsTailCall = CI && CI->isTailCall() &&
isInTailCallPosition(*CI, getTarget(),
Expand All @@ -8789,11 +8790,11 @@ SDValue SelectionDAG::getMemcpy(

CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(TLI->getLibcallCallingConv(RTLIB::MEMCPY),
Dst.getValueType().getTypeForEVT(*getContext()),
getExternalSymbol(TLI->getLibcallName(RTLIB::MEMCPY),
TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setLibCallee(
TLI->getLibcallCallingConv(RTLIB::MEMCPY),
Dst.getValueType().getTypeForEVT(*getContext()),
getExternalSymbol(MemCpyName, TLI->getPointerTy(getDataLayout())),
std::move(Args))
.setDiscardResult()
.setTailCall(IsTailCall);

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,

if (TT.isOSAIX()) {
bool isPPC64 = TT.isPPC64();
setLibcallName(RTLIB::MEMCPY, isPPC64 ? "___memmove64" : "___memmove");
setLibcallName(RTLIB::MEMCPY, nullptr);
setLibcallName(RTLIB::MEMMOVE, isPPC64 ? "___memmove64" : "___memmove");
setLibcallName(RTLIB::MEMSET, isPPC64 ? "___memset64" : "___memset");
setLibcallName(RTLIB::BZERO, isPPC64 ? "___bzero64" : "___bzero");
Expand Down
Loading