diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index acd2e32d8..6f6452237 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -2185,7 +2185,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 481064b40..1f05f6b1a 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(ptr %0, ptr %0) ret void }