[llvm] [PowerPC] using milicode call for strcmp instead of lib call (PR #177009)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 26 06:48:42 PST 2026
https://github.com/diggerlin updated https://github.com/llvm/llvm-project/pull/177009
>From d5c23a38e2fa6b4ac09437d843579fb48d25436c Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Fri, 16 Jan 2026 14:59:03 +0000
Subject: [PATCH 1/4] implement milicode strcmp
---
llvm/include/llvm/CodeGen/SelectionDAG.h | 6 ++++++
llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h | 9 ++++-----
llvm/include/llvm/IR/RuntimeLibcalls.td | 2 ++
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 10 ++++++++++
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 8 +++-----
llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp | 7 +++++++
llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h | 5 ++++-
llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp | 4 ++--
llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h | 9 ++++-----
llvm/test/CodeGen/PowerPC/milicode32.ll | 2 +-
llvm/test/CodeGen/PowerPC/milicode64.ll | 3 ++-
11 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index a208481df0c70..44761f4294e86 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -1291,6 +1291,12 @@ class SelectionDAG {
SDValue Size,
const CallInst *CI);
+ /// Lower a strcmp operation into a target library call and return the
+ /// resulting chain and call result as SelectionDAG SDValues.
+ LLVM_ABI std::pair<SDValue, SDValue> getStrcmp(SDValue Chain, const SDLoc &dl,
+ SDValue S0, SDValue S1,
+ const CallInst *CI);
+
/// Lower a strcpy operation into a target library call and return the
/// resulting chain and call result as SelectionDAG SDValues.
LLVM_ABI std::pair<SDValue, SDValue> getStrcpy(SDValue Chain, const SDLoc &dl,
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h b/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
index 0b137a92fce19..508514a007819 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
@@ -161,11 +161,10 @@ class SelectionDAGTargetInfo {
/// faster than a libcall.
/// The first returned SDValue is the result of the strcmp and the second is
/// the chain. Both SDValues can be null if a normal libcall should be used.
- virtual std::pair<SDValue, SDValue>
- EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
- SDValue Op1, SDValue Op2,
- MachinePointerInfo Op1PtrInfo,
- MachinePointerInfo Op2PtrInfo) const {
+ virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcmp(
+ SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
+ SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
+ const CallInst *CI) const {
return std::make_pair(SDValue(), SDValue());
}
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index c22a3bc994457..9d7b1675ddb06 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -3125,6 +3125,7 @@ defset list<RuntimeLibcallImpl> PPC64AIXCallList = {
def ___memmove64 : RuntimeLibcallImpl<MEMMOVE>;
def ___memset64 : RuntimeLibcallImpl<MEMSET>;
def ___bzero64 : RuntimeLibcallImpl<BZERO>;
+ def ___strcmp64 : RuntimeLibcallImpl<STRCMP>;
def ___strcpy64 : RuntimeLibcallImpl<STRCPY>;
def ___strlen64 : RuntimeLibcallImpl<STRLEN>;
def ___strstr64 : RuntimeLibcallImpl<STRSTR>;
@@ -3135,6 +3136,7 @@ defset list<RuntimeLibcallImpl> PPC32AIXCallList = {
def ___memmove : RuntimeLibcallImpl<MEMMOVE>;
def ___memset : RuntimeLibcallImpl<MEMSET>;
def ___bzero : RuntimeLibcallImpl<BZERO>;
+ def ___strcmp : RuntimeLibcallImpl<STRCMP>;
def ___strcpy : RuntimeLibcallImpl<STRCPY>;
def ___strlen : RuntimeLibcallImpl<STRLEN>;
def ___strstr : RuntimeLibcallImpl<STRSTR>;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index c7c36ac56a8ab..94de39bae54ec 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9210,6 +9210,16 @@ getRuntimeCallSDValueHelper(SDValue Chain, const SDLoc &dl,
return TLI->LowerCallTo(CLI);
}
+std::pair<SDValue, SDValue> SelectionDAG::getStrcmp(SDValue Chain,
+ const SDLoc &dl, SDValue S1,
+ SDValue S2,
+ const CallInst *CI) {
+ PointerType *PT = PointerType::getUnqual(*getContext());
+ TargetLowering::ArgListTy Args = {{S1, PT}, {S2, PT}};
+ return getRuntimeCallSDValueHelper(Chain, dl, std::move(Args), CI,
+ RTLIB::STRCMP, this, TLI);
+}
+
std::pair<SDValue, SDValue> SelectionDAG::getStrstr(SDValue Chain,
const SDLoc &dl, SDValue S1,
SDValue S2,
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 52e623830b0f5..d89ba7cdf969e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9457,11 +9457,9 @@ bool SelectionDAGBuilder::visitStrCmpCall(const CallInst &I) {
const Value *Arg0 = I.getArgOperand(0), *Arg1 = I.getArgOperand(1);
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
- std::pair<SDValue, SDValue> Res =
- TSI.EmitTargetCodeForStrcmp(DAG, getCurSDLoc(), DAG.getRoot(),
- getValue(Arg0), getValue(Arg1),
- MachinePointerInfo(Arg0),
- MachinePointerInfo(Arg1));
+ std::pair<SDValue, SDValue> Res = TSI.EmitTargetCodeForStrcmp(
+ DAG, getCurSDLoc(), DAG.getRoot(), getValue(Arg0), getValue(Arg1),
+ MachinePointerInfo(Arg0), MachinePointerInfo(Arg1), &I);
if (Res.first.getNode()) {
processIntegerCallValue(I, Res.first, true);
PendingLoads.push_back(Res.second);
diff --git a/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp b/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp
index 6f087ec47ddc2..dc8434fc703bf 100644
--- a/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp
@@ -81,6 +81,13 @@ std::pair<SDValue, SDValue> PPCSelectionDAGInfo::EmitTargetCodeForMemcmp(
return DAG.getMemcmp(Chain, dl, Op1, Op2, Op3, CI);
}
+std::pair<SDValue, SDValue> PPCSelectionDAGInfo::EmitTargetCodeForStrcmp(
+ SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,
+ MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
+ const CallInst *CI) const {
+ return DAG.getStrcmp(Chain, DL, Op1, Op2, CI);
+}
+
std::pair<SDValue, SDValue> PPCSelectionDAGInfo::EmitTargetCodeForStrcpy(
SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo,
diff --git a/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h b/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h
index d617501366cb8..ae6ae85d0b0e9 100644
--- a/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h
+++ b/llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h
@@ -76,7 +76,10 @@ class PPCSelectionDAGInfo : public SelectionDAGGenTargetInfo {
EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
SDValue Op1, SDValue Op2, SDValue Op3,
const CallInst *CI) const override;
-
+ std::pair<SDValue, SDValue> EmitTargetCodeForStrcmp(
+ SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1,
+ SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
+ const CallInst *CI) const override;
std::pair<SDValue, SDValue>
EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
SDValue Dest, SDValue Src,
diff --git a/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp b/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
index afffeb52da879..eec37a9df386f 100644
--- a/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
@@ -238,8 +238,8 @@ std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcpy(
std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForStrcmp(
SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
- SDValue Src2, MachinePointerInfo Op1PtrInfo,
- MachinePointerInfo Op2PtrInfo) const {
+ SDValue Src2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
+ const CallInst *CI) const {
SDVTList VTs = DAG.getVTList(Src1.getValueType(), MVT::i32, MVT::Other);
// Swap operands to invert CC == 1 vs. CC == 2 cases.
SDValue Unused = DAG.getNode(SystemZISD::STRCMP, DL, VTs, Chain, Src2, Src1,
diff --git a/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h b/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h
index 6da36c9bc4225..8e6da4fe8b0ae 100644
--- a/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h
+++ b/llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h
@@ -74,11 +74,10 @@ class SystemZSelectionDAGInfo : public SelectionDAGGenTargetInfo {
MachinePointerInfo SrcPtrInfo, bool isStpcpy,
const CallInst *CI) const override;
- std::pair<SDValue, SDValue>
- EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
- SDValue Src1, SDValue Src2,
- MachinePointerInfo Op1PtrInfo,
- MachinePointerInfo Op2PtrInfo) const override;
+ std::pair<SDValue, SDValue> EmitTargetCodeForStrcmp(
+ SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
+ SDValue Src2, MachinePointerInfo Op1PtrInfo,
+ MachinePointerInfo Op2PtrInfo, const CallInst *CI) const override;
std::pair<SDValue, SDValue>
EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
diff --git a/llvm/test/CodeGen/PowerPC/milicode32.ll b/llvm/test/CodeGen/PowerPC/milicode32.ll
index f569bc4d2668e..491f32ee65053 100644
--- a/llvm/test/CodeGen/PowerPC/milicode32.ll
+++ b/llvm/test/CodeGen/PowerPC/milicode32.ll
@@ -342,7 +342,7 @@ define signext i32 @test_strcmp(ptr noundef %s1, ptr noundef %s2) nounwind {
; CHECK-AIX-32-P9-NEXT: mflr r0
; CHECK-AIX-32-P9-NEXT: stwu r1, -64(r1)
; CHECK-AIX-32-P9-NEXT: stw r0, 72(r1)
-; CHECK-AIX-32-P9-NEXT: bl .strcmp[PR]
+; CHECK-AIX-32-P9-NEXT: bl .___strcmp[PR]
; CHECK-AIX-32-P9-NEXT: nop
; CHECK-AIX-32-P9-NEXT: addi r1, r1, 64
; CHECK-AIX-32-P9-NEXT: lwz r0, 8(r1)
diff --git a/llvm/test/CodeGen/PowerPC/milicode64.ll b/llvm/test/CodeGen/PowerPC/milicode64.ll
index e78577af3c2bf..6dcb2f2ff0513 100644
--- a/llvm/test/CodeGen/PowerPC/milicode64.ll
+++ b/llvm/test/CodeGen/PowerPC/milicode64.ll
@@ -469,8 +469,9 @@ define signext i32 @test_strcmp(ptr noundef %s1, ptr noundef %s2) nounwind {
; CHECK-AIX-64-P9-NEXT: mflr r0
; CHECK-AIX-64-P9-NEXT: stdu r1, -112(r1)
; CHECK-AIX-64-P9-NEXT: std r0, 128(r1)
-; CHECK-AIX-64-P9-NEXT: bl .strcmp[PR]
+; CHECK-AIX-64-P9-NEXT: bl .___strcmp64[PR]
; CHECK-AIX-64-P9-NEXT: nop
+; CHECK-AIX-64-P9-NEXT: extsw r3, r3
; CHECK-AIX-64-P9-NEXT: addi r1, r1, 112
; CHECK-AIX-64-P9-NEXT: ld r0, 16(r1)
; CHECK-AIX-64-P9-NEXT: mtlr r0
>From b0d969fac62419a5048ada09a9fbd20306441863 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Tue, 20 Jan 2026 19:59:37 +0000
Subject: [PATCH 2/4] add some new argument for the setLibCallee
---
llvm/include/llvm/CodeGen/TargetLowering.h | 43 +++++++++++++++++--
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +-
llvm/test/CodeGen/PowerPC/milicode64.ll | 1 -
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index d8b5274d37c85..9d65cc5bcae9d 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4827,16 +4827,53 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
// setCallee with target/module-specific attributes
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
- SDValue Target, ArgListTy &&ArgsList) {
+ SDValue Target, ArgListTy &&ArgsList,
+ AttributeSet ResultAttrs = {}) {
return setLibCallee(CC, ResultType, ResultType, Target,
- std::move(ArgsList));
+ std::move(ArgsList), ResultAttrs);
}
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
Type *OrigResultType, SDValue Target,
- ArgListTy &&ArgsList) {
+ ArgListTy &&ArgsList,
+ AttributeSet ResultAttrs = {}) {
OrigRetTy = OrigResultType;
RetTy = ResultType;
+ IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
+ RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
+ RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
+ NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);
+ Callee = Target;
+ CallConv = CC;
+ NumFixedArgs = ArgsList.size();
+ Args = std::move(ArgsList);
+
+ DAG.getTargetLoweringInfo().markLibCallAttributes(
+ &(DAG.getMachineFunction()), CC, Args);
+ return *this;
+ }
+
+ // setCallee with target/module-specific attributes
+ CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
+ SDValue Target, ArgListTy &&ArgsList,
+ const CallBase &Call) {
+ return setLibCallee(CC, ResultType, ResultType, Target,
+ std::move(ArgsList), Call);
+ }
+
+ CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
+ Type *OrigResultType, SDValue Target,
+ ArgListTy &&ArgsList, const CallBase &Call) {
+ OrigRetTy = OrigResultType;
+ RetTy = ResultType;
+ IsInReg = Call.hasRetAttr(Attribute::InReg);
+ DoesNotReturn =
+ Call.doesNotReturn() ||
+ (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
+ IsReturnValueUsed = !Call.use_empty();
+ RetSExt = Call.hasRetAttr(Attribute::SExt);
+ RetZExt = Call.hasRetAttr(Attribute::ZExt);
+ NoMerge = Call.hasFnAttr(Attribute::NoMerge);
Callee = Target;
CallConv = CC;
NumFixedArgs = ArgsList.size();
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 94de39bae54ec..149ece90a93ba 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9204,7 +9204,7 @@ getRuntimeCallSDValueHelper(SDValue Chain, const SDLoc &dl,
CLI.setDebugLoc(dl)
.setChain(Chain)
.setLibCallee(DAG->getLibcalls().getLibcallImplCallingConv(LCImpl),
- CI->getType(), Callee, std::move(Args))
+ CI->getType(), Callee, std::move(Args), *CI)
.setTailCall(IsTailCall);
return TLI->LowerCallTo(CLI);
diff --git a/llvm/test/CodeGen/PowerPC/milicode64.ll b/llvm/test/CodeGen/PowerPC/milicode64.ll
index 6dcb2f2ff0513..c75b6224c8156 100644
--- a/llvm/test/CodeGen/PowerPC/milicode64.ll
+++ b/llvm/test/CodeGen/PowerPC/milicode64.ll
@@ -471,7 +471,6 @@ define signext i32 @test_strcmp(ptr noundef %s1, ptr noundef %s2) nounwind {
; CHECK-AIX-64-P9-NEXT: std r0, 128(r1)
; CHECK-AIX-64-P9-NEXT: bl .___strcmp64[PR]
; CHECK-AIX-64-P9-NEXT: nop
-; CHECK-AIX-64-P9-NEXT: extsw r3, r3
; CHECK-AIX-64-P9-NEXT: addi r1, r1, 112
; CHECK-AIX-64-P9-NEXT: ld r0, 16(r1)
; CHECK-AIX-64-P9-NEXT: mtlr r0
>From d333f147a991d799773f536be7ea15e5873ae635 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Thu, 22 Jan 2026 16:11:14 +0000
Subject: [PATCH 3/4] add a helper function setAttributeSet
---
llvm/include/llvm/CodeGen/TargetLowering.h | 61 ++++++++-----------
.../SelectionDAG/SelectionDAGBuilder.cpp | 3 +-
2 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 9d65cc5bcae9d..3fbb5c3acc5e8 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4825,6 +4825,25 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
return *this;
}
+ void setAttributeSet(AttributeSet &ResultAttrs) {
+ IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
+ RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
+ RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
+ NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);
+ }
+
+ void setAttributeSet(const CallBase &Call) {
+ IsInReg = Call.hasRetAttr(Attribute::InReg);
+ DoesNotReturn =
+ Call.doesNotReturn() ||
+ (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
+ IsVarArg = Call.getFunctionType()->isVarArg();
+ IsReturnValueUsed = !Call.use_empty();
+ RetSExt = Call.hasRetAttr(Attribute::SExt);
+ RetZExt = Call.hasRetAttr(Attribute::ZExt);
+ NoMerge = Call.hasFnAttr(Attribute::NoMerge);
+ }
+
// setCallee with target/module-specific attributes
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
SDValue Target, ArgListTy &&ArgsList,
@@ -4839,15 +4858,11 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
AttributeSet ResultAttrs = {}) {
OrigRetTy = OrigResultType;
RetTy = ResultType;
- IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
- RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
- RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
- NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);
Callee = Target;
CallConv = CC;
NumFixedArgs = ArgsList.size();
Args = std::move(ArgsList);
-
+ setAttributeSet(ResultAttrs);
DAG.getTargetLoweringInfo().markLibCallAttributes(
&(DAG.getMachineFunction()), CC, Args);
return *this;
@@ -4866,18 +4881,11 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
ArgListTy &&ArgsList, const CallBase &Call) {
OrigRetTy = OrigResultType;
RetTy = ResultType;
- IsInReg = Call.hasRetAttr(Attribute::InReg);
- DoesNotReturn =
- Call.doesNotReturn() ||
- (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
- IsReturnValueUsed = !Call.use_empty();
- RetSExt = Call.hasRetAttr(Attribute::SExt);
- RetZExt = Call.hasRetAttr(Attribute::ZExt);
- NoMerge = Call.hasFnAttr(Attribute::NoMerge);
Callee = Target;
CallConv = CC;
NumFixedArgs = ArgsList.size();
Args = std::move(ArgsList);
+ setAttributeSet(Call);
DAG.getTargetLoweringInfo().markLibCallAttributes(
&(DAG.getMachineFunction()), CC, Args);
@@ -4888,40 +4896,23 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
SDValue Target, ArgListTy &&ArgsList,
AttributeSet ResultAttrs = {}) {
RetTy = OrigRetTy = ResultType;
- IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
- RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
- RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
- NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);
-
Callee = Target;
CallConv = CC;
NumFixedArgs = ArgsList.size();
Args = std::move(ArgsList);
+ setAttributeSet(ResultAttrs);
return *this;
}
- CallLoweringInfo &setCallee(Type *ResultType, FunctionType *FTy,
- SDValue Target, ArgListTy &&ArgsList,
- const CallBase &Call) {
+ CallLoweringInfo &setCallee(Type *ResultType, SDValue Target,
+ ArgListTy &&ArgsList, const CallBase &Call) {
RetTy = OrigRetTy = ResultType;
-
- IsInReg = Call.hasRetAttr(Attribute::InReg);
- DoesNotReturn =
- Call.doesNotReturn() ||
- (!isa<InvokeInst>(Call) && isa<UnreachableInst>(Call.getNextNode()));
- IsVarArg = FTy->isVarArg();
- IsReturnValueUsed = !Call.use_empty();
- RetSExt = Call.hasRetAttr(Attribute::SExt);
- RetZExt = Call.hasRetAttr(Attribute::ZExt);
- NoMerge = Call.hasFnAttr(Attribute::NoMerge);
-
Callee = Target;
-
CallConv = Call.getCallingConv();
- NumFixedArgs = FTy->getNumParams();
+ NumFixedArgs = Call.getFunctionType()->getNumParams();
Args = std::move(ArgsList);
-
CB = &Call;
+ setAttributeSet(Call);
return *this;
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index d89ba7cdf969e..25905d5782950 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9104,7 +9104,6 @@ void SelectionDAGBuilder::LowerCallTo(const CallBase &CB, SDValue Callee,
const BasicBlock *EHPadBB,
const TargetLowering::PtrAuthInfo *PAI) {
auto &DL = DAG.getDataLayout();
- FunctionType *FTy = CB.getFunctionType();
Type *RetTy = CB.getType();
TargetLowering::ArgListTy Args;
@@ -9184,7 +9183,7 @@ void SelectionDAGBuilder::LowerCallTo(const CallBase &CB, SDValue Callee,
TargetLowering::CallLoweringInfo CLI(DAG);
CLI.setDebugLoc(getCurSDLoc())
.setChain(getRoot())
- .setCallee(RetTy, FTy, Callee, std::move(Args), CB)
+ .setCallee(RetTy, Callee, std::move(Args), CB)
.setTailCall(isTailCall)
.setConvergent(CB.isConvergent())
.setIsPreallocated(
>From cb7543fe210797cc740cf838c728799ebaf87adc Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Mon, 26 Jan 2026 14:59:00 +0000
Subject: [PATCH 4/4] add some comment for the new function
---
llvm/include/llvm/CodeGen/TargetLowering.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 3fbb5c3acc5e8..f7e1f8fa41022 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4844,7 +4844,8 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
NoMerge = Call.hasFnAttr(Attribute::NoMerge);
}
- // setCallee with target/module-specific attributes
+ // Set callee info for a library call, allowing caller-provided result
+ // attributes.
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
SDValue Target, ArgListTy &&ArgsList,
AttributeSet ResultAttrs = {}) {
@@ -4868,7 +4869,6 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
return *this;
}
- // setCallee with target/module-specific attributes
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
SDValue Target, ArgListTy &&ArgsList,
const CallBase &Call) {
@@ -4876,6 +4876,8 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
std::move(ArgsList), Call);
}
+ // Set callee info for a library call and propagate attribute information
+ // from the CallBase.
CallLoweringInfo &setLibCallee(CallingConv::ID CC, Type *ResultType,
Type *OrigResultType, SDValue Target,
ArgListTy &&ArgsList, const CallBase &Call) {
More information about the llvm-commits
mailing list