llvm::ConstantFoldInstOperands

Attempt to constant fold an instruction with the specified operands.

Synopsis

Declared in <llvm/Analysis/ConstantFolding.h>

Constant*
ConstantFoldInstOperands(
    Instruction const* I,
    ArrayRef<Constant*> Ops,
    DataLayout const& DL,
    TargetLibraryInfo const* TLI = nullptr,
    bool AllowNonDeterministic = true);

Description

If successful, the constant result is returned, if not, null is returned. Note that this function can fail when attempting to fold instructions like loads and stores, which have no constant expression form.

In some cases, constant folding may return one value chosen from a set of multiple legal return values. For example, the exact bit pattern of NaN results is not guaranteed. Using such a result is usually only valid if all uses of the original operation are replaced by the constant-folded result. The AllowNonDeterministic parameter controls whether this is allowed.

Return Value

The folded constant on success, or null on failure.

Parameters

NameDescription
IInstruction whose opcode and attributes guide folding.
OpsConstant operands to fold with.
DLData layout used for type sizes and pointer widths.
TLIOptional target library info for libcall folding.
AllowNonDeterministicWhether non-deterministic fold results are OK.