llvm::matchSelectPattern

Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out parameter results if we successfully match.

Synopsis

Declared in <llvm/Analysis/ValueTracking.h>

SelectPatternResult
matchSelectPattern(
    Value* V,
    Value*& LHS,
    Value*& RHS,
    Instruction::CastOps* CastOp = nullptr,
    unsigned int Depth = 0);

Description

For ABS/NABS, LHS will be set to the input to the abs idiom. RHS will be the negation instruction from the idiom.

If CastOp is not nullptr, also match MIN/MAX idioms where the type does not match that of the original select. If this is the case, the cast operation (one of Trunc,SExt,Zext) that must be done to transform the type of LHS and RHS into the type of V is returned in CastOp.

For example: %1 = icmp slt i32 %a, i32 4 %2 = sext i32 %a to i64 %3 = select i1 %1, i64 %2, i64 4

-> LHS = %a, RHS = i32 4, *CastOp = Instruction::SExt

Return Value

Matched select pattern result.

Parameters

NameDescription
VSelect (or equivalent) value to match.
LHSOutput left-hand operand of the matched idiom.
RHSOutput right-hand operand of the matched idiom.
CastOpOptional output cast needed to unify operand types.
DepthCurrent recursion depth for this query.