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

Ilia Diachkov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 13:28:38 PST 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;
----------------
iliya-diyachkov wrote:

In my opinion, nullptr is easier to understand.

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


More information about the llvm-commits mailing list