InstCombiner::visitIntToPtr can insert a zero extend or truncate to match pointer size. The pointer size is determined by a corresponding DataLayout record for a given address space.
The problem occurs when that is a pointer to a function. There are no DataLayout fields to represent code, so size of a pointer to code is unknown.
Problem manifest itself as a pointer truncation in case if target is 64 bit, but a pointer to address space zero is 32 bit (for example "e-p:32:64-p1:64:64"). In this situation InstCombine would produce from:
%0 = ptrtoint i8 addrspace(1)* %ptr to i64 %1 = inttoptr i64 %0 to i32 ()* %call = tail call spir_func i32 %1()
a malformed call to a function using truncated pointer:
%0 = ptrtoint i8 addrspace(1)* %ptr to i64 %1 = trunc i64 %0 to i32 %2 = inttoptr i32 %1 to i32 ()* %call = tail call spir_func i32 %2()
In a longer term that is needed to create a mechanism to provide code pointer size info. Currently patch disables this optimization on a function pointer.
Put the comment before the added condition maybe?