Skip to content

Commit ec4feae

Browse files
committedJul 6, 2018
AMDGPU: Fix UBSan error caused by r335942
Summary: Fixes PR38071. Reviewers: arsenm, dstenb Reviewed By: arsenm Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, llvm-commits Differential Revision: https://reviews.llvm.org/D48979 llvm-svn: 336448
1 parent 373d6ed commit ec4feae

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed
 

‎llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3939,7 +3939,8 @@ SDValue AMDGPUTargetLowering::loadInputValue(SelectionDAG &DAG,
39393939
uint32_t AMDGPUTargetLowering::getImplicitParameterOffset(
39403940
const MachineFunction &MF, const ImplicitParameter Param) const {
39413941
const AMDGPUMachineFunction *MFI = MF.getInfo<AMDGPUMachineFunction>();
3942-
const AMDGPUSubtarget &ST = MF.getSubtarget<AMDGPUSubtarget>();
3942+
const AMDGPUCommonSubtarget &ST =
3943+
AMDGPUCommonSubtarget::get(getTargetMachine(), MF.getFunction());
39433944
unsigned ExplicitArgOffset = ST.getExplicitKernelArgOffset(MF.getFunction());
39443945
unsigned Alignment = ST.getAlignmentForImplicitArgPtr();
39453946
uint64_t ArgOffset = alignTo(MFI->getExplicitKernArgSize(), Alignment) +

‎llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h

+18-22
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ class AMDGPUCommonSubtarget {
114114
return TargetTriple.getOS() == Triple::AMDPAL;
115115
}
116116

117+
bool isMesa3DOS() const {
118+
return TargetTriple.getOS() == Triple::Mesa3D;
119+
}
120+
121+
bool isMesaKernel(const Function &F) const {
122+
return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
123+
}
124+
125+
bool isAmdCodeObjectV2(const Function &F) const {
126+
return isAmdHsaOS() || isMesaKernel(F);
127+
}
128+
117129
bool has16BitInsts() const {
118130
return Has16BitInsts;
119131
}
@@ -166,6 +178,12 @@ class AMDGPUCommonSubtarget {
166178
return isAmdHsaOS() ? 8 : 4;
167179
}
168180

181+
/// Returns the offset in bytes from the start of the input buffer
182+
/// of the first explicit kernel argument.
183+
unsigned getExplicitKernelArgOffset(const Function &F) const {
184+
return isAmdCodeObjectV2(F) ? 0 : 36;
185+
}
186+
169187
/// \returns Maximum number of work groups per compute unit supported by the
170188
/// subtarget and limited by given \p FlatWorkGroupSize.
171189
unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
@@ -384,10 +402,6 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo,
384402

385403
void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
386404

387-
bool isMesa3DOS() const {
388-
return TargetTriple.getOS() == Triple::Mesa3D;
389-
}
390-
391405
Generation getGeneration() const {
392406
return (Generation)Gen;
393407
}
@@ -603,19 +617,11 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo,
603617
return HasUnpackedD16VMem;
604618
}
605619

606-
bool isMesaKernel(const Function &F) const {
607-
return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
608-
}
609-
610620
// Covers VS/PS/CS graphics shaders
611621
bool isMesaGfxShader(const Function &F) const {
612622
return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
613623
}
614624

615-
bool isAmdCodeObjectV2(const Function &F) const {
616-
return isAmdHsaOS() || isMesaKernel(F);
617-
}
618-
619625
bool hasMad64_32() const {
620626
return getGeneration() >= SEA_ISLANDS;
621627
}
@@ -652,12 +658,6 @@ class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo,
652658
return D16PreservesUnusedBits;
653659
}
654660

655-
/// Returns the offset in bytes from the start of the input buffer
656-
/// of the first explicit kernel argument.
657-
unsigned getExplicitKernelArgOffset(const Function &F) const {
658-
return isAmdCodeObjectV2(F) ? 0 : 36;
659-
}
660-
661661
/// \returns Number of bytes of arguments that are passed to a shader or
662662
/// kernel in addition to the explicit ones declared for the function.
663663
unsigned getImplicitArgNumBytes(const Function &F) const {
@@ -1088,10 +1088,6 @@ class R600Subtarget final : public R600GenSubtargetInfo,
10881088

10891089
bool hasFMA() const { return FMA; }
10901090

1091-
unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
1092-
return 36;
1093-
}
1094-
10951091
bool hasCFAluBug() const { return CFALUBug; }
10961092

10971093
bool hasVertexCache() const { return HasVertexCache; }

‎llvm/lib/Target/AMDGPU/R600ISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ SDValue R600TargetLowering::LowerFormalArguments(
16581658

16591659
unsigned ValBase = ArgLocs[In.getOrigArgIndex()].getLocMemOffset();
16601660
unsigned PartOffset = VA.getLocMemOffset();
1661-
unsigned Offset = Subtarget->getExplicitKernelArgOffset(MF) +
1661+
unsigned Offset = Subtarget->getExplicitKernelArgOffset(MF.getFunction()) +
16621662
VA.getLocMemOffset();
16631663

16641664
MachinePointerInfo PtrInfo(UndefValue::get(PtrTy), PartOffset - ValBase);

0 commit comments

Comments
 (0)
Please sign in to comment.