<div dir="ltr">What exactly is being optimized here? Does program performance improve? <div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 16, 2021 at 5:19 PM Johannes Doerfert via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Bhumitram Kumar,<br>
<br>
First, great you are interested in working on LLVM.<br>
<br>
I think you might have stumbled on a bug report that is not great for <br>
beginners.<br>
<br>
I don't think there is a bug here, optimizing this to return 1 seems <br>
fine. That<br>
said, the people reporting the bug obviously disagree which will at <br>
least cause<br>
some discussion before any decision on how to deal with this is made. <br>
Long story<br>
short, you might want to look at another bug.<br>
<br>
All the best,<br>
   Johannes<br>
<br>
<br>
On 11/16/21 12:33, bhumitram kumar via llvm-dev wrote:<br>
> Hi,<br>
>      This is my first post and I am looking at the bug 50482 . It is related<br>
> to malloc optimization. I have a doubt related to malloc optimization.<br>
> Here is the code:-<br>
><br>
> #include <stdlib.h><br>
> int test() {<br>
>    char *x = malloc(-1);<br>
>    char *y = malloc(2);<br>
>    int ret = (x != NULL) && (y != NULL);<br>
>    free(x); free(y);<br>
>    return ret;<br>
> }<br>
><br>
> Above program returns 1.<br>
><br>
> During optimization (-O1) when llvm IR goes through instruction<br>
> combining pass then program behaves incorrect.<br>
><br>
> This link follows Instruction combining pass.<br>
><br>
> <a href="https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2639" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2639</a><br>
><br>
> Where it is mentioned that<br>
><br>
> If we have a malloc call which is only used in any amount of<br>
> comparisons to null and free calls, delete the calls and replace the<br>
> comparisons with true or false as appropriate.<br>
><br>
> but is it feasible solution to replace every malloc call with true or<br>
> false when comparison to null and free calls?<br>
><br>
> Thank you,<br>
><br>
> Bhumitram Kumar<br>
><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>