[llvm] [ValueTracking] isNonZero trunc of sub of ptr2int's with recursive GEP where pointers are limited to a 32bit alloc. (PR #84933)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 05:47:41 PDT 2024


bipmis wrote:

> > > > Looks like a case where it's better to change the source code to use the correct type instead (size_t instead of unsigned).
> > > 
> > > 
> > > I would agree. However there are scenarios in benchmark applications where source cannot be changed.
> > 
> > 
> > I suspected you were going to say this. This patch very much looks like a hack for the sake of improving some benchmark score, which is something I am not very fond of. Of course, if we can get a clean implementation out of this and show that it benefits non-benchmark code (cc @dtcxzyw), then that's a different matter...
> 
> `trunc(sub(ptr2int, ptr2int)) to i32` is a common pattern. But this patch seems to just handle a special case :( I cannot tell whether it provides benefits to some real-world applications.

It definitely extends beyond a single case. This would also apply to the legacy code scenarios where stringLength() was bound to an int type. I am seeing this with utf8_check_string(). And there can be scenarios where we would like to build these applications with the latest compiler.
Additionally if `trunc(sub(ptr2int, ptr2int)) to i32` is a common pattern and it can be determined that the 2 ptrs point to same object and objectSize evaluated statically/known by the application user and suggested via flag, it should be a valid optimisation.

https://github.com/llvm/llvm-project/pull/84933


More information about the llvm-commits mailing list