[llvm-dev] Understand if a condition was true or false

Alberto Barbaro via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 22 03:06:34 PDT 2019


Thanks Tim,
I think I'll go for getZExtValue as you suggested. Anyway saw also
getBoolValue that I can use.

Thanks again for your help


On Fri, Mar 22, 2019, 09:32 Tim Northover <t.p.northover at gmail.com> wrote:

> On Fri, 22 Mar 2019 at 08:09, Alberto Barbaro via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > Now I would like to understand if the comparison was true or false. Is
> it correct to use condition.IntVal.getSExtValue() and if the value is 0
> consider the true and if the value is -1 consider the condition false?
>
> The result of an icmp is a 1-bit integer. As a pure bag-of-bits 0b0 is
> false and 0b1 is true. If you interpret those as signed integers then
> 0b1 is actually -1 though, so the condition is reversed from what you
> said above.
>
> It would probably be more natural if you used getZExtValue, which
> zero-extends the 1-bit answer and gives the much more natural result
> that 0 == false, 1 == true.
>
> > I'm not sure because I was expecting something different and I'm a bit
> lost
>
> I assume you were expecting 0 or 1 and aren't sure how to interpret
> the -1? It's really just a quirk of 2s-complement representation LLVM
> uses (together with most CPUs) that a 1-bit signed value doesn't
> actually have any positive values and the single non-zero one is -1.
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190322/c7c542af/attachment-0001.html>


More information about the llvm-dev mailing list