Skip to content

Commit f3f57b8

Browse files
authored
[ESIMD] Do not use ReadNone attribute for GenX intrinsics (#7969)
The attribute is suggested by GenX Intrinsics component for call declarations. Such attribute on calls causes verification since LLVM 16, and needs to be replaced with setMemoryEffects(MemoryEffects::none()). Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent 5e8ae21 commit f3f57b8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/IR/Module.h"
3535
#include "llvm/IR/PatternMatch.h"
3636
#include "llvm/Pass.h"
37+
#include "llvm/Support/ModRef.h"
3738
#include "llvm/Support/raw_ostream.h"
3839

3940
#include <cctype>
@@ -1046,12 +1047,20 @@ static Instruction *generateGenXCall(Instruction *EEI, StringRef IntrinName,
10461047
? GenXIntrinsic::getGenXDeclaration(
10471048
EEI->getModule(), ID, FixedVectorType::get(I32Ty, MAX_DIMS))
10481049
: GenXIntrinsic::getGenXDeclaration(EEI->getModule(), ID);
1050+
// llvm::Attribute::ReadNone must not be used for call statements anymore.
1051+
bool FixReadNone =
1052+
NewFDecl->getFnAttribute(llvm::Attribute::ReadNone).isValid();
1053+
if (FixReadNone)
1054+
NewFDecl->removeFnAttr(llvm::Attribute::ReadNone);
1055+
10491056
// Use hardcoded prefix when EEI has no name.
10501057
std::string ResultName =
10511058
((EEI->hasName() ? Twine(EEI->getName()) : Twine("Res")) + "." +
10521059
FullIntrinName)
10531060
.str();
10541061
Instruction *Inst = IntrinsicInst::Create(NewFDecl, {}, ResultName, EEI);
1062+
if (FixReadNone)
1063+
(cast<CallInst>(Inst))->setMemoryEffects(MemoryEffects::none());
10551064
Inst->setDebugLoc(EEI->getDebugLoc());
10561065

10571066
if (IsVectorCall) {
@@ -1394,14 +1403,21 @@ static void translateESIMDIntrinsicCall(CallInst &CI) {
13941403
GenXOverloadedTypes);
13951404
}
13961405

1397-
Instruction *NewCI = IntrinsicInst::Create(
1406+
// llvm::Attribute::ReadNone must not be used for call statements anymore.
1407+
bool FixReadNone =
1408+
NewFDecl->getFnAttribute(llvm::Attribute::ReadNone).isValid();
1409+
if (FixReadNone)
1410+
NewFDecl->removeFnAttr(llvm::Attribute::ReadNone);
1411+
CallInst *NewCI = IntrinsicInst::Create(
13981412
NewFDecl, GenXArgs,
13991413
NewFDecl->getReturnType()->isVoidTy() ? "" : CI.getName() + ".esimd",
14001414
&CI);
1401-
if (CI.getDebugLoc())
1402-
NewCI->setDebugLoc(CI.getDebugLoc());
1403-
NewCI = addCastInstIfNeeded(&CI, NewCI);
1404-
CI.replaceAllUsesWith(NewCI);
1415+
if (FixReadNone)
1416+
NewCI->setMemoryEffects(MemoryEffects::none());
1417+
NewCI->setDebugLoc(CI.getDebugLoc());
1418+
1419+
Instruction *NewInst = addCastInstIfNeeded(&CI, NewCI);
1420+
CI.replaceAllUsesWith(NewInst);
14051421
CI.eraseFromParent();
14061422
}
14071423

llvm/test/SYCLLowerIR/ESIMD/lower_spirv_intrins.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ define spir_kernel void @"__spirv_GlobalInvocationId_xyz"(i64 addrspace(1)* %_ar
5656
; CHECK-NEXT: store i64 [[ADD]], i64 addrspace(4)* [[PTRIDX_ASCAST_I_I]], align 8
5757
; CHECK-NEXT: ret void
5858
;
59+
; Verify that the attribute is deleted from GenX declaration
60+
; CHECK-NOT: readnone
5961
entry:
6062
%0 = load <3 x i64>, <3 x i64> addrspace(4)* addrspacecast (<3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId to <3 x i64> addrspace(4)*), align 32
6163
%1 = extractelement <3 x i64> %0, i64 0

0 commit comments

Comments
 (0)