How to tell if a pointer is "this"?

I’m looking for a way to distinguish “this” from other pointers and wonder how to tell the difference in LLVM. Any pointer is appreciated.

What are you trying to do? There are no “this” pointers in IR. There are just regular pointers, so there is no difference. If you compile from C++, it’s usually passed as an implicit first argument (that’s also noundef, nonnull and dereferenceable), but there is nothing special about it in IR. You can try compiling a few simple C++ snippets to IR to get a better understanding: Compiler Explorer (you can notice that there is virtually no difference between A::foo and bar).

If its type matches, any pointer can be this I think - would there be a specific optimization for this considering?

Thanks very much for your responses @danilaml @aqjune. I was trying to reason about its semantic of being nonmodifiable in C++. Probably this semantic is already captured by attributes. I need to do some exploration.

Conceptually, I think “this” would be a const pointer to either const or non-const data, depending on whether the method was marked const or not. I suppose there could be an IR attribute that marks a parameter as unmodifiable? I don’t work with IR enough to know off the top of my head.