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

Hal Finkel hfinkel at anl.gov
Mon Jul 22 10:44:19 PDT 2013

----- Original Message -----
> Hi,
> I noticed that ConstantFP::get automatically returns the
> appropriately
> types Constant depending on the LLVM type passed in (i.e. if called
> with a vector, it returns a splat vector with the given constant).
> Is there any simple way to do the inverse of this function? i.e.,
> given a llvm::Value, check whether it is either a scalar of the given
> constant value or a splat vector with the given constant value? I
> can't seem to find any, and it doesn't look like the pattern matching
> interface provides something similar to this either.
> If this doesn't exist, then I propose adding static versions of all
> the various ConstantFoo::isBar() functions, which take a value as a
> parameter and check that the value is of a constant of the
> appropriate
> type and value (checking for vectors matching the predicate in the
> vector case).
> For example:
>    static bool ConstantFP::isExactlyValue(Value *V, double D);

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.


> would return true is V is ConstantFP, a splat ConstantVector, or a
> ConstantDataVector with the appropriate type. Similarly,
>    static bool ConstantFP::isZero(Value *V);
> would return true if V is a ConstantFP with zero of either sign, a
> ConstantVector or ConstantDataVector with all zeros of either sign,
> or
> a zero initializer...
> Anyone have any thoughts, and/or can point me to somewhere where this
> kind of thing is already implemented?
> Thanks,
> Stephen
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory

More information about the llvm-dev mailing list