[llvm] [SPIR-V] Emit SPIR-V bitcasts between source/expected pointer type (PR #69621)

Michal Paszkowski via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 11:08:23 PDT 2023


================
@@ -255,7 +259,19 @@ Instruction *SPIRVEmitIntrinsics::visitGetElementPtrInst(GetElementPtrInst &I) {
 }
 
 Instruction *SPIRVEmitIntrinsics::visitBitCastInst(BitCastInst &I) {
-  SmallVector<Type *, 2> Types = {I.getType(), I.getOperand(0)->getType()};
+  Value *Source = I.getOperand(0);
+  
+  // SPIR-V, contrary to LLVM 17+ IR, supports bitcasts between pointers of
+  // varying element types. In case of IR coming from older versions of LLVM
+  // such bitcasts do not provide sufficient information, should be just skipped
+  // here, and handled in insertPtrCastInstr.
+  if (I.getType()->isPointerTy()) {
+    I.replaceAllUsesWith(Source);
+    I.eraseFromParent();
+    return &I;
----------------
michalpaszkowski wrote:

@iliya-diyachkov Here I am removing the nop bitcasts from older versions of LLVM (ptr -> ptr) and returning orphaned instruction (requiring a check `I->getParent()` at line 575). Alternatively I could return nullptr if it would make more sense.

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


More information about the llvm-commits mailing list