[llvm-dev] Missed strlen optimizations

Daniel Berlin via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 20 10:26:28 PDT 2018


This will not work if it's memory.

Yu'd need to use MemorySSA or MemoryDependenceAnalysis to get the last
instruction to modify a block of memory.


On Fri, Apr 20, 2018 at 10:24 AM, Dávid Bolvanský via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Maybe nicer..
> auto i = Src->uses().begin();
> std::advance(i, Src->getNumUses() - 1);
> i->getUser()->dump();
>
> 2018-04-20 19:19 GMT+02:00 Dávid Bolvanský <david.bolvansky at gmail.com>:
>
>>   Use *last = nullptr;
>>   for (Use &U : Src->uses())
>>       last = &U;
>>   last->getUser()->dump();
>>
>>
>> Or any better solution?
>>
>> 2018-04-20 19:19 GMT+02:00 Dávid Bolvanský <david.bolvansky at gmail.com>:
>>
>>> Is:
>>>
>>>
>>> 2018-04-20 18:07 GMT+02:00 Dávid Bolvanský <david.bolvansky at gmail.com>:
>>>
>>>> Hello,
>>>>
>>>> Code: https://godbolt.org/g/EG4Wi6
>>>>
>>>> unsigned fff3(void) {
>>>>     char buf[10] = "";
>>>>     return strlen(buf);
>>>> }
>>>>
>>>> Since we are memset-ing before strlen call, we could replace strlen
>>>> with just 0.
>>>>
>>>> Has LLVM any API to get "last instruction before strlen" which modifies
>>>> strlen argument "buf"? So we can check "yes, it is memset there, replace
>>>> strlen with zero" ?
>>>>
>>>>
>>>> Thanks
>>>>
>>>
>>>
>>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180420/aa90c1a2/attachment.html>


More information about the llvm-dev mailing list