LLVM: lib/Analysis/CmpInstAnalysis.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

18

19using namespace llvm;

20

22 switch (Pred) {

23

34

35 default:

37 }

38}

39

42 switch (Code) {

44 case 0:

52 case 7:

54 }

55 return nullptr;

56}

57

63

68 "Unexpected FCmp predicate!");

73 return nullptr;

74}

75

76std::optional

78 bool LookThruTrunc, bool AllowNonZeroC,

79 bool DecomposeAnd) {

81

82 const APInt *OrigC;

85 return std::nullopt;

86

87 bool Inverted = false;

89 Inverted = true;

91 }

92

96 return std::nullopt;

97 ++C;

99 }

100

102 switch (Pred) {

103 default:

106

107 if (C.isZero()) {

111 break;

112 }

113

116

117 Result.Mask = -FlippedSign;

120 break;

121 }

122

124

125 Result.Mask = FlippedSign;

126 Result.C = C;

128 break;

129 }

130

131 return std::nullopt;

132 }

134

135 if (C.isPowerOf2()) {

136 Result.Mask = -C;

139 break;

140 }

141

142

143 if (C.isNegatedPowerOf2()) {

144 Result.Mask = C;

145 Result.C = C;

147 break;

148 }

149

150 return std::nullopt;

151 }

154 assert(DecomposeAnd);

155 const APInt *AndC;

158 LHS = AndVal;

159 Result.Mask = *AndC;

160 Result.C = C;

161 Result.Pred = Pred;

162 break;

163 }

164

165 return std::nullopt;

166 }

167 }

168

169 if (!AllowNonZeroC && !Result.C.isZero())

170 return std::nullopt;

171

172 if (Inverted)

174

177 Result.X = X;

178 Result.Mask = Result.Mask.zext(X->getType()->getScalarSizeInBits());

179 Result.C = Result.C.zext(X->getType()->getScalarSizeInBits());

180 } else {

181 Result.X = LHS;

182 }

183

184 return Result;

185}

186

188 bool LookThruTrunc,

189 bool AllowNonZeroC,

190 bool DecomposeAnd) {

193

194 if (!ICmp->getOperand(0)->getType()->isIntOrIntVectorTy())

195 return std::nullopt;

197 ICmp->getPredicate(), LookThruTrunc,

198 AllowNonZeroC, DecomposeAnd);

199 }

201 if (Cond->getType()->isIntOrIntVectorTy(1) &&

205 Result.X = X;

206 unsigned BitWidth = X->getType()->getScalarSizeInBits();

210

211 return Result;

212 }

213

214 return std::nullopt;

215}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file contains the declarations for the subclasses of Constant, which represent the different fla...

const SmallVectorImpl< MachineOperand > & Cond

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

Class for arbitrary precision integers.

bool isNegatedPowerOf2() const

Check if this APInt's negated value is a power of two greater than zero.

static APInt getSignMask(unsigned BitWidth)

Get the SignMask for a specific bit width.

bool isPowerOf2() const

Check if this APInt's value is a power of two greater than zero.

static APInt getZero(unsigned numBits)

Get the '0' value for the specified bit-width.

static Type * makeCmpResultType(Type *opnd_type)

Create a result type for fcmp/icmp.

Predicate getStrictPredicate() const

For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.

Predicate

This enumeration lists the possible predicates for CmpInst subclasses.

@ FCMP_TRUE

1 1 1 1 Always true (always folded)

@ ICMP_SLT

signed less than

@ ICMP_SLE

signed less or equal

@ ICMP_UGE

unsigned greater or equal

@ ICMP_UGT

unsigned greater than

@ ICMP_SGT

signed greater than

@ ICMP_ULT

unsigned less than

@ ICMP_SGE

signed greater or equal

@ ICMP_ULE

unsigned less or equal

@ FCMP_FALSE

0 0 0 0 Always false (always folded)

Predicate getInversePredicate() const

For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...

This is an important base class in LLVM.

static bool isGE(Predicate P)

Return true if the predicate is SGE or UGE.

static bool isGT(Predicate P)

Return true if the predicate is SGT or UGT.

bool isEquality() const

Return true if this predicate is either EQ or NE.

static bool isEquality(Predicate P)

Return true if this predicate is either EQ or NE.

static bool isLE(Predicate P)

Return true if the predicate is SLE or ULE.

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM Value Representation.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)

Matches a register not-ed by a G_XOR.

BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)

CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)

Matches Trunc.

ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)

Match APInt while allowing poison in splat vector constants.

bool match(Val *V, const Pattern &P)

class_match< Value > m_Value()

Match an arbitrary value and ignore it.

This is an optimization pass for GlobalISel generic memory operations.

Constant * getPredForFCmpCode(unsigned Code, Type *OpTy, CmpInst::Predicate &Pred)

This is the complement of getFCmpCode.

Definition CmpInstAnalysis.cpp:64

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

bool predicatesFoldable(CmpInst::Predicate P1, CmpInst::Predicate P2)

Return true if both predicates match sign or if at least one of them is an equality comparison (which...

Definition CmpInstAnalysis.cpp:58

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

std::optional< DecomposedBitTest > decomposeBitTest(Value *Cond, bool LookThroughTrunc=true, bool AllowNonZeroC=false, bool DecomposeAnd=false)

Decompose an icmp into the form ((X & Mask) pred C) if possible.

Definition CmpInstAnalysis.cpp:187

constexpr unsigned BitWidth

unsigned getICmpCode(CmpInst::Predicate Pred)

Encode a icmp predicate into a three bit mask.

Definition CmpInstAnalysis.cpp:21

std::optional< DecomposedBitTest > decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred, bool LookThroughTrunc=true, bool AllowNonZeroC=false, bool DecomposeAnd=false)

Decompose an icmp into the form ((X & Mask) pred C) if possible.

Definition CmpInstAnalysis.cpp:77

Constant * getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, CmpInst::Predicate &Pred)

This is the complement of getICmpCode.

Definition CmpInstAnalysis.cpp:40

Represents the operation icmp (X & Mask) pred C, where pred can only be eq or ne.