llvm::ConstantFoldInstruction

Try to constant fold the specified instruction.

Synopsis

Declared in <llvm/Analysis/ConstantFolding.h>

Constant*
ConstantFoldInstruction(
    Instruction const* I,
    DataLayout const& DL,
    TargetLibraryInfo const* TLI = nullptr);

Description

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

Return Value

The folded constant on success, or null on failure.

Parameters

NameDescription
IInstruction to attempt to fold.
DLData layout used for type sizes and pointer widths.
TLIOptional target library info for libcall folding.