llvm-ir: anonymous struct name mangling

Hi,

Nikita pointed me to an issue in the full restrict patches, related to name mangling used for llvm-ir functions (See [0, 3]).

The problem is the following: Given:

  %0 = type { i32 }
  %1 = type { i32 }

Creating an intrinsic @llvm.FOO that accepts 'a pointer to %0' cannot be distinguished from the intrinsic accepting 'a pointer to %1':
  ;For a %0* ptr0, %1* ptr1
  
  call @llvm.FOO.p0s_s %0* %ptr0
  call @llvm.FOO.p0s_s %1* %ptr1 ; assertion failure: same name produced, but %ptr1 is not compatible with '%0*'

It seems that the name mangling is not coping well with anonymous structs ?
See: [1,2]: All anonymous structs get a 's_s' mangling. Still, %0 and %1 are treated as different types.

Any idea what the best way is to handle (or fix) this ?
(My feeling is that the name mangling should be improved, but at the moment I have no clue what the right approach would be)

Thanks,

Jeroen Dobbelaere

[0] The problem, as reported by Nikita: ⚙ D68484 [PATCH 01/27] [noalias] LangRef: noalias intrinsics and ptr_provenance documentation.
[1] Intrinsic::getName https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Function.cpp#L775
[2] getMangledTypeStr for a struct: https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Function.cpp#L725
[3] The actual intrinsic creation that triggered the problem: ⚙ D68491 [PATCH 06/27] [noalias] [IR] IRBuilder support for noalias intrinsics. (Look for 'Intrinsic::getDeclaration')

Hi,