LLVM 18.0.0git
InstructionSimplify.h
Go to the documentation of this file.
1//===-- InstructionSimplify.h - Fold instrs into simpler forms --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares routines for folding instructions into simpler forms
10// that do not require creating new instructions. This does constant folding
11// ("add i32 1, 1" -> "2") but can also handle non-constant operands, either
12// returning a constant ("and i32 %x, 0" -> "0") or an already existing value
13// ("and i32 %x, %x" -> "%x"). If the simplification is also an instruction
14// then it dominates the original instruction.
15//
16// These routines implicitly resolve undef uses. The easiest way to be safe when
17// using these routines to obtain simplified values for existing instructions is
18// to always replace all uses of the instructions with the resulting simplified
19// values. This will prevent other code from seeing the same undef uses and
20// resolving them to different values.
21//
22// They require that all the IR that they encounter be valid and inserted into a
23// parent function.
24//
25// Additionally, these routines can't simplify to the instructions that are not
26// def-reachable, meaning we can't just scan the basic block for instructions
27// to simplify to.
28//
29//===----------------------------------------------------------------------===//
30
31#ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
32#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
33
35
36namespace llvm {
37
38template <typename T, typename... TArgs> class AnalysisManager;
39template <class T> class ArrayRef;
40class AssumptionCache;
41class BinaryOperator;
42class CallBase;
43class DataLayout;
44class DominatorTree;
45class Function;
46class Instruction;
47struct LoopStandardAnalysisResults;
48class MDNode;
49class Pass;
50template <class T, unsigned n> class SmallSetVector;
51class TargetLibraryInfo;
52class Type;
53class Value;
54
55/// InstrInfoQuery provides an interface to query additional information for
56/// instructions like metadata or keywords like nsw, which provides conservative
57/// results if the users specified it is safe to use.
59 InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
60 InstrInfoQuery() = default;
61 bool UseInstrInfo = true;
62
63 MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
64 if (UseInstrInfo)
65 return I->getMetadata(KindID);
66 return nullptr;
67 }
68
69 template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
70 if (UseInstrInfo)
71 return Op->hasNoUnsignedWrap();
72 return false;
73 }
74
75 template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
76 if (UseInstrInfo)
77 return Op->hasNoSignedWrap();
78 return false;
79 }
80
81 bool isExact(const BinaryOperator *Op) const {
82 if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
83 return cast<PossiblyExactOperator>(Op)->isExact();
84 return false;
85 }
86
87 template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
88 if (UseInstrInfo)
89 return Op->hasNoSignedZeros();
90 return false;
91 }
92};
93
95 const DataLayout &DL;
96 const TargetLibraryInfo *TLI = nullptr;
97 const DominatorTree *DT = nullptr;
98 AssumptionCache *AC = nullptr;
99 const Instruction *CxtI = nullptr;
100
101 // Wrapper to query additional information for instructions like metadata or
102 // keywords like nsw, which provides conservative results if those cannot
103 // be safely used.
105
106 /// Controls whether simplifications are allowed to constrain the range of
107 /// possible values for uses of undef. If it is false, simplifications are not
108 /// allowed to assume a particular value for a use of undef for example.
109 bool CanUseUndef = true;
110
111 SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
112 : DL(DL), CxtI(CXTI) {}
113
115 const DominatorTree *DT = nullptr,
116 AssumptionCache *AC = nullptr,
117 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
118 bool CanUseUndef = true)
119 : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
122 SimplifyQuery Copy(*this);
123 Copy.CxtI = I;
124 return Copy;
125 }
127 SimplifyQuery Copy(*this);
128 Copy.CanUseUndef = false;
129 return Copy;
130 }
131
132 /// If CanUseUndef is true, returns whether \p V is undef.
133 /// Otherwise always return false.
134 bool isUndefValue(Value *V) const {
135 if (!CanUseUndef)
136 return false;
137
138 using namespace PatternMatch;
139 return match(V, m_Undef());
140 }
141};
142
143// NOTE: the explicit multiple argument versions of these functions are
144// deprecated.
145// Please use the SimplifyQuery versions in new code.
146
147/// Given operands for an Add, fold the result or return null.
148Value *simplifyAddInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW,
149 const SimplifyQuery &Q);
150
151/// Given operands for a Sub, fold the result or return null.
152Value *simplifySubInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW,
153 const SimplifyQuery &Q);
154
155/// Given operands for a Mul, fold the result or return null.
156Value *simplifyMulInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW,
157 const SimplifyQuery &Q);
158
159/// Given operands for an SDiv, fold the result or return null.
160Value *simplifySDivInst(Value *LHS, Value *RHS, bool IsExact,
161 const SimplifyQuery &Q);
162
163/// Given operands for a UDiv, fold the result or return null.
164Value *simplifyUDivInst(Value *LHS, Value *RHS, bool IsExact,
165 const SimplifyQuery &Q);
166
167/// Given operands for an SRem, fold the result or return null.
168Value *simplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q);
169
170/// Given operands for a URem, fold the result or return null.
171Value *simplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q);
172
173/// Given operand for an FNeg, fold the result or return null.
174Value *simplifyFNegInst(Value *Op, FastMathFlags FMF, const SimplifyQuery &Q);
175
176
177/// Given operands for an FAdd, fold the result or return null.
178Value *
179simplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF,
180 const SimplifyQuery &Q,
183
184/// Given operands for an FSub, fold the result or return null.
185Value *
186simplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF,
187 const SimplifyQuery &Q,
190
191/// Given operands for an FMul, fold the result or return null.
192Value *
193simplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF,
194 const SimplifyQuery &Q,
197
198/// Given operands for the multiplication of a FMA, fold the result or return
199/// null. In contrast to simplifyFMulInst, this function will not perform
200/// simplifications whose unrounded results differ when rounded to the argument
201/// type.
202Value *simplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF,
203 const SimplifyQuery &Q,
206
207/// Given operands for an FDiv, fold the result or return null.
208Value *
209simplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF,
210 const SimplifyQuery &Q,
213
214/// Given operands for an FRem, fold the result or return null.
215Value *
216simplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF,
217 const SimplifyQuery &Q,
220
221/// Given operands for a Shl, fold the result or return null.
222Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
223 const SimplifyQuery &Q);
224
225/// Given operands for a LShr, fold the result or return null.
226Value *simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
227 const SimplifyQuery &Q);
228
229/// Given operands for a AShr, fold the result or return nulll.
230Value *simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact,
231 const SimplifyQuery &Q);
232
233/// Given operands for an And, fold the result or return null.
234Value *simplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q);
235
236/// Given operands for an Or, fold the result or return null.
237Value *simplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q);
238
239/// Given operands for an Xor, fold the result or return null.
240Value *simplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q);
241
242/// Given operands for an ICmpInst, fold the result or return null.
243Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
244 const SimplifyQuery &Q);
245
246/// Given operands for an FCmpInst, fold the result or return null.
247Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
248 FastMathFlags FMF, const SimplifyQuery &Q);
249
250/// Given operands for a SelectInst, fold the result or return null.
251Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
252 const SimplifyQuery &Q);
253
254/// Given operands for a GetElementPtrInst, fold the result or return null.
255Value *simplifyGEPInst(Type *SrcTy, Value *Ptr, ArrayRef<Value *> Indices,
256 bool InBounds, const SimplifyQuery &Q);
257
258/// Given operands for an InsertValueInst, fold the result or return null.
259Value *simplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
260 const SimplifyQuery &Q);
261
262/// Given operands for an InsertElement, fold the result or return null.
263Value *simplifyInsertElementInst(Value *Vec, Value *Elt, Value *Idx,
264 const SimplifyQuery &Q);
265
266/// Given operands for an ExtractValueInst, fold the result or return null.
267Value *simplifyExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
268 const SimplifyQuery &Q);
269
270/// Given operands for an ExtractElementInst, fold the result or return null.
271Value *simplifyExtractElementInst(Value *Vec, Value *Idx,
272 const SimplifyQuery &Q);
273
274/// Given operands for a CastInst, fold the result or return null.
275Value *simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty,
276 const SimplifyQuery &Q);
277
278/// Given operands for a ShuffleVectorInst, fold the result or return null.
279/// See class ShuffleVectorInst for a description of the mask representation.
280Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1, ArrayRef<int> Mask,
281 Type *RetTy, const SimplifyQuery &Q);
282
283//=== Helper functions for higher up the class hierarchy.
284
285/// Given operands for a CmpInst, fold the result or return null.
286Value *simplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
287 const SimplifyQuery &Q);
288
289/// Given operand for a UnaryOperator, fold the result or return null.
290Value *simplifyUnOp(unsigned Opcode, Value *Op, const SimplifyQuery &Q);
291
292/// Given operand for a UnaryOperator, fold the result or return null.
293/// Try to use FastMathFlags when folding the result.
294Value *simplifyUnOp(unsigned Opcode, Value *Op, FastMathFlags FMF,
295 const SimplifyQuery &Q);
296
297/// Given operands for a BinaryOperator, fold the result or return null.
298Value *simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
299 const SimplifyQuery &Q);
300
301/// Given operands for a BinaryOperator, fold the result or return null.
302/// Try to use FastMathFlags when folding the result.
303Value *simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, FastMathFlags FMF,
304 const SimplifyQuery &Q);
305
306/// Given a callsite, callee, and arguments, fold the result or return null.
307Value *simplifyCall(CallBase *Call, Value *Callee, ArrayRef<Value *> Args,
308 const SimplifyQuery &Q);
309
310/// Given a constrained FP intrinsic call, tries to compute its simplified
311/// version. Returns a simplified result or null.
312///
313/// This function provides an additional contract: it guarantees that if
314/// simplification succeeds that the intrinsic is side effect free. As a result,
315/// successful simplification can be used to delete the intrinsic not just
316/// replace its result.
317Value *simplifyConstrainedFPCall(CallBase *Call, const SimplifyQuery &Q);
318
319/// Given an operand for a Freeze, see if we can fold the result.
320/// If not, this returns null.
321Value *simplifyFreezeInst(Value *Op, const SimplifyQuery &Q);
322
323/// Given a load instruction and its pointer operand, fold the result or return
324/// null.
325Value *simplifyLoadInst(LoadInst *LI, Value *PtrOp, const SimplifyQuery &Q);
326
327/// See if we can compute a simplified version of this instruction. If not,
328/// return null.
329Value *simplifyInstruction(Instruction *I, const SimplifyQuery &Q);
330
331/// Like \p simplifyInstruction but the operands of \p I are replaced with
332/// \p NewOps. Returns a simplified value, or null if none was found.
333Value *
334simplifyInstructionWithOperands(Instruction *I, ArrayRef<Value *> NewOps,
335 const SimplifyQuery &Q);
336
337/// See if V simplifies when its operand Op is replaced with RepOp. If not,
338/// return null.
339/// AllowRefinement specifies whether the simplification can be a refinement
340/// (e.g. 0 instead of poison), or whether it needs to be strictly identical.
341/// Op and RepOp can be assumed to not be poison when determining refinement.
342///
343/// If DropFlags is passed, then the replacement result is only valid if
344/// poison-generating flags/metadata on those instructions are dropped. This
345/// is only useful in conjunction with AllowRefinement=false.
346Value *
347simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
348 const SimplifyQuery &Q, bool AllowRefinement,
349 SmallVectorImpl<Instruction *> *DropFlags = nullptr);
350
351/// Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
352///
353/// This first performs a normal RAUW of I with SimpleV. It then recursively
354/// attempts to simplify those users updated by the operation. The 'I'
355/// instruction must not be equal to the simplified value 'SimpleV'.
356/// If UnsimplifiedUsers is provided, instructions that could not be simplified
357/// are added to it.
358///
359/// The function returns true if any simplifications were performed.
361 Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI = nullptr,
362 const DominatorTree *DT = nullptr, AssumptionCache *AC = nullptr,
363 SmallSetVector<Instruction *, 8> *UnsimplifiedUsers = nullptr);
364
365// These helper functions return a SimplifyQuery structure that contains as
366// many of the optional analysis we use as are currently valid. This is the
367// strongly preferred way of constructing SimplifyQuery in passes.
368const SimplifyQuery getBestSimplifyQuery(Pass &, Function &);
369template <class T, class... TArgs>
370const SimplifyQuery getBestSimplifyQuery(AnalysisManager<T, TArgs...> &,
371 Function &);
372const SimplifyQuery getBestSimplifyQuery(LoopStandardAnalysisResults &,
373 const DataLayout &);
374} // end namespace llvm
375
376#endif
RelocType Type
Definition: COFFYAML.cpp:391
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
print lazy value Lazy Value Info Printer Pass
#define I(x, y, z)
Definition: MD5.cpp:58
#define T
const SmallVectorImpl< MachineOperand > & Cond
Value * RHS
Value * LHS
A cache of @llvm.assume calls within a function.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
Metadata node.
Definition: Metadata.h:950
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition: Value.h:74
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
auto m_Undef()
Match an arbitrary undef constant.
Definition: PatternMatch.h:136
ExceptionBehavior
Exception behavior used for floating point operations.
Definition: FPEnv.h:38
@ ebIgnore
This corresponds to "fpexcept.ignore".
Definition: FPEnv.h:39
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Value * simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q)
Given operands for a AShr, fold the result or return nulll.
Value * simplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FMul, fold the result or return null.
Value * simplifyFreezeInst(Value *Op, const SimplifyQuery &Q)
Given an operand for a Freeze, see if we can fold the result.
Value * simplifySDivInst(Value *LHS, Value *RHS, bool IsExact, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
Value * simplifyUnOp(unsigned Opcode, Value *Op, const SimplifyQuery &Q)
Given operand for a UnaryOperator, fold the result or return null.
Value * simplifyMulInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Mul, fold the result or return null.
Value * simplifyInstructionWithOperands(Instruction *I, ArrayRef< Value * > NewOps, const SimplifyQuery &Q)
Like simplifyInstruction but the operands of I are replaced with NewOps.
Value * simplifyCall(CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q)
Given a callsite, callee, and arguments, fold the result or return null.
Value * simplifyShuffleVectorInst(Value *Op0, Value *Op1, ArrayRef< int > Mask, Type *RetTy, const SimplifyQuery &Q)
Given operands for a ShuffleVectorInst, fold the result or return null.
Value * simplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Or, fold the result or return null.
Value * simplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Xor, fold the result or return null.
Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
Value * simplifySubInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Sub, fold the result or return null.
Value * simplifyAddInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, SmallSetVector< Instruction *, 8 > *UnsimplifiedUsers=nullptr)
Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
Value * simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Shl, fold the result or return null.
Value * simplifyFNegInst(Value *Op, FastMathFlags FMF, const SimplifyQuery &Q)
Given operand for an FNeg, fold the result or return null.
Value * simplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FSub, fold the result or return null.
Value * simplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FRem, fold the result or return null.
Value * simplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FAdd, fold the result or return null.
Value * simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q)
Given operands for a LShr, fold the result or return null.
Value * simplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an And, fold the result or return null.
Value * simplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
Value * simplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an InsertValueInst, fold the result or return null.
Value * simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an ICmpInst, fold the result or return null.
Value * simplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FDiv, fold the result or return null.
Value * simplifyLoadInst(LoadInst *LI, Value *PtrOp, const SimplifyQuery &Q)
Given a load instruction and its pointer operand, fold the result or return null.
Value * simplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for the multiplication of a FMA, fold the result or return null.
Value * simplifyConstrainedFPCall(CallBase *Call, const SimplifyQuery &Q)
Given a constrained FP intrinsic call, tries to compute its simplified version.
Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
Value * simplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
Value * simplifyUDivInst(Value *LHS, Value *RHS, bool IsExact, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
DWARFExpression::Operation Op
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
ArrayRef(const T &OneElt) -> ArrayRef< T >
Value * simplifyInsertElementInst(Value *Vec, Value *Elt, Value *Idx, const SimplifyQuery &Q)
Given operands for an InsertElement, fold the result or return null.
Value * simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags=nullptr)
See if V simplifies when its operand Op is replaced with RepOp.
Value * simplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
Value * simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FCmpInst, fold the result or return null.
Value * simplifyGEPInst(Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, bool InBounds, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
Value * simplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a URem, fold the result or return null.
Value * simplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &Q)
Given operands for an ExtractElementInst, fold the result or return null.
Value * simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q)
Given operands for a SelectInst, fold the result or return null.
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
bool isExact(const BinaryOperator *Op) const
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
bool hasNoSignedZeros(const InstT *Op) const
bool hasNoSignedWrap(const InstT *Op) const
InstrInfoQuery()=default
bool hasNoUnsignedWrap(const InstT *Op) const
const DataLayout & DL
const Instruction * CxtI
SimplifyQuery(const DataLayout &DL, const Instruction *CXTI=nullptr)
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
const DominatorTree * DT
bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
AssumptionCache * AC
SimplifyQuery getWithInstruction(Instruction *I) const
const TargetLibraryInfo * TLI
SimplifyQuery(const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CXTI=nullptr, bool UseInstrInfo=true, bool CanUseUndef=true)
SimplifyQuery getWithoutUndef() const
const InstrInfoQuery IIQ