LLVM 19.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
25#include "llvm/IR/IRBuilder.h"
27#include "llvm/Support/Debug.h"
29#include <cassert>
30
31#define DEBUG_TYPE "instcombine"
33
34namespace llvm {
35
36class AAResults;
37class AssumptionCache;
38class OptimizationRemarkEmitter;
39class ProfileSummaryInfo;
40class TargetLibraryInfo;
41class TargetTransformInfo;
42
43/// The core instruction combiner logic.
44///
45/// This class provides both the logic to recursively visit instructions and
46/// combine them.
48 /// Only used to call target specific intrinsic combining.
49 /// It must **NOT** be used for any other purpose, as InstCombine is a
50 /// target-independent canonicalization transform.
52
53public:
54 /// Maximum size of array considered when transforming.
55 uint64_t MaxArraySizeForCombine = 0;
56
57 /// An IRBuilder that automatically inserts new instructions into the
58 /// worklist.
61
62protected:
63 /// A worklist of the instructions that need to be simplified.
65
66 // Mode in which we are running the combiner.
67 const bool MinimizeSize;
68
70
71 // Required analyses.
75 const DataLayout &DL;
81
82 // Optional analyses. When non-null, these can both be used to do better
83 // combining and will be updated to reflect any changes.
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
94public:
96 bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
100 const DataLayout &DL, LoopInfo *LI)
101 : TTI(TTI), Builder(Builder), Worklist(Worklist),
102 MinimizeSize(MinimizeSize), AA(AA), AC(AC), TLI(TLI), DT(DT), DL(DL),
103 SQ(DL, &TLI, &DT, &AC, nullptr, /*UseInstrInfo*/ true,
104 /*CanUseUndef*/ true, &DC),
105 ORE(ORE), BFI(BFI), PSI(PSI), LI(LI) {}
106
107 virtual ~InstCombiner() = default;
108
109 /// Return the source operand of a potentially bitcasted value while
110 /// optionally checking if it has one use. If there is no bitcast or the one
111 /// use check is not met, return the input value itself.
112 static Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
113 if (auto *BitCast = dyn_cast<BitCastInst>(V))
114 if (!OneUseOnly || BitCast->hasOneUse())
115 return BitCast->getOperand(0);
116
117 // V is not a bitcast or V has more than one use and OneUseOnly is true.
118 return V;
119 }
120
121 /// Assign a complexity or rank value to LLVM Values. This is used to reduce
122 /// the amount of pattern matching needed for compares and commutative
123 /// instructions. For example, if we have:
124 /// icmp ugt X, Constant
125 /// or
126 /// xor (add X, Constant), cast Z
127 ///
128 /// We do not have to consider the commuted variants of these patterns because
129 /// canonicalization based on complexity guarantees the above ordering.
130 ///
131 /// This routine maps IR values to various complexity ranks:
132 /// 0 -> undef
133 /// 1 -> Constants
134 /// 2 -> Other non-instructions
135 /// 3 -> Arguments
136 /// 4 -> Cast and (f)neg/not instructions
137 /// 5 -> Other instructions
138 static unsigned getComplexity(Value *V) {
139 if (isa<Instruction>(V)) {
140 if (isa<CastInst>(V) || match(V, m_Neg(PatternMatch::m_Value())) ||
141 match(V, m_Not(PatternMatch::m_Value())) ||
142 match(V, m_FNeg(PatternMatch::m_Value())))
143 return 4;
144 return 5;
145 }
146 if (isa<Argument>(V))
147 return 3;
148 return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
149 }
150
151 /// Predicate canonicalization reduces the number of patterns that need to be
152 /// matched by other transforms. For example, we may swap the operands of a
153 /// conditional branch or select to create a compare with a canonical
154 /// (inverted) predicate which is then more likely to be matched with other
155 /// values.
157 switch (Pred) {
158 case CmpInst::ICMP_NE:
159 case CmpInst::ICMP_ULE:
160 case CmpInst::ICMP_SLE:
161 case CmpInst::ICMP_UGE:
162 case CmpInst::ICMP_SGE:
163 // TODO: There are 16 FCMP predicates. Should others be (not) canonical?
164 case CmpInst::FCMP_ONE:
165 case CmpInst::FCMP_OLE:
166 case CmpInst::FCMP_OGE:
167 return false;
168 default:
169 return true;
170 }
171 }
172
173 /// Add one to a Constant
175 return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));
176 }
177
178 /// Subtract one from a Constant
180 return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1));
181 }
182
183 std::optional<std::pair<
185 Constant *>> static getFlippedStrictnessPredicateAndConstant(CmpInst::
186 Predicate
187 Pred,
188 Constant *C);
189
191 // a ? b : false and a ? true : b are the canonical form of logical and/or.
192 // This includes !a ? b : false and !a ? true : b. Absorbing the not into
193 // the select by swapping operands would break recognition of this pattern
194 // in other analyses, so don't do that.
195 return match(&SI, PatternMatch::m_LogicalAnd(PatternMatch::m_Value(),
196 PatternMatch::m_Value())) ||
197 match(&SI, PatternMatch::m_LogicalOr(PatternMatch::m_Value(),
198 PatternMatch::m_Value()));
199 }
200
201 /// Return nonnull value if V is free to invert under the condition of
202 /// WillInvertAllUses.
203 /// If Builder is nonnull, it will return a simplified ~V.
204 /// If Builder is null, it will return an arbitrary nonnull value (not
205 /// dereferenceable).
206 /// If the inversion will consume instructions, `DoesConsume` will be set to
207 /// true. Otherwise it will be false.
208 Value *getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
209 BuilderTy *Builder, bool &DoesConsume,
210 unsigned Depth);
211
212 Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
213 BuilderTy *Builder, bool &DoesConsume) {
214 DoesConsume = false;
215 return getFreelyInvertedImpl(V, WillInvertAllUses, Builder, DoesConsume,
216 /*Depth*/ 0);
217 }
218
219 Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
220 BuilderTy *Builder) {
221 bool Unused;
222 return getFreelyInverted(V, WillInvertAllUses, Builder, Unused);
223 }
224
225 /// Return true if the specified value is free to invert (apply ~ to).
226 /// This happens in cases where the ~ can be eliminated. If WillInvertAllUses
227 /// is true, work under the assumption that the caller intends to remove all
228 /// uses of V and only keep uses of ~V.
229 ///
230 /// See also: canFreelyInvertAllUsersOf()
231 bool isFreeToInvert(Value *V, bool WillInvertAllUses,
232 bool &DoesConsume) {
233 return getFreelyInverted(V, WillInvertAllUses, /*Builder*/ nullptr,
234 DoesConsume) != nullptr;
235 }
236
237 bool isFreeToInvert(Value *V, bool WillInvertAllUses) {
238 bool Unused;
239 return isFreeToInvert(V, WillInvertAllUses, Unused);
240 }
241
242 /// Given i1 V, can every user of V be freely adapted if V is changed to !V ?
243 /// InstCombine's freelyInvertAllUsersOf() must be kept in sync with this fn.
244 /// NOTE: for Instructions only!
245 ///
246 /// See also: isFreeToInvert()
248 // Look at every user of V.
249 for (Use &U : V->uses()) {
250 if (U.getUser() == IgnoredUser)
251 continue; // Don't consider this user.
252
253 auto *I = cast<Instruction>(U.getUser());
254 switch (I->getOpcode()) {
255 case Instruction::Select:
256 if (U.getOperandNo() != 0) // Only if the value is used as select cond.
257 return false;
258 if (shouldAvoidAbsorbingNotIntoSelect(*cast<SelectInst>(I)))
259 return false;
260 break;
261 case Instruction::Br:
262 assert(U.getOperandNo() == 0 && "Must be branching on that value.");
263 break; // Free to invert by swapping true/false values/destinations.
264 case Instruction::Xor: // Can invert 'xor' if it's a 'not', by ignoring
265 // it.
266 if (!match(I, m_Not(PatternMatch::m_Value())))
267 return false; // Not a 'not'.
268 break;
269 default:
270 return false; // Don't know, likely not freely invertible.
271 }
272 // So far all users were free to invert...
273 }
274 return true; // Can freely invert all users!
275 }
276
277 /// Some binary operators require special handling to avoid poison and
278 /// undefined behavior. If a constant vector has undef elements, replace those
279 /// undefs with identity constants if possible because those are always safe
280 /// to execute. If no identity constant exists, replace undef with some other
281 /// safe constant.
282 static Constant *
284 bool IsRHSConstant) {
285 auto *InVTy = cast<FixedVectorType>(In->getType());
286
287 Type *EltTy = InVTy->getElementType();
288 auto *SafeC = ConstantExpr::getBinOpIdentity(Opcode, EltTy, IsRHSConstant);
289 if (!SafeC) {
290 // TODO: Should this be available as a constant utility function? It is
291 // similar to getBinOpAbsorber().
292 if (IsRHSConstant) {
293 switch (Opcode) {
294 case Instruction::SRem: // X % 1 = 0
295 case Instruction::URem: // X %u 1 = 0
296 SafeC = ConstantInt::get(EltTy, 1);
297 break;
298 case Instruction::FRem: // X % 1.0 (doesn't simplify, but it is safe)
299 SafeC = ConstantFP::get(EltTy, 1.0);
300 break;
301 default:
303 "Only rem opcodes have no identity constant for RHS");
304 }
305 } else {
306 switch (Opcode) {
307 case Instruction::Shl: // 0 << X = 0
308 case Instruction::LShr: // 0 >>u X = 0
309 case Instruction::AShr: // 0 >> X = 0
310 case Instruction::SDiv: // 0 / X = 0
311 case Instruction::UDiv: // 0 /u X = 0
312 case Instruction::SRem: // 0 % X = 0
313 case Instruction::URem: // 0 %u X = 0
314 case Instruction::Sub: // 0 - X (doesn't simplify, but it is safe)
315 case Instruction::FSub: // 0.0 - X (doesn't simplify, but it is safe)
316 case Instruction::FDiv: // 0.0 / X (doesn't simplify, but it is safe)
317 case Instruction::FRem: // 0.0 % X = 0
318 SafeC = Constant::getNullValue(EltTy);
319 break;
320 default:
321 llvm_unreachable("Expected to find identity constant for opcode");
322 }
323 }
324 }
325 assert(SafeC && "Must have safe constant for binop");
326 unsigned NumElts = InVTy->getNumElements();
327 SmallVector<Constant *, 16> Out(NumElts);
328 for (unsigned i = 0; i != NumElts; ++i) {
329 Constant *C = In->getAggregateElement(i);
330 Out[i] = isa<UndefValue>(C) ? SafeC : C;
331 }
332 return ConstantVector::get(Out);
333 }
334
335 void addToWorklist(Instruction *I) { Worklist.push(I); }
336
337 AssumptionCache &getAssumptionCache() const { return AC; }
339 DominatorTree &getDominatorTree() const { return DT; }
340 const DataLayout &getDataLayout() const { return DL; }
341 const SimplifyQuery &getSimplifyQuery() const { return SQ; }
343 return ORE;
344 }
347 LoopInfo *getLoopInfo() const { return LI; }
348
349 // Call target specific combiners
350 std::optional<Instruction *> targetInstCombineIntrinsic(IntrinsicInst &II);
351 std::optional<Value *>
352 targetSimplifyDemandedUseBitsIntrinsic(IntrinsicInst &II, APInt DemandedMask,
353 KnownBits &Known,
354 bool &KnownBitsComputed);
355 std::optional<Value *> targetSimplifyDemandedVectorEltsIntrinsic(
356 IntrinsicInst &II, APInt DemandedElts, APInt &UndefElts,
357 APInt &UndefElts2, APInt &UndefElts3,
358 std::function<void(Instruction *, unsigned, APInt, APInt &)>
359 SimplifyAndSetOp);
360
361 /// Inserts an instruction \p New before instruction \p Old
362 ///
363 /// Also adds the new instruction to the worklist and returns \p New so that
364 /// it is suitable for use as the return from the visitation patterns.
366 assert(New && !New->getParent() &&
367 "New instruction already inserted into a basic block!");
368 New->insertBefore(Old); // Insert inst
369 Worklist.add(New);
370 return New;
371 }
372
373 /// Same as InsertNewInstBefore, but also sets the debug loc.
375 New->setDebugLoc(Old->getDebugLoc());
376 return InsertNewInstBefore(New, Old);
377 }
378
379 /// A combiner-aware RAUW-like routine.
380 ///
381 /// This method is to be used when an instruction is found to be dead,
382 /// replaceable with another preexisting expression. Here we add all uses of
383 /// I to the worklist, replace all uses of I with the new value, then return
384 /// I, so that the inst combiner will know that I was modified.
386 // If there are no uses to replace, then we return nullptr to indicate that
387 // no changes were made to the program.
388 if (I.use_empty()) return nullptr;
389
390 Worklist.pushUsersToWorkList(I); // Add all modified instrs to worklist.
391
392 // If we are replacing the instruction with itself, this must be in a
393 // segment of unreachable code, so just clobber the instruction.
394 if (&I == V)
395 V = PoisonValue::get(I.getType());
396
397 LLVM_DEBUG(dbgs() << "IC: Replacing " << I << "\n"
398 << " with " << *V << '\n');
399
400 // If V is a new unnamed instruction, take the name from the old one.
401 if (V->use_empty() && isa<Instruction>(V) && !V->hasName() && I.hasName())
402 V->takeName(&I);
403
404 I.replaceAllUsesWith(V);
405 return &I;
406 }
407
408 /// Replace operand of instruction and add old operand to the worklist.
410 Value *OldOp = I.getOperand(OpNum);
411 I.setOperand(OpNum, V);
412 Worklist.handleUseCountDecrement(OldOp);
413 return &I;
414 }
415
416 /// Replace use and add the previously used value to the worklist.
417 void replaceUse(Use &U, Value *NewValue) {
418 Value *OldOp = U;
419 U = NewValue;
420 Worklist.handleUseCountDecrement(OldOp);
421 }
422
423 /// Combiner aware instruction erasure.
424 ///
425 /// When dealing with an instruction that has side effects or produces a void
426 /// value, we can't rely on DCE to delete the instruction. Instead, visit
427 /// methods should return the value returned by this function.
429
430 void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
431 const Instruction *CxtI) const {
433 }
434
435 KnownBits computeKnownBits(const Value *V, unsigned Depth,
436 const Instruction *CxtI) const {
438 }
439
440 bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
441 unsigned Depth = 0,
442 const Instruction *CxtI = nullptr) {
443 return llvm::isKnownToBeAPowerOfTwo(V, DL, OrZero, Depth, &AC, CxtI, &DT);
444 }
445
446 bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
447 const Instruction *CxtI = nullptr) const {
448 return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
449 }
450
451 unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,
452 const Instruction *CxtI = nullptr) const {
453 return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT);
454 }
455
456 unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth = 0,
457 const Instruction *CxtI = nullptr) const {
458 return llvm::ComputeMaxSignificantBits(Op, DL, Depth, &AC, CxtI, &DT);
459 }
460
462 const Value *RHS,
463 const Instruction *CxtI) const {
465 SQ.getWithInstruction(CxtI));
466 }
467
469 const Instruction *CxtI) const {
471 SQ.getWithInstruction(CxtI));
472 }
473
477 const Instruction *CxtI) const {
479 SQ.getWithInstruction(CxtI));
480 }
481
485 const Instruction *CxtI) const {
487 SQ.getWithInstruction(CxtI));
488 }
489
491 const Value *RHS,
492 const Instruction *CxtI) const {
494 SQ.getWithInstruction(CxtI));
495 }
496
498 const Instruction *CxtI) const {
500 SQ.getWithInstruction(CxtI));
501 }
502
503 virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
504 const APInt &DemandedMask, KnownBits &Known,
505 unsigned Depth = 0) = 0;
506 virtual Value *
507 SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &UndefElts,
508 unsigned Depth = 0,
509 bool AllowMultipleUsers = false) = 0;
510
511 bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
512};
513
514} // namespace llvm
515
516#undef DEBUG_TYPE
517
518#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
basic Basic Alias true
IRBuilder< TargetFolder > BuilderTy
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_LIBRARY_VISIBILITY
Definition: Compiler.h:131
#define LLVM_DEBUG(X)
Definition: Debug.h:101
#define I(x, y, z)
Definition: MD5.cpp:58
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:76
A cache of @llvm.assume calls within a function.
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:164
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:955
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:965
This is an important base class in LLVM.
Definition: Constant.h:41
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:162
The core instruction combiner logic.
Definition: InstCombiner.h:47
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:497
SimplifyQuery SQ
Definition: InstCombiner.h:76
const DataLayout & getDataLayout() const
Definition: InstCombiner.h:340
static bool isCanonicalPredicate(CmpInst::Predicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
Definition: InstCombiner.h:156
bool isFreeToInvert(Value *V, bool WillInvertAllUses)
Definition: InstCombiner.h:237
virtual Instruction * eraseInstFromFunction(Instruction &I)=0
Combiner aware instruction erasure.
bool isFreeToInvert(Value *V, bool WillInvertAllUses, bool &DoesConsume)
Return true if the specified value is free to invert (apply ~ to).
Definition: InstCombiner.h:231
DominatorTree & getDominatorTree() const
Definition: InstCombiner.h:339
virtual ~InstCombiner()=default
LoopInfo * getLoopInfo() const
Definition: InstCombiner.h:347
BlockFrequencyInfo * BFI
Definition: InstCombiner.h:78
static unsigned getComplexity(Value *V)
Assign a complexity or rank value to LLVM Values.
Definition: InstCombiner.h:138
SmallDenseMap< BasicBlock *, SmallVector< BasicBlock * >, 8 > PredOrder
Order of predecessors to canonicalize phi nodes towards.
Definition: InstCombiner.h:92
TargetLibraryInfo & TLI
Definition: InstCombiner.h:73
TargetLibraryInfo & getTargetLibraryInfo() const
Definition: InstCombiner.h:338
BlockFrequencyInfo * getBlockFrequencyInfo() const
Definition: InstCombiner.h:345
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
Definition: InstCombiner.h:440
Instruction * InsertNewInstBefore(Instruction *New, BasicBlock::iterator Old)
Inserts an instruction New before instruction Old.
Definition: InstCombiner.h:365
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:461
AAResults * AA
Definition: InstCombiner.h:69
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
Definition: InstCombiner.h:385
static bool shouldAvoidAbsorbingNotIntoSelect(const SelectInst &SI)
Definition: InstCombiner.h:190
OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:483
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
Definition: InstCombiner.h:179
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo, const APInt &DemandedMask, KnownBits &Known, unsigned Depth=0)=0
KnownBits computeKnownBits(const Value *V, unsigned Depth, const Instruction *CxtI) const
Definition: InstCombiner.h:435
void replaceUse(Use &U, Value *NewValue)
Replace use and add the previously used value to the worklist.
Definition: InstCombiner.h:417
InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, const DataLayout &DL, LoopInfo *LI)
Definition: InstCombiner.h:95
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:490
InstructionWorklist & Worklist
A worklist of the instructions that need to be simplified.
Definition: InstCombiner.h:64
Instruction * InsertNewInstWith(Instruction *New, BasicBlock::iterator Old)
Same as InsertNewInstBefore, but also sets the debug loc.
Definition: InstCombiner.h:374
const DataLayout & DL
Definition: InstCombiner.h:75
unsigned ComputeNumSignBits(const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
Definition: InstCombiner.h:451
DomConditionCache DC
Definition: InstCombiner.h:80
const bool MinimizeSize
Definition: InstCombiner.h:67
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...
Definition: InstCombiner.h:112
bool canFreelyInvertAllUsersOf(Instruction *V, Value *IgnoredUser)
Given i1 V, can every user of V be freely adapted if V is changed to !V ? InstCombine's freelyInvertA...
Definition: InstCombiner.h:247
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder)
Definition: InstCombiner.h:219
AssumptionCache & AC
Definition: InstCombiner.h:72
void addToWorklist(Instruction *I)
Definition: InstCombiner.h:335
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
Definition: InstCombiner.h:409
DominatorTree & DT
Definition: InstCombiner.h:74
static Constant * getSafeVectorConstantForBinop(BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant)
Some binary operators require special handling to avoid poison and undefined behavior.
Definition: InstCombiner.h:283
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:468
ProfileSummaryInfo * getProfileSummaryInfo() const
Definition: InstCombiner.h:346
OptimizationRemarkEmitter & getOptimizationRemarkEmitter() const
Definition: InstCombiner.h:342
ProfileSummaryInfo * PSI
Definition: InstCombiner.h:79
SmallDenseSet< std::pair< BasicBlock *, BasicBlock * >, 8 > DeadEdges
Edges that are known to never be taken.
Definition: InstCombiner.h:89
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
Definition: InstCombiner.h:430
BuilderTy & Builder
Definition: InstCombiner.h:60
AssumptionCache & getAssumptionCache() const
Definition: InstCombiner.h:337
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
Definition: InstCombiner.h:446
OptimizationRemarkEmitter & ORE
Definition: InstCombiner.h:77
OverflowResult computeOverflowForUnsignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const Instruction *CxtI) const
Definition: InstCombiner.h:475
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume)
Definition: InstCombiner.h:212
const SimplifyQuery & getSimplifyQuery() const
Definition: InstCombiner.h:341
static Constant * AddOne(Constant *C)
Add one to a Constant.
Definition: InstCombiner.h:174
unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
Definition: InstCombiner.h:456
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
void pushUsersToWorkList(Instruction &I)
When an instruction is simplified, add all users of the instruction to the work lists because they mi...
void add(Instruction *I)
Add instruction to the worklist.
void push(Instruction *I)
Push the instruction onto the worklist stack.
void handleUseCountDecrement(Value *V)
Should be called after decrementing the use-count on V.
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
The optimization diagnostic interface.
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:290
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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:43
LLVM Value Representation.
Definition: Value.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OverflowResult
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const SimplifyQuery &DL, unsigned Depth=0)
Return true if 'V & Mask' is known to be zero.
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined.
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits.
OverflowResult computeOverflowForUnsignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
unsigned ComputeMaxSignificantBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Get the upper bound on bit size for this Value Op as a signed integer.
SimplifyQuery getWithInstruction(const Instruction *I) const
Definition: SimplifyQuery.h:96