Understand if a condition was true or false

Hi all,
I have the condition of an ICmpInst in a variable called condition obtained doing GenericValue condition = getOperandValue(&I, SF);

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?

I’m not sure because I was expecting something different and I’m a bit lost

Should I use another approach?

Thanks

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.

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