[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:
Shouldn't this be:
```cpp
while (BitCastInst *BC = dyn_cast<BitCastInst>)
Pointer = BC->getOperand(0);
```
Otherwise, the bitcast isn't properly added if I change the `uitofp-with-bool.ll` test to:
```llvm
%AA = bitcast float addrspace(1)* %A to i32 addrspace(1)*
%AAA = bitcast i32 addrspace(1)* %AA to float addrspace(1)*
store float %conv, float addrspace(1)* %AAA, align 4;
;store float %conv, float addrspace(1)* %A, align 4;
```
https://github.com/llvm/llvm-project/pull/75514
More information about the llvm-commits
mailing list