[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
Mon Apr 29 04:15:32 PDT 2024


bipmis wrote:

I just the looked at usability of the sequence trunc(sub(ptr2int, ptr2int)) / (unsigned)(strlen) and looks like it indeed it is quite common in a class of applications beyond the legacy code example cited earlier. Some of the other scenarios(not an extensive list) where we see this pattern and should be able to optimise out the "trunc instruction" would be
1. Database applications like sql - https://opensource.apple.com/source/CPANInternal/CPANInternal-108/DBD-SQLite/sqlite3.c, openDirectory()
2. Multimedia applications - https://github.com/xiph/flac/blob/master/src/metaflac/options.c, parse_add_seekpoint()
3. Compression algorithms - https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/UI/Common/HashCalc.cpp, AddHashResultLine()
In some these cases if the allocations are limited to a max 4Gb(32 bit allocations) which is definitely possible and known to the application user, we could use the supported flag to optimise out the "trunc" instruction, which in turn could enable host of other optimisations.

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


More information about the llvm-commits mailing list