[llvm-dev] Problem with the LLVM v8.0 IR 'select' instruction
Mehdi AMINI via llvm-dev
llvm-dev at lists.llvm.org
Sun Jul 7 19:30:41 PDT 2019
Hi,
On Sun, Jul 7, 2019 at 4:26 PM Mikael Egevig via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi guys,
>
> 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:
>
> ************************************************
> ; Run-time Library Definitions
> %Exception = type { i8 }
>
> define private %Exception* @Start(i1* %$result) #0
> {
> prologue:
> store i1 true, i1* %$result
> br label %epilogue
> epilogue:
> ret %Exception* null
> }
>
> ; Generated main() function.
> define i32 @main(i32 %argc, i8** %argv)
> {
> prologue:
> %0 = alloca i1
> %1 = call %Exception *@Start(i1* %0)
> %2 = load i1, i1* %0
> %3 = select i1 %2, i32 0, i32 1
> ret i32 %3
> }
> ************************************************
>
> I'd expect the 'select' instruction in main() to yield zero, not one.
>
Seems correct to me.
> But when I compile the sample on x86_64, arm7, and aarch64, I always get
> code that yields one.
>
Can you provide a reproducer?
As far as I can tell the optimizer folds the code you provided above to
yield 0: https://godbolt.org/z/T5wkSJ
--
Mehdi
>
> 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'.
>
> The above code is automatically generated, except I have removed all
> irrelevant code generated by the compiler.
>
> 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).
>
> Thanks in advance!
>
>
> Cheers,
> Mikael Egevig
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://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/20190707/edadef2f/attachment.html>
More information about the llvm-dev
mailing list