arithmetic with SCEVs, SCEVConsts, ConstInts, and APInts

Hi,

Pondering the code for StrongSIV and trying to write my own, I find I have many questions.
In this code, for example,

if (isa(delta) && isa(srcCoeff)) {
const SCEVConstant *constDelta = cast(delta);
const SCEVConstant *constCoeff = cast(srcCoeff);
APInt distance, remainder;
APInt::sdivrem(constDelta->getValue()->getValue(),
constCoeff->getValue()->getValue(),
distance, remainder);

Generally, this makes sense. But reading the documentation for APInt, it sounds like I must somehow ensure that the representations ofconstDelta and constCoeff are the same length. Are they going to be automatically, or do I need to do something to check?

How do we set the lengths of distance and remainder? Or are they set by the sdivrem operations?

If I want to divide distance by 2, how do I create an APInt with the value of 2 and the correct length?
I’ve seen you create an SCEV with value 2. Should I do that each time?

I’m working on writing out Banerjee and Wolfe’s exact SIV test and the hardest part seems to be specifying the type of all the various numbers. I’m manipulating many constants (0, 1, and various SCEVConstants) and doing arithmetic with them. I assume it’s better (quicker, smaller) to use APInts for everything.

Any general advice?

Thanks,
Preston