LLVM 22.0.0git
InstCombiner.h
Go to the documentation of this file.
1//===- InstCombiner.h - InstCombine implementation --------------*- 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/// \file
9///
10/// This file provides the interface for the instcombine pass implementation.
11/// The interface is used for generic transformations in this folder and
12/// target specific combinations in the targets.
13/// The visitor implementation is in \c InstCombinerImpl in
14/// \c InstCombineInternal.h.
15///
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINER_H
19#define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINER_H
20
26#include "llvm/IR/IRBuilder.h"
28#include "llvm/Support/Debug.h"
30#include <cassert>
31
32#define DEBUG_TYPE "instcombine"
34
35namespace llvm {
36
37class AAResults;
38class AssumptionCache;
39class OptimizationRemarkEmitter;
40class ProfileSummaryInfo;
41class TargetLibraryInfo;
42class TargetTransformInfo;
43
44/// The core instruction combiner logic.
45///
46/// This class provides both the logic to recursively visit instructions and
47/// combine them.
49 /// Only used to call target specific intrinsic combining.
50 /// It must **NOT** be used for any other purpose, as InstCombine is a
51 /// target-independent canonicalization transform.
52 TargetTransformInfo &TTIForTargetIntrinsicsOnly;
53
54public:
55 /// Maximum size of array considered when transforming.
57
58 /// An IRBuilder that automatically inserts new instructions into the
59 /// worklist.
62
63protected:
64 /// A worklist of the instructions that need to be simplified.
66
67 // Mode in which we are running the combiner.
68 const bool MinimizeSize;
69
71
72 // Required analyses.
76 const DataLayout &DL;
83
85
86 bool MadeIRChange = false;
87
88 /// Edges that are known to never be taken.
90
91 /// Order of predecessors to canonicalize phi nodes towards.
93
94 /// Backedges, used to avoid pushing instructions across backedges in cases
95 /// where this may result in infinite combine loops. For irreducible loops
96 /// this picks an arbitrary backedge.
98 bool ComputedBackEdges = false;
99
100public:
113
114 virtual ~InstCombiner() = default;
115
116 /// Return the source operand of a potentially bitcasted value while
117 /// optionally checking if it has one use. If there is no bitcast or the one
118 /// use check is not met, return the input value itself.
119 static Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
120 if (auto *BitCast = dyn_cast<BitCastInst>(V))
121 if (!OneUseOnly || BitCast->hasOneUse())
122 return BitCast->getOperand(0);
123
124 // V is not a bitcast or V has more than one use and OneUseOnly is true.
125 return V;
126 }
127
128 /// Assign a complexity or rank value to LLVM Values. This is used to reduce
129 /// the amount of pattern matching needed for compares and commutative
130 /// instructions. For example, if we have:
131 /// icmp ugt X, Constant
132 /// or
133 /// xor (add X, Constant), cast Z
134 ///
135 /// We do not have to consider the commuted variants of these patterns because
136 /// canonicalization based on complexity guarantees the above ordering.
137 ///
138 /// This routine maps IR values to various complexity ranks:
139 /// 0 -> undef
140 /// 1 -> Constants
141 /// 2 -> Cast and (f)neg/not instructions
142 /// 3 -> Other instructions and arguments
143 static unsigned getComplexity(Value *V) {
144 if (isa<Constant>(V))
145 return isa<UndefValue>(V) ? 0 : 1;
146
150 return 2;
151
152 return 3;
153 }
154
155 /// Predicate canonicalization reduces the number of patterns that need to be
156 /// matched by other transforms. For example, we may swap the operands of a
157 /// conditional branch or select to create a compare with a canonical
158 /// (inverted) predicate which is then more likely to be matched with other
159 /// values.
161 switch (Pred) {
162 case CmpInst::ICMP_NE:
167 // TODO: There are 16 FCMP predicates. Should others be (not) canonical?
171 return false;
172 default:
173 return true;
174 }
175 }
176
177 /// Add one to a Constant
179 return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));
180 }
181
182 /// Subtract one from a Constant
184 return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1));
185 }
186
188 // a ? b : false and a ? true : b are the canonical form of logical and/or.
189 // This includes !a ? b : false and !a ? true : b. Absorbing the not into
190 // the select by swapping operands would break recognition of this pattern
191 // in other analyses, so don't do that.
196 }
197
198 /// Return nonnull value if V is free to invert under the condition of
199 /// WillInvertAllUses.
200 /// If Builder is nonnull, it will return a simplified ~V.
201 /// If Builder is null, it will return an arbitrary nonnull value (not
202 /// dereferenceable).
203 /// If the inversion will consume instructions, `DoesConsume` will be set to
204 /// true. Otherwise it will be false.
205 Value *getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
206 BuilderTy *Builder, bool &DoesConsume,
207 unsigned Depth);
208
209 Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
210 BuilderTy *Builder, bool &DoesConsume) {
211 DoesConsume = false;
212 return getFreelyInvertedImpl(V, WillInvertAllUses, Builder, DoesConsume,
213 /*Depth*/ 0);
214 }
215
216 Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
218 bool Unused;
219 return getFreelyInverted(V, WillInvertAllUses, Builder, Unused);
220 }
221
222 /// Return true if the specified value is free to invert (apply ~ to).
223 /// This happens in cases where the ~ can be eliminated. If WillInvertAllUses
224 /// is true, work under the assumption that the caller intends to remove all
225 /// uses of V and only keep uses of ~V.
226 ///
227 /// See also: canFreelyInvertAllUsersOf()
228 bool isFreeToInvert(Value *V, bool WillInvertAllUses,
229 bool &DoesConsume) {
230 return getFreelyInverted(V, WillInvertAllUses, /*Builder*/ nullptr,
231 DoesConsume) != nullptr;
232 }
233
234 bool isFreeToInvert(Value *V, bool WillInvertAllUses) {
235 bool Unused;
236 return isFreeToInvert(V, WillInvertAllUses, Unused);
237 }
238
239 /// Given i1 V, can every user of V be freely adapted if V is changed to !V ?
240 /// InstCombine's freelyInvertAllUsersOf() must be kept in sync with this fn.
241 /// NOTE: for Instructions only!
242 ///
243 /// See also: isFreeToInvert()
245 // Look at every user of V.
246 for (Use &U : V->uses()) {
247 if (U.getUser() == IgnoredUser)
248 continue; // Don't consider this user.
249
250 auto *I = cast<Instruction>(U.getUser());
251 switch (I->getOpcode()) {
252 case Instruction::Select:
253 if (U.getOperandNo() != 0) // Only if the value is used as select cond.
254 return false;
256 return false;
257 break;
258 case Instruction::Br:
259 assert(U.getOperandNo() == 0 && "Must be branching on that value.");
260 break; // Free to invert by swapping true/false values/destinations.
261 case Instruction::Xor: // Can invert 'xor' if it's a 'not', by ignoring
262 // it.
264 return false; // Not a 'not'.
265 break;
266 default:
267 return false; // Don't know, likely not freely invertible.
268 }
269 // So far all users were free to invert...
270 }
271 return true; // Can freely invert all users!
272 }
273
274 /// Some binary operators require special handling to avoid poison and
275 /// undefined behavior. If a constant vector has undef elements, replace those
276 /// undefs with identity constants if possible because those are always safe
277 /// to execute. If no identity constant exists, replace undef with some other
278 /// safe constant.
279 static Constant *
281 bool IsRHSConstant) {
282 auto *InVTy = cast<FixedVectorType>(In->getType());
283
284 Type *EltTy = InVTy->getElementType();
285 auto *SafeC = ConstantExpr::getBinOpIdentity(Opcode, EltTy, IsRHSConstant);
286 if (!SafeC) {
287 // TODO: Should this be available as a constant utility function? It is
288 // similar to getBinOpAbsorber().
289 if (IsRHSConstant) {
290 switch (Opcode) {
291 case Instruction::SRem: // X % 1 = 0
292 case Instruction::URem: // X %u 1 = 0
293 SafeC = ConstantInt::get(EltTy, 1);
294 break;
295 case Instruction::FRem: // X % 1.0 (doesn't simplify, but it is safe)
296 SafeC = ConstantFP::get(EltTy, 1.0);
297 break;
298 default:
300 "Only rem opcodes have no identity constant for RHS");
301 }
302 } else {
303 switch (Opcode) {
304 case Instruction::Shl: // 0 << X = 0
305 case Instruction::LShr: // 0 >>u X = 0
306 case Instruction::AShr: // 0 >> X = 0
307 case Instruction::SDiv: // 0 / X = 0
308 case Instruction::UDiv: // 0 /u X = 0
309 case Instruction::SRem: // 0 % X = 0
310 case Instruction::URem: // 0 %u X = 0
311 case Instruction::Sub: // 0 - X (doesn't simplify, but it is safe)
312 case Instruction::FSub: // 0.0 - X (doesn't simplify, but it is safe)
313 case Instruction::FDiv: // 0.0 / X (doesn't simplify, but it is safe)
314 case Instruction::FRem: // 0.0 % X = 0
315 SafeC = Constant::getNullValue(EltTy);
316 break;
317 default:
318 llvm_unreachable("Expected to find identity constant for opcode");
319 }
320 }
321 }
322 assert(SafeC && "Must have safe constant for binop");
323 unsigned NumElts = InVTy->getNumElements();
324 SmallVector<Constant *, 16> Out(NumElts);
325 for (unsigned i = 0; i != NumElts; ++i) {
326 Constant *C = In->getAggregateElement(i);
327 Out[i] = isa<UndefValue>(C) ? SafeC : C;
328 }
329 return ConstantVector::get(Out);
330 }
331
333
336 DominatorTree &getDominatorTree() const { return DT; }
337 const DataLayout &getDataLayout() const { return DL; }
338 const SimplifyQuery &getSimplifyQuery() const { return SQ; }
344
345 // Call target specific combiners
346 std::optional<Instruction *> targetInstCombineIntrinsic(IntrinsicInst &II);
347 std::optional<Value *>
348 targetSimplifyDemandedUseBitsIntrinsic(IntrinsicInst &II, APInt DemandedMask,
349 KnownBits &Known,
350 bool &KnownBitsComputed);
351 std::optional<Value *> targetSimplifyDemandedVectorEltsIntrinsic(
352 IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
353 APInt &UndefElts2, APInt &UndefElts3,
354 std::function<void(Instruction *, unsigned, APInt, APInt &)>
355 SimplifyAndSetOp);
356
357 void computeBackEdges();
358 bool isBackEdge(const BasicBlock *From, const BasicBlock *To) {
361 return BackEdges.contains({From, To});
362 }
363
364 /// Inserts an instruction \p New before instruction \p Old
365 ///
366 /// Also adds the new instruction to the worklist and returns \p New so that
367 /// it is suitable for use as the return from the visitation patterns.
369 assert(New && !New->getParent() &&
370 "New instruction already inserted into a basic block!");
371 New->insertBefore(Old); // Insert inst
372 Worklist.add(New);
373 return New;
374 }
375
376 /// Same as InsertNewInstBefore, but also sets the debug loc.
378 New->setDebugLoc(Old->getDebugLoc());
379 return InsertNewInstBefore(New, Old);
380 }
381
382 /// A combiner-aware RAUW-like routine.
383 ///
384 /// This method is to be used when an instruction is found to be dead,
385 /// replaceable with another preexisting expression. Here we add all uses of
386 /// I to the worklist, replace all uses of I with the new value, then return
387 /// I, so that the inst combiner will know that I was modified.
389 // If there are no uses to replace, then we return nullptr to indicate that
390 // no changes were made to the program.
391 if (I.use_empty()) return nullptr;
392
393 Worklist.pushUsersToWorkList(I); // Add all modified instrs to worklist.
394
395 // If we are replacing the instruction with itself, this must be in a
396 // segment of unreachable code, so just clobber the instruction.
397 if (&I == V)
398 V = PoisonValue::get(I.getType());
399
400 LLVM_DEBUG(dbgs() << "IC: Replacing " << I << "\n"
401 << " with " << *V << '\n');
402
403 // If V is a new unnamed instruction, take the name from the old one.
404 if (V->use_empty() && isa<Instruction>(V) && !V->hasName() && I.hasName())
405 V->takeName(&I);
406
407 I.replaceAllUsesWith(V);
408 return &I;
409 }
410
411 /// Replace operand of instruction and add old operand to the worklist.
413 Value *OldOp = I.getOperand(OpNum);
414 I.setOperand(OpNum, V);
415 Worklist.handleUseCountDecrement(OldOp);
416 return &I;
417 }
418
419 /// Replace use and add the previously used value to the worklist.
420 void replaceUse(Use &U, Value *NewValue) {
421 Value *OldOp = U;
422 U = NewValue;
423 Worklist.handleUseCountDecrement(OldOp);
424 }
425
426 /// Combiner aware instruction erasure.
427 ///
428 /// When dealing with an instruction that has side effects or produces a void
429 /// value, we can't rely on DCE to delete the instruction. Instead, visit
430 /// methods should return the value returned by this function.
432
433 void computeKnownBits(const Value *V, KnownBits &Known,
434 const Instruction *CxtI, unsigned Depth = 0) const {
435 llvm::computeKnownBits(V, Known, SQ.getWithInstruction(CxtI), Depth);
436 }
437
439 unsigned Depth = 0) const {
440 return llvm::computeKnownBits(V, SQ.getWithInstruction(CxtI), Depth);
441 }
442
443 bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
444 const Instruction *CxtI = nullptr,
445 unsigned Depth = 0) {
446 return llvm::isKnownToBeAPowerOfTwo(V, OrZero, SQ.getWithInstruction(CxtI),
447 Depth);
448 }
449
450 bool MaskedValueIsZero(const Value *V, const APInt &Mask,
451 const Instruction *CxtI = nullptr,
452 unsigned Depth = 0) const {
453 return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
454 }
455
456 unsigned ComputeNumSignBits(const Value *Op,
457 const Instruction *CxtI = nullptr,
458 unsigned Depth = 0) const {
459 return llvm::ComputeNumSignBits(Op, DL, &AC, CxtI, &DT, Depth);
460 }
461
463 const Instruction *CxtI = nullptr,
464 unsigned Depth = 0) const {
465 return llvm::ComputeMaxSignificantBits(Op, DL, &AC, CxtI, &DT, Depth);
466 }
467
469 const Value *RHS,
470 const Instruction *CxtI,
471 bool IsNSW = false) const {
473 LHS, RHS, SQ.getWithInstruction(CxtI), IsNSW);
474 }
475
477 const Instruction *CxtI) const {
479 SQ.getWithInstruction(CxtI));
480 }
481
485 const Instruction *CxtI) const {
487 SQ.getWithInstruction(CxtI));
488 }
489
493 const Instruction *CxtI) const {
495 SQ.getWithInstruction(CxtI));
496 }
497
499 const Value *RHS,
500 const Instruction *CxtI) const {
502 SQ.getWithInstruction(CxtI));
503 }
504
506 const Instruction *CxtI) const {
508 SQ.getWithInstruction(CxtI));
509 }
510
511 virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
512 const APInt &DemandedMask, KnownBits &Known,
513 const SimplifyQuery &Q,
514 unsigned Depth = 0) = 0;
515
516 bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
517 const APInt &DemandedMask, KnownBits &Known) {
518 return SimplifyDemandedBits(I, OpNo, DemandedMask, Known,
519 SQ.getWithInstruction(I));
520 }
521
522 virtual Value *
523 SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &UndefElts,
524 unsigned Depth = 0,
525 bool AllowMultipleUsers = false) = 0;
526
527 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
528};
529
530} // namespace llvm
531
532#undef DEBUG_TYPE
533
534#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
#define I(x, y, z)
Definition MD5.cpp:58
uint64_t IntrinsicInst * II
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:708
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:683
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:702
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:686
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:685
@ ICMP_NE
not equal
Definition InstrTypes.h:700
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:706
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:704
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:165
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2780
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
SimplifyQuery SQ
const DataLayout & getDataLayout() const
unsigned ComputeMaxSignificantBits(const Value *Op, const Instruction *CxtI=nullptr, unsigned Depth=0) const
bool isFreeToInvert(Value *V, bool WillInvertAllUses)
virtual Instruction * eraseInstFromFunction(Instruction &I)=0
Combiner aware instruction erasure.
IRBuilder< TargetFolder, IRBuilderCallbackInserter > BuilderTy
An IRBuilder that automatically inserts new instructions into the worklist.
bool isFreeToInvert(Value *V, bool WillInvertAllUses, bool &DoesConsume)
Return true if the specified value is free to invert (apply ~ to).
DominatorTree & getDominatorTree() const
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI, bool IsNSW=false) const
virtual ~InstCombiner()=default
BlockFrequencyInfo * BFI
static unsigned getComplexity(Value *V)
Assign a complexity or rank value to LLVM Values.
SmallDenseMap< BasicBlock *, SmallVector< BasicBlock * >, 8 > PredOrder
Order of predecessors to canonicalize phi nodes towards.
TargetLibraryInfo & TLI
TargetLibraryInfo & getTargetLibraryInfo() const
unsigned ComputeNumSignBits(const Value *Op, const Instruction *CxtI=nullptr, unsigned Depth=0) const
BlockFrequencyInfo * getBlockFrequencyInfo() const
Instruction * InsertNewInstBefore(Instruction *New, BasicBlock::iterator Old)
Inserts an instruction New before instruction Old.
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
uint64_t MaxArraySizeForCombine
Maximum size of array considered when transforming.
static bool shouldAvoidAbsorbingNotIntoSelect(const SelectInst &SI)
OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
void replaceUse(Use &U, Value *NewValue)
Replace use and add the previously used value to the worklist.
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
static bool isCanonicalPredicate(CmpPredicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
InstructionWorklist & Worklist
A worklist of the instructions that need to be simplified.
Instruction * InsertNewInstWith(Instruction *New, BasicBlock::iterator Old)
Same as InsertNewInstBefore, but also sets the debug loc.
BranchProbabilityInfo * BPI
bool SimplifyDemandedBits(Instruction *I, unsigned OpNo, const APInt &DemandedMask, KnownBits &Known)
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo, const APInt &DemandedMask, KnownBits &Known, const SimplifyQuery &Q, unsigned Depth=0)=0
ReversePostOrderTraversal< BasicBlock * > & RPOT
const DataLayout & DL
DomConditionCache DC
const bool MinimizeSize
void computeKnownBits(const Value *V, KnownBits &Known, const Instruction *CxtI, unsigned Depth=0) const
virtual Value * SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &UndefElts, unsigned Depth=0, bool AllowMultipleUsers=false)=0
static Value * peekThroughBitcast(Value *V, bool OneUseOnly=false)
Return the source operand of a potentially bitcasted value while optionally checking if it has one us...
KnownBits computeKnownBits(const Value *V, const Instruction *CxtI, unsigned Depth=0) const
bool canFreelyInvertAllUsersOf(Instruction *V, Value *IgnoredUser)
Given i1 V, can every user of V be freely adapted if V is changed to !V ?
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder)
AssumptionCache & AC
void addToWorklist(Instruction *I)
Value * getFreelyInvertedImpl(Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume, unsigned Depth)
Return nonnull value if V is free to invert under the condition of WillInvertAllUses.
SmallDenseSet< std::pair< const BasicBlock *, const BasicBlock * >, 8 > BackEdges
Backedges, used to avoid pushing instructions across backedges in cases where this may result in infi...
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const Instruction *CxtI=nullptr, unsigned Depth=0) const
DominatorTree & DT
static Constant * getSafeVectorConstantForBinop(BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant)
Some binary operators require special handling to avoid poison and undefined behavior.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
ProfileSummaryInfo * getProfileSummaryInfo() const
OptimizationRemarkEmitter & getOptimizationRemarkEmitter() const
ProfileSummaryInfo * PSI
SmallDenseSet< std::pair< BasicBlock *, BasicBlock * >, 8 > DeadEdges
Edges that are known to never be taken.
BuilderTy & Builder
AssumptionCache & getAssumptionCache() const
OptimizationRemarkEmitter & ORE
bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const
OverflowResult computeOverflowForUnsignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume)
const SimplifyQuery & getSimplifyQuery() const
bool isBackEdge(const BasicBlock *From, const BasicBlock *To)
InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI, const DataLayout &DL, ReversePostOrderTraversal< BasicBlock * > &RPOT)
static Constant * AddOne(Constant *C)
Add one to a Constant.
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, const Instruction *CxtI=nullptr, unsigned Depth=0)
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
A wrapper class for inspecting calls to intrinsic functions.
The optimization diagnostic interface.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis providing profile information.
This class represents the LLVM 'select' instruction.
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:281
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
iterator_range< use_iterator > uses()
Definition Value.h:380
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
LogicalOp_match< LHS, RHS, Instruction::And > m_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R either in the form of L & R or L ?
bool match(Val *V, const Pattern &P)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
LogicalOp_match< LHS, RHS, Instruction::Or > m_LogicalOr(const LHS &L, const RHS &R)
Matches L || R either in the form of L | R or L ?
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
LLVM_ABI bool MaskedValueIsZero(const Value *V, const APInt &Mask, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if 'V & Mask' is known to be zero.
LLVM_ABI OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ, bool IsNSW=false)
LLVM_ABI OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_ABI OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
TargetTransformInfo TTI
LLVM_ABI OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
DWARFExpression::Operation Op
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return the number of times the sign bit of the register is replicated into the other bits.
LLVM_ABI OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
LLVM_ABI unsigned ComputeMaxSignificantBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Get the upper bound on bit size for this Value Op as a signed integer.
LLVM_ABI OverflowResult computeOverflowForUnsignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return true if the given value is known to have exactly one bit set when defined.