[PATCH] [InstCombine] Lower unknown @llvm.objectsize early.

Ahmed Bougacha ahmed.bougacha at gmail.com
Thu Jan 22 09:41:50 PST 2015


We already try to lower objectsize in InstCombine, but only if the
result is known.  When it is unknown, the intrinsic calls would survive
the mid-level optimizers, to be lowered late, in CodeGenPrepare.

We can lower them in InstCombine as well, to 0 or -1, depending on the
min argument.
One could argue this is a bit early to do the lowering, since the size
might be made apparent by later optimizations.  In practice however,
the majority of cases has a never-known objectsize, and in a lot of
the remaining few, the size is immediately apparent (say from a
global value, or an alloca).
Always keeping the intrinsic call intact prevents optimizations, and
makes memcpyopt useless when libcall fortification is enabled (the
default on a few major targets).


There are a few alternatives to doing it here; all seem overkill:
- teach the libcall simplifier to look through unknown
  @llvm.objectsize, so it's able to replace the fortified version
  of a libcall with the non-fortified one if the size is unknown.
- make a dedicated pass that lowers the intrinsic, even when
  the size is unknown, run it before memcpyopt & friends.
- in memcpyopt, start by running the libcall simplifier, to
  lower @llvm.objectsize, even when the size is unknown.

Also, Nuno proposes a related improvement to the associated
APIs (MemoryBuiltins.h): "[the analyzer] could be improved to
produce an interval instead.  If we know that the minimum
objectsize is larger than the written size, then the check could
go away, even if we don't know the exact size of the buffer."

http://reviews.llvm.org/D7129

Files:
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/objsize.ll
  test/Transforms/InstCombine/stpcpy_chk-1.ll
  test/Transforms/InstCombine/strcpy_chk-1.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7129.18619.patch
Type: text/x-patch
Size: 4235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150122/b5384956/attachment.bin>


More information about the llvm-commits mailing list