Attempt to constant fold an instruction with the specified operands.
Declared in <llvm/Analysis/ConstantFolding.h>
Constant*
ConstantFoldInstOperands(
Instruction const* I,
ArrayRef<Constant*> Ops,
DataLayout const& DL,
TargetLibraryInfo const* TLI = nullptr,
bool AllowNonDeterministic = true);
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.
The folded constant on success, or null on failure.
| Name | Description |
|---|---|
| I | Instruction whose opcode and attributes guide folding. |
| Ops | Constant operands to fold with. |
| DL | Data layout used for type sizes and pointer widths. |
| TLI | Optional target library info for libcall folding. |
| AllowNonDeterministic | Whether non-deterministic fold results are OK. |