[llvm-dev] Problem with the LLVM v8.0 IR 'select' instruction

Mikael Egevig via llvm-dev llvm-dev at lists.llvm.org
Sun Jul 7 16:26:13 PDT 2019


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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190708/be3b5a79/attachment.html>


More information about the llvm-dev mailing list