Hi,
I have three constants (B, C and V) and V = B + C. I want to find out if B +
C wraps around. The way I'll do it is, assuming B and C are both positive,
to check if V < B or C.
For this I need the values of B, C and V. I tried using APInt as below.
***
If (isa<Constant> (B) && isa<Constant> (C) &&
isa<Constant>(V)) {
ConstantInt *CV = dyn_cast<ConstantInt>(V);
ConstantInt *CB = dyn_cast<ConstantInt>(B);
ConstantInt *CC = dyn_cast<ConstantInt>(C);
if (CV && CB && CC) {
const APInt &VVal = CV->getValue();
const APInt &BVal = CB->getValue();
const APInt &CVal = CC->getValue();
******
But isn't APInt considered to represent unsigned integers ? Is there another
way of doing this ?
Thanks in advance,
Pranav
On Wed, Jul 13, 2011 at 12:09 PM, Pranav Bhandarkar <pranavb at codeaurora.org> wrote:> Hi, > > I have three constants (B, C and V) and V = B + C. I want to find out if B + > C wraps around. The way I'll do it is, assuming B and C are both positive, > to check if V < B or C. > For this I need the values of B, C and V. I tried using APInt as below. > *** > If (isa<Constant> (B) && isa<Constant> (C) && isa<Constant>(V)) { > ConstantInt *CV = dyn_cast<ConstantInt>(V); > ConstantInt *CB = dyn_cast<ConstantInt>(B); > ConstantInt *CC = dyn_cast<ConstantInt>(C); > if (CV && CB && CC) { > const APInt &VVal = CV->getValue(); > const APInt &BVal = CB->getValue(); > const APInt &CVal = CC->getValue(); > ****** > > But isn't APInt considered to represent unsigned integers ? Is there another > way of doing this ?APInt's aren't inherently signed or unsigned; see http://llvm.org/doxygen/classllvm_1_1APInt.html#amgrp54923b9793dae891d9489cc5947f263a . -Eli
>APInt's aren't inherently signed or unsigned; see >http://llvm.org/doxygen/classllvm_1_1APInt.html#amgrp54923b9793dae891d9489cc5947f263a Oh, so that makes sense. I was thrown off by these comments in the APInt.h ***************************** ///It is a functional replacement for common case unsigned integer type like /// "unsigned", "unsigned long" or "uint64_t", but also allows non-byte-width /// integer sizes and large integer value types such as 3-bits, 15-bits, or more /// than 64-bits of precision. ******************************* Pranav