<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.  But when I compile the sample on x86_64, arm7, and aarch64, I always get code that yields one.</div><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>