<div dir="ltr">Hi again,<div><br></div><div>It is probably me doing something wrong, but I have attached a trimmed down sample that shows the issue and the output that Clang 8.0.0 makes (using the binary release from <a href="http://llvm.org">llvm.org</a>).</div><div><br></div><div>I invoke clang as follows: clang -S -O3 -o Evergrowing.s -Wall Evergrowing.ll</div><div><br></div><div>I tried using -O1, -O2, and -O3, but all where the same.  Please notice that I renamed 'main()' to 'mainfunc()' to be sure Clang isn't picking up 'main()' as a reserved, special function.</div><div><br></div><div>This on a Windows 10 x64 PC, but I got exactly the same behavior on arm7hf and aarch64.</div><div><br></div><div><br></div><div>Cheers,</div><div>Mikael Egevig</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Den man. 8. jul. 2019 kl. 04.30 skrev Mehdi AMINI <<a href="mailto:joker.eph@gmail.com">joker.eph@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 7, 2019 at 4:26 PM Mikael Egevig via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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"><div dir="ltr">Hi guys,<div><br></div><div>I am doing a hobby compiler using LLVM.  I have a rather peculiar problem with the 'select' instruction, as far as I can see.  Given this code:</div><div><br></div><div>************************************************</div><div>; Run-time Library Definitions<br>%Exception = type { i8 }<br><br>define private %Exception* @Start(i1* %$result) #0<br>{<br>prologue:<br>    store i1 true, i1* %$result<br>    br label %epilogue<br>epilogue:<br>    ret %Exception* null<br>}<br><br>; Generated main() function.<br>define i32 @main(i32 %argc, i8** %argv)<br>{<br>prologue:<br>    %0 = alloca i1<br>    %1 = call %Exception *@Start(i1* %0)<br>    %2 = load i1, i1* %0<br>    %3 = select i1 %2, i32 0, i32 1<br>    ret i32 %3<br>}<br>************************************************ </div><div><br></div><div>I'd expect the 'select' instruction in main() to yield zero, not one.</div></div></blockquote><div><br></div><div>Seems correct to me.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>  But when I compile the sample on x86_64, arm7, and aarch64, I always get code that yields one.</div></div></blockquote><div><br></div><div>Can you provide a reproducer?</div><div>As far as I can tell the optimizer folds the code you provided above to yield 0: <a href="https://godbolt.org/z/T5wkSJ" target="_blank">https://godbolt.org/z/T5wkSJ</a></div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>The idea is that if the program, @Start, returns false, one should be returned to the OS and vice versa.  I guess I could use 'not' instead of 'select', but I don't understand the behavior of 'select'.</div><div><br></div><div>The above code is automatically generated, except I have removed all irrelevant code generated by the compiler.</div><div><br></div><div>I'm not sure if LLVM gets confused by me returning the result in an alloca'ed area, but I use the return value, of all functions, for the exception pointer (null = no exception).</div><div><br></div><div>Thanks in advance!</div><div><br></div><div><br></div><div>Cheers,</div><div>Mikael Egevig</div><div> <br></div></div>
_______________________________________________<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></div></div>
</blockquote></div>