diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index 9c2f16b537..832117e8d4 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -2167,7 +2167,9 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, auto *BC = static_cast(BV); auto Ops = transValue(BC->getOperands(), F, BB); IRBuilder<> Builder(BB); - Value *V = Builder.CreatePtrDiff(transType(BC->getType()), Ops[0], Ops[1]); + Type *ElemTy = + transType(BC->getOperands()[0]->getType()->getPointerElementType()); + Value *V = Builder.CreatePtrDiff(ElemTy, Ops[0], Ops[1]); return mapValue(BV, V); } diff --git a/test/transcoding/ptr_diff.ll b/test/transcoding/ptr_diff.ll index bb08e74467..e1851f22e1 100644 --- a/test/transcoding/ptr_diff.ll +++ b/test/transcoding/ptr_diff.ll @@ -35,7 +35,7 @@ entry: ; CHECK-LLVM: %[[#Arg1:]] = ptrtoint ptr %[[#]] to i64 ; CHECK-LLVM: %[[#Arg2:]] = ptrtoint ptr %[[#]] to i64 ; CHECK-LLVM: %[[#Sub:]] = sub i64 %[[#Arg1]], %[[#Arg2]] -; CHECK-LLVM: sdiv exact i64 %[[#Sub]], ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64) +; CHECK-LLVM: sdiv exact i64 %[[#Sub]], ptrtoint (ptr getelementptr (float, ptr null, i32 1) to i64) %1 = call spir_func noundef i32 @_Z15__spirv_PtrDiff(float* %0, float* %0) ret void }