[LLVMdev] Inverse of ConstantFP::get and similar functions?

Stephen Lin swlin at post.harvard.edu
Mon Jul 22 11:12:43 PDT 2013


> You can currently do this:
>   if (const ConstantVector *CV = dyn_cast<ConstantVector>(X))
>     if (Constant *Splat = CV->getSplatValue())
>       // Now you know that Splat is a splatted value, so check it for something.
>

Yes, but that's only if you want to check the vector case only; I
would like to check for either the scalar constant or the splat
vector, in the same way that ConstantFP::get creates either the scalar
constant or splat vector.

Also, that doesn't check for ConstantDataVector, either, which is the
usual canonical form.

Basically, I want the alternative to the following:

static bool IsExactlyValueConstantFP(Value *V, double D) {
  ConstantFP *CFP;
  ConstantDataVector *CDV;
  ConstantVector *CV;
  return ((CFP = dyn_cast<ConstantFP>(V)) && CFP->isExactlyValue(D)) ||
         ((CDV = dyn_cast<ConstantDataVector>(V)) &&
          (CFP = dyn_cast_or_null<ConstantFP>(CDV->getSplatValue())) &&
          CFP->isExactlyValue(D)) ||
         ((CV = dyn_cast<ConstantVector>(V)) &&
          (CFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue())) &&
          CFP->isExactlyValue(D));
}

Stephen



More information about the llvm-dev mailing list