[llvm-branch-commits] [clang] clang/OpenCL: Fix special casing OpenCL in call emission (PR #138864)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 7 06:14:09 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
This essentially reverts 1bf1a156d673.
OpenCL's handling of address spaces has always been a mess, but it's
better than it used to be so this hack appears to be unnecessary now.
None of the code here should really depend on the language or language
address space. The ABI address space to use is already explicit in the
ABIArgInfo, so use that instead of guessing it has anything to do with
LangAS::Default or getASTAllocaAddressSpace.
The below usage of LangAS::Default and getASTAllocaAddressSpace are also
suspect, but appears to be a more involved and separate fix.
---
Full diff: https://github.com/llvm/llvm-project/pull/138864.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGCall.cpp (+7-12)
``````````diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 82a24f7c295a2..1404bdfd69647 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5366,7 +5366,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
NeedCopy = true;
} else if (I->hasLValue()) {
auto LV = I->getKnownLValue();
- auto AS = LV.getAddressSpace();
bool isByValOrRef =
ArgInfo.isIndirectAliased() || ArgInfo.getIndirectByVal();
@@ -5375,17 +5374,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
(LV.getAlignment() < getContext().getTypeAlignInChars(I->Ty))) {
NeedCopy = true;
}
- if (!getLangOpts().OpenCL) {
- if ((isByValOrRef && (AS != LangAS::Default &&
- AS != CGM.getASTAllocaAddressSpace()))) {
- NeedCopy = true;
- }
- }
- // For OpenCL even if RV is located in default or alloca address space
- // we don't want to perform address space cast for it.
- else if ((isByValOrRef && Addr.getType()->getAddressSpace() !=
- IRFuncTy->getParamType(FirstIRArg)
- ->getPointerAddressSpace())) {
+
+ if (isByValOrRef && Addr.getType()->getAddressSpace() !=
+ ArgInfo.getIndirectAddrSpace()) {
NeedCopy = true;
}
}
@@ -5396,6 +5387,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
auto *T = llvm::PointerType::get(
CGM.getLLVMContext(), CGM.getDataLayout().getAllocaAddrSpace());
+ // FIXME: This should not depend on the language address spaces, and
+ // only the contextual values. If the address space mismatches, see if
+ // we can look through a cast to a compatible address space value,
+ // otherwise emit a copy.
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
*this, V, LangAS::Default, CGM.getASTAllocaAddressSpace(), T,
true);
``````````
</details>
https://github.com/llvm/llvm-project/pull/138864
More information about the llvm-branch-commits
mailing list