[llvm] [SPIR-V] Do not reassign kernel arg SPIRVType based on later calls/uses (PR #75514)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 07:35:09 PST 2024


================
@@ -265,6 +281,85 @@ Instruction *SPIRVEmitIntrinsics::visitBitCastInst(BitCastInst &I) {
   return NewI;
 }
 
+void SPIRVEmitIntrinsics::insertPtrCastInstr(Instruction *I) {
+  Value *Pointer;
+  Type *ExpectedElementType;
+  unsigned OperandToReplace;
+  if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
+    Pointer = SI->getPointerOperand();
+    ExpectedElementType = SI->getValueOperand()->getType();
+    OperandToReplace = 1;
+  } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
+    Pointer = LI->getPointerOperand();
+    ExpectedElementType = LI->getType();
+    OperandToReplace = 0;
+  } else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
+    Pointer = GEPI->getPointerOperand();
+    ExpectedElementType = GEPI->getSourceElementType();
+    OperandToReplace = 0;
+  } else {
+    return;
+  }
+
+  // If Pointer is the result of nop BitCastInst (ptr -> ptr), use the source
+  // pointer instead. The BitCastInst should be later removed when visited.
+  if (BitCastInst *BC = dyn_cast<BitCastInst>(Pointer))
----------------
Keenuts wrote:

Ahh figured the reason.
The code above (line 268) ignores bitcast instructions, and replaced the src with the bitcast src.
So the code here gets replaced with `store float %conv, float addrspace(1)* %A, align 4;`

Unsure why this then fails to generate the proper bitcast. Seems like the `while ()` works because it visits the instruction before removing the bitcast, and generates a spv_ptrcast, which remains. But unsure.

https://github.com/llvm/llvm-project/pull/75514


More information about the llvm-commits mailing list