Skip to content

Commit 543e304

Browse files
Add BitCast instructions from float to int for AtomicCmpXchg calls (#3331)
In SPIRV-Translator for `llvm_release_160`, the `BitCast` instruction from `float` to `int` is currently applied only to argument 2 of the `AtomicCmpXchg` call. This approach works correctly when using opaque pointers. However, when typed pointers are present, SPIRV-Translator must also insert `BitCast` instructions for arguments 0 and 1, as is done in the `llvm_release_150` branch. Prior to this change, SPIRV-Translator generated the call `__spirv_AtomicCompareExchangeWeakPU3AS1fiiiif` for this atomic operation. After adding the additional `BitCast` instructions, the generated call becomes `__spirv_AtomicCompareExchangeWeakPU3AS1iiiiii`. This modification is compatible with both opaque and typed pointers. The change for llvm_release_150: 663dffd
1 parent 8b07ad1 commit 543e304

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ CallInst *OCLToSPIRVBase::visitCallAtomicCmpXchg(CallInst *CI) {
485485
if (MemTy->isFloatTy() || MemTy->isDoubleTy()) {
486486
MemTy =
487487
MemTy->isFloatTy() ? Type::getInt32Ty(*Ctx) : Type::getInt64Ty(*Ctx);
488+
489+
if (!Mutator.getArg(0)->getType()->isOpaquePointerTy()) {
490+
TypedPointerType *Arg0PtrType = TypedPointerType::get(
491+
MemTy, Mutator.getArg(0)->getType()->getPointerAddressSpace());
492+
TypedPointerType *Arg1PtrType = TypedPointerType::get(
493+
MemTy, Mutator.getArg(1)->getType()->getPointerAddressSpace());
494+
495+
Mutator.mapArg(0, [=](IRBuilder<> &Builder, Value *V) {
496+
return Builder.CreateBitCast(V, Arg0PtrType);
497+
});
498+
499+
Mutator.mapArg(1, [=](IRBuilder<> &Builder, Value *V) {
500+
return Builder.CreateBitCast(V, Arg1PtrType);
501+
});
502+
}
503+
488504
Mutator.replaceArg(
489505
0,
490506
{Mutator.getArg(0),

0 commit comments

Comments
 (0)