LLVM  7.0.0svn
InstCombineInternal.h
Go to the documentation of this file.
1 //===- InstCombineInternal.h - InstCombine pass internals -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 ///
12 /// This file provides internal interfaces used to implement the InstCombine.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
17 #define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
18 
19 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/IR/Argument.h"
26 #include "llvm/IR/BasicBlock.h"
27 #include "llvm/IR/Constant.h"
28 #include "llvm/IR/Constants.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/IRBuilder.h"
31 #include "llvm/IR/InstVisitor.h"
32 #include "llvm/IR/InstrTypes.h"
33 #include "llvm/IR/Instruction.h"
34 #include "llvm/IR/IntrinsicInst.h"
35 #include "llvm/IR/Intrinsics.h"
36 #include "llvm/IR/Use.h"
37 #include "llvm/IR/Value.h"
38 #include "llvm/Support/Casting.h"
39 #include "llvm/Support/Compiler.h"
40 #include "llvm/Support/Debug.h"
41 #include "llvm/Support/KnownBits.h"
44 #include <cassert>
45 #include <cstdint>
46 
47 #define DEBUG_TYPE "instcombine"
48 
49 namespace llvm {
50 
51 class APInt;
52 class AssumptionCache;
53 class CallSite;
54 class DataLayout;
55 class DominatorTree;
56 class GEPOperator;
57 class GlobalVariable;
58 class LoopInfo;
59 class OptimizationRemarkEmitter;
60 class TargetLibraryInfo;
61 class User;
62 
63 /// Assign a complexity or rank value to LLVM Values. This is used to reduce
64 /// the amount of pattern matching needed for compares and commutative
65 /// instructions. For example, if we have:
66 /// icmp ugt X, Constant
67 /// or
68 /// xor (add X, Constant), cast Z
69 ///
70 /// We do not have to consider the commuted variants of these patterns because
71 /// canonicalization based on complexity guarantees the above ordering.
72 ///
73 /// This routine maps IR values to various complexity ranks:
74 /// 0 -> undef
75 /// 1 -> Constants
76 /// 2 -> Other non-instructions
77 /// 3 -> Arguments
78 /// 4 -> Cast and (f)neg/not instructions
79 /// 5 -> Other instructions
80 static inline unsigned getComplexity(Value *V) {
81  if (isa<Instruction>(V)) {
82  if (isa<CastInst>(V) || BinaryOperator::isNeg(V) ||
84  return 4;
85  return 5;
86  }
87  if (isa<Argument>(V))
88  return 3;
89  return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
90 }
91 
92 /// Predicate canonicalization reduces the number of patterns that need to be
93 /// matched by other transforms. For example, we may swap the operands of a
94 /// conditional branch or select to create a compare with a canonical (inverted)
95 /// predicate which is then more likely to be matched with other values.
96 static inline bool isCanonicalPredicate(CmpInst::Predicate Pred) {
97  switch (Pred) {
98  case CmpInst::ICMP_NE:
99  case CmpInst::ICMP_ULE:
100  case CmpInst::ICMP_SLE:
101  case CmpInst::ICMP_UGE:
102  case CmpInst::ICMP_SGE:
103  // TODO: There are 16 FCMP predicates. Should others be (not) canonical?
104  case CmpInst::FCMP_ONE:
105  case CmpInst::FCMP_OLE:
106  case CmpInst::FCMP_OGE:
107  return false;
108  default:
109  return true;
110  }
111 }
112 
113 /// Return the source operand of a potentially bitcasted value while optionally
114 /// checking if it has one use. If there is no bitcast or the one use check is
115 /// not met, return the input value itself.
116 static inline Value *peekThroughBitcast(Value *V, bool OneUseOnly = false) {
117  if (auto *BitCast = dyn_cast<BitCastInst>(V))
118  if (!OneUseOnly || BitCast->hasOneUse())
119  return BitCast->getOperand(0);
120 
121  // V is not a bitcast or V has more than one use and OneUseOnly is true.
122  return V;
123 }
124 
125 /// Add one to a Constant
126 static inline Constant *AddOne(Constant *C) {
127  return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1));
128 }
129 
130 /// Subtract one from a Constant
131 static inline Constant *SubOne(Constant *C) {
132  return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1));
133 }
134 
135 /// Return true if the specified value is free to invert (apply ~ to).
136 /// This happens in cases where the ~ can be eliminated. If WillInvertAllUses
137 /// is true, work under the assumption that the caller intends to remove all
138 /// uses of V and only keep uses of ~V.
139 static inline bool IsFreeToInvert(Value *V, bool WillInvertAllUses) {
140  // ~(~(X)) -> X.
141  if (BinaryOperator::isNot(V))
142  return true;
143 
144  // Constants can be considered to be not'ed values.
145  if (isa<ConstantInt>(V))
146  return true;
147 
148  // A vector of constant integers can be inverted easily.
149  if (V->getType()->isVectorTy() && isa<Constant>(V)) {
150  unsigned NumElts = V->getType()->getVectorNumElements();
151  for (unsigned i = 0; i != NumElts; ++i) {
152  Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
153  if (!Elt)
154  return false;
155 
156  if (isa<UndefValue>(Elt))
157  continue;
158 
159  if (!isa<ConstantInt>(Elt))
160  return false;
161  }
162  return true;
163  }
164 
165  // Compares can be inverted if all of their uses are being modified to use the
166  // ~V.
167  if (isa<CmpInst>(V))
168  return WillInvertAllUses;
169 
170  // If `V` is of the form `A + Constant` then `-1 - V` can be folded into `(-1
171  // - Constant) - A` if we are willing to invert all of the uses.
172  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V))
173  if (BO->getOpcode() == Instruction::Add ||
174  BO->getOpcode() == Instruction::Sub)
175  if (isa<Constant>(BO->getOperand(0)) || isa<Constant>(BO->getOperand(1)))
176  return WillInvertAllUses;
177 
178  return false;
179 }
180 
181 /// Specific patterns of overflow check idioms that we match.
189 
191 };
192 
193 /// Returns the OverflowCheckFlavor corresponding to a overflow_with_op
194 /// intrinsic.
195 static inline OverflowCheckFlavor
197  switch (ID) {
198  default:
199  return OCF_INVALID;
200  case Intrinsic::uadd_with_overflow:
201  return OCF_UNSIGNED_ADD;
202  case Intrinsic::sadd_with_overflow:
203  return OCF_SIGNED_ADD;
204  case Intrinsic::usub_with_overflow:
205  return OCF_UNSIGNED_SUB;
206  case Intrinsic::ssub_with_overflow:
207  return OCF_SIGNED_SUB;
208  case Intrinsic::umul_with_overflow:
209  return OCF_UNSIGNED_MUL;
210  case Intrinsic::smul_with_overflow:
211  return OCF_SIGNED_MUL;
212  }
213 }
214 
215 /// Integer division/remainder require special handling to avoid undefined
216 /// behavior. If a constant vector has undef elements, replace those undefs with
217 /// '1' because that's always safe to execute.
219  assert(In->getType()->isVectorTy() && "Not expecting scalars here");
221  "Not expecting FP opcodes/operands/constants here");
222 
223  unsigned NumElts = In->getType()->getVectorNumElements();
224  SmallVector<Constant *, 16> Out(NumElts);
225  for (unsigned i = 0; i != NumElts; ++i) {
226  Constant *C = In->getAggregateElement(i);
227  Out[i] = isa<UndefValue>(C) ? ConstantInt::get(C->getType(), 1) : C;
228  }
229  return ConstantVector::get(Out);
230 }
231 
232 /// The core instruction combiner logic.
233 ///
234 /// This class provides both the logic to recursively visit instructions and
235 /// combine them.
237  : public InstVisitor<InstCombiner, Instruction *> {
238  // FIXME: These members shouldn't be public.
239 public:
240  /// A worklist of the instructions that need to be simplified.
242 
243  /// An IRBuilder that automatically inserts new instructions into the
244  /// worklist.
247 
248 private:
249  // Mode in which we are running the combiner.
250  const bool MinimizeSize;
251 
252  /// Enable combines that trigger rarely but are costly in compiletime.
253  const bool ExpensiveCombines;
254 
255  AliasAnalysis *AA;
256 
257  // Required analyses.
258  AssumptionCache &AC;
259  TargetLibraryInfo &TLI;
260  DominatorTree &DT;
261  const DataLayout &DL;
262  const SimplifyQuery SQ;
264 
265  // Optional analyses. When non-null, these can both be used to do better
266  // combining and will be updated to reflect any changes.
267  LoopInfo *LI;
268 
269  bool MadeIRChange = false;
270 
271 public:
273  bool MinimizeSize, bool ExpensiveCombines, AliasAnalysis *AA,
275  OptimizationRemarkEmitter &ORE, const DataLayout &DL,
276  LoopInfo *LI)
277  : Worklist(Worklist), Builder(Builder), MinimizeSize(MinimizeSize),
278  ExpensiveCombines(ExpensiveCombines), AA(AA), AC(AC), TLI(TLI), DT(DT),
279  DL(DL), SQ(DL, &TLI, &DT, &AC), ORE(ORE), LI(LI) {}
280 
281  /// Run the combiner over the entire worklist until it is empty.
282  ///
283  /// \returns true if the IR is changed.
284  bool run();
285 
286  AssumptionCache &getAssumptionCache() const { return AC; }
287 
288  const DataLayout &getDataLayout() const { return DL; }
289 
290  DominatorTree &getDominatorTree() const { return DT; }
291 
292  LoopInfo *getLoopInfo() const { return LI; }
293 
294  TargetLibraryInfo &getTargetLibraryInfo() const { return TLI; }
295 
296  // Visitation implementation - Implement instruction combining for different
297  // instruction types. The semantics are as follows:
298  // Return Value:
299  // null - No change was made
300  // I - Change was made, I is still valid, I may be dead though
301  // otherwise - Change was made, replace I with returned instruction
302  //
303  Instruction *visitAdd(BinaryOperator &I);
304  Instruction *visitFAdd(BinaryOperator &I);
305  Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty);
306  Instruction *visitSub(BinaryOperator &I);
307  Instruction *visitFSub(BinaryOperator &I);
308  Instruction *visitMul(BinaryOperator &I);
309  Instruction *visitFMul(BinaryOperator &I);
310  Instruction *visitURem(BinaryOperator &I);
311  Instruction *visitSRem(BinaryOperator &I);
312  Instruction *visitFRem(BinaryOperator &I);
313  bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I);
314  Instruction *commonRemTransforms(BinaryOperator &I);
315  Instruction *commonIRemTransforms(BinaryOperator &I);
316  Instruction *commonDivTransforms(BinaryOperator &I);
317  Instruction *commonIDivTransforms(BinaryOperator &I);
318  Instruction *visitUDiv(BinaryOperator &I);
319  Instruction *visitSDiv(BinaryOperator &I);
320  Instruction *visitFDiv(BinaryOperator &I);
321  Value *simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted);
322  Instruction *visitAnd(BinaryOperator &I);
323  Instruction *visitOr(BinaryOperator &I);
324  Instruction *visitXor(BinaryOperator &I);
325  Instruction *visitShl(BinaryOperator &I);
326  Instruction *visitAShr(BinaryOperator &I);
327  Instruction *visitLShr(BinaryOperator &I);
328  Instruction *commonShiftTransforms(BinaryOperator &I);
329  Instruction *visitFCmpInst(FCmpInst &I);
330  Instruction *visitICmpInst(ICmpInst &I);
331  Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1,
332  BinaryOperator &I);
333  Instruction *commonCastTransforms(CastInst &CI);
334  Instruction *commonPointerCastTransforms(CastInst &CI);
335  Instruction *visitTrunc(TruncInst &CI);
336  Instruction *visitZExt(ZExtInst &CI);
337  Instruction *visitSExt(SExtInst &CI);
338  Instruction *visitFPTrunc(FPTruncInst &CI);
339  Instruction *visitFPExt(CastInst &CI);
340  Instruction *visitFPToUI(FPToUIInst &FI);
341  Instruction *visitFPToSI(FPToSIInst &FI);
342  Instruction *visitUIToFP(CastInst &CI);
343  Instruction *visitSIToFP(CastInst &CI);
344  Instruction *visitPtrToInt(PtrToIntInst &CI);
345  Instruction *visitIntToPtr(IntToPtrInst &CI);
346  Instruction *visitBitCast(BitCastInst &CI);
347  Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI);
348  Instruction *FoldItoFPtoI(Instruction &FI);
349  Instruction *visitSelectInst(SelectInst &SI);
350  Instruction *visitCallInst(CallInst &CI);
351  Instruction *visitInvokeInst(InvokeInst &II);
352 
353  Instruction *SliceUpIllegalIntegerPHI(PHINode &PN);
354  Instruction *visitPHINode(PHINode &PN);
355  Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
356  Instruction *visitAllocaInst(AllocaInst &AI);
357  Instruction *visitAllocSite(Instruction &FI);
358  Instruction *visitFree(CallInst &FI);
359  Instruction *visitLoadInst(LoadInst &LI);
360  Instruction *visitStoreInst(StoreInst &SI);
361  Instruction *visitBranchInst(BranchInst &BI);
362  Instruction *visitFenceInst(FenceInst &FI);
363  Instruction *visitSwitchInst(SwitchInst &SI);
364  Instruction *visitReturnInst(ReturnInst &RI);
365  Instruction *visitInsertValueInst(InsertValueInst &IV);
366  Instruction *visitInsertElementInst(InsertElementInst &IE);
367  Instruction *visitExtractElementInst(ExtractElementInst &EI);
368  Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI);
369  Instruction *visitExtractValueInst(ExtractValueInst &EV);
370  Instruction *visitLandingPadInst(LandingPadInst &LI);
371  Instruction *visitVAStartInst(VAStartInst &I);
372  Instruction *visitVACopyInst(VACopyInst &I);
373 
374  /// Specify what to return for unhandled instructions.
375  Instruction *visitInstruction(Instruction &I) { return nullptr; }
376 
377  /// True when DB dominates all uses of DI except UI.
378  /// UI must be in the same block as DI.
379  /// The routine checks that the DI parent and DB are different.
380  bool dominatesAllUses(const Instruction *DI, const Instruction *UI,
381  const BasicBlock *DB) const;
382 
383  /// Try to replace select with select operand SIOpd in SI-ICmp sequence.
384  bool replacedSelectWithOperand(SelectInst *SI, const ICmpInst *Icmp,
385  const unsigned SIOpd);
386 
387  /// Try to replace instruction \p I with value \p V which are pointers
388  /// in different address space.
389  /// \return true if successful.
390  bool replacePointer(Instruction &I, Value *V);
391 
392 private:
393  bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
394  bool shouldChangeType(Type *From, Type *To) const;
395  Value *dyn_castNegVal(Value *V) const;
396  Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset,
397  SmallVectorImpl<Value *> &NewIndices);
398 
399  /// Classify whether a cast is worth optimizing.
400  ///
401  /// This is a helper to decide whether the simplification of
402  /// logic(cast(A), cast(B)) to cast(logic(A, B)) should be performed.
403  ///
404  /// \param CI The cast we are interested in.
405  ///
406  /// \return true if this cast actually results in any code being generated and
407  /// if it cannot already be eliminated by some other transformation.
408  bool shouldOptimizeCast(CastInst *CI);
409 
410  /// Try to optimize a sequence of instructions checking if an operation
411  /// on LHS and RHS overflows.
412  ///
413  /// If this overflow check is done via one of the overflow check intrinsics,
414  /// then CtxI has to be the call instruction calling that intrinsic. If this
415  /// overflow check is done by arithmetic followed by a compare, then CtxI has
416  /// to be the arithmetic instruction.
417  ///
418  /// If a simplification is possible, stores the simplified result of the
419  /// operation in OperationResult and result of the overflow check in
420  /// OverflowResult, and return true. If no simplification is possible,
421  /// returns false.
422  bool OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS, Value *RHS,
423  Instruction &CtxI, Value *&OperationResult,
425 
426  Instruction *visitCallSite(CallSite CS);
427  Instruction *tryOptimizeCall(CallInst *CI);
428  bool transformConstExprCastCall(CallSite CS);
429  Instruction *transformCallThroughTrampoline(CallSite CS,
430  IntrinsicInst *Tramp);
431 
432  /// Transform (zext icmp) to bitwise / integer operations in order to
433  /// eliminate it.
434  ///
435  /// \param ICI The icmp of the (zext icmp) pair we are interested in.
436  /// \parem CI The zext of the (zext icmp) pair we are interested in.
437  /// \param DoTransform Pass false to just test whether the given (zext icmp)
438  /// would be transformed. Pass true to actually perform the transformation.
439  ///
440  /// \return null if the transformation cannot be performed. If the
441  /// transformation can be performed the new instruction that replaces the
442  /// (zext icmp) pair will be returned (if \p DoTransform is false the
443  /// unmodified \p ICI will be returned in this case).
444  Instruction *transformZExtICmp(ICmpInst *ICI, ZExtInst &CI,
445  bool DoTransform = true);
446 
447  Instruction *transformSExtICmp(ICmpInst *ICI, Instruction &CI);
448 
449  bool willNotOverflowSignedAdd(const Value *LHS, const Value *RHS,
450  const Instruction &CxtI) const {
451  return computeOverflowForSignedAdd(LHS, RHS, &CxtI) ==
453  }
454 
455  bool willNotOverflowUnsignedAdd(const Value *LHS, const Value *RHS,
456  const Instruction &CxtI) const {
457  return computeOverflowForUnsignedAdd(LHS, RHS, &CxtI) ==
459  }
460 
461  bool willNotOverflowSignedSub(const Value *LHS, const Value *RHS,
462  const Instruction &CxtI) const {
463  return computeOverflowForSignedSub(LHS, RHS, &CxtI) ==
465  }
466 
467  bool willNotOverflowUnsignedSub(const Value *LHS, const Value *RHS,
468  const Instruction &CxtI) const {
469  return computeOverflowForUnsignedSub(LHS, RHS, &CxtI) ==
471  }
472 
473  bool willNotOverflowSignedMul(const Value *LHS, const Value *RHS,
474  const Instruction &CxtI) const {
475  return computeOverflowForSignedMul(LHS, RHS, &CxtI) ==
477  }
478 
479  bool willNotOverflowUnsignedMul(const Value *LHS, const Value *RHS,
480  const Instruction &CxtI) const {
481  return computeOverflowForUnsignedMul(LHS, RHS, &CxtI) ==
483  }
484 
485  Value *EmitGEPOffset(User *GEP);
486  Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN);
487  Value *EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask);
488  Instruction *foldCastedBitwiseLogic(BinaryOperator &I);
489  Instruction *narrowBinOp(TruncInst &Trunc);
490  Instruction *narrowMaskedBinOp(BinaryOperator &And);
491  Instruction *narrowRotate(TruncInst &Trunc);
492  Instruction *optimizeBitCastFromPhi(CastInst &CI, PHINode *PN);
493 
494  /// Determine if a pair of casts can be replaced by a single cast.
495  ///
496  /// \param CI1 The first of a pair of casts.
497  /// \param CI2 The second of a pair of casts.
498  ///
499  /// \return 0 if the cast pair cannot be eliminated, otherwise returns an
500  /// Instruction::CastOps value for a cast that can replace the pair, casting
501  /// CI1->getSrcTy() to CI2->getDstTy().
502  ///
503  /// \see CastInst::isEliminableCastPair
504  Instruction::CastOps isEliminableCastPair(const CastInst *CI1,
505  const CastInst *CI2);
506 
507  Value *foldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction &CxtI);
508  Value *foldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction &CxtI);
509  Value *foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS);
510 
511  /// Optimize (fcmp)&(fcmp) or (fcmp)|(fcmp).
512  /// NOTE: Unlike most of instcombine, this returns a Value which should
513  /// already be inserted into the function.
514  Value *foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS, bool IsAnd);
515 
516  Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
517  bool JoinedByAnd, Instruction &CxtI);
518 public:
519  /// Inserts an instruction \p New before instruction \p Old
520  ///
521  /// Also adds the new instruction to the worklist and returns \p New so that
522  /// it is suitable for use as the return from the visitation patterns.
524  assert(New && !New->getParent() &&
525  "New instruction already inserted into a basic block!");
526  BasicBlock *BB = Old.getParent();
527  BB->getInstList().insert(Old.getIterator(), New); // Insert inst
528  Worklist.Add(New);
529  return New;
530  }
531 
532  /// Same as InsertNewInstBefore, but also sets the debug loc.
534  New->setDebugLoc(Old.getDebugLoc());
535  return InsertNewInstBefore(New, Old);
536  }
537 
538  /// A combiner-aware RAUW-like routine.
539  ///
540  /// This method is to be used when an instruction is found to be dead,
541  /// replaceable with another preexisting expression. Here we add all uses of
542  /// I to the worklist, replace all uses of I with the new value, then return
543  /// I, so that the inst combiner will know that I was modified.
545  // If there are no uses to replace, then we return nullptr to indicate that
546  // no changes were made to the program.
547  if (I.use_empty()) return nullptr;
548 
549  Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
550 
551  // If we are replacing the instruction with itself, this must be in a
552  // segment of unreachable code, so just clobber the instruction.
553  if (&I == V)
554  V = UndefValue::get(I.getType());
555 
556  LLVM_DEBUG(dbgs() << "IC: Replacing " << I << "\n"
557  << " with " << *V << '\n');
558 
559  I.replaceAllUsesWith(V);
560  return &I;
561  }
562 
563  /// Creates a result tuple for an overflow intrinsic \p II with a given
564  /// \p Result and a constant \p Overflow value.
566  Constant *Overflow) {
567  Constant *V[] = {UndefValue::get(Result->getType()), Overflow};
568  StructType *ST = cast<StructType>(II->getType());
569  Constant *Struct = ConstantStruct::get(ST, V);
570  return InsertValueInst::Create(Struct, Result, 0);
571  }
572 
573  /// Combiner aware instruction erasure.
574  ///
575  /// When dealing with an instruction that has side effects or produces a void
576  /// value, we can't rely on DCE to delete the instruction. Instead, visit
577  /// methods should return the value returned by this function.
579  LLVM_DEBUG(dbgs() << "IC: ERASE " << I << '\n');
580  assert(I.use_empty() && "Cannot erase instruction that is used!");
581  salvageDebugInfo(I);
582 
583  // Make sure that we reprocess all operands now that we reduced their
584  // use counts.
585  if (I.getNumOperands() < 8) {
586  for (Use &Operand : I.operands())
587  if (auto *Inst = dyn_cast<Instruction>(Operand))
588  Worklist.Add(Inst);
589  }
590  Worklist.Remove(&I);
591  I.eraseFromParent();
592  MadeIRChange = true;
593  return nullptr; // Don't do anything with FI
594  }
595 
596  void computeKnownBits(const Value *V, KnownBits &Known,
597  unsigned Depth, const Instruction *CxtI) const {
598  llvm::computeKnownBits(V, Known, DL, Depth, &AC, CxtI, &DT);
599  }
600 
601  KnownBits computeKnownBits(const Value *V, unsigned Depth,
602  const Instruction *CxtI) const {
603  return llvm::computeKnownBits(V, DL, Depth, &AC, CxtI, &DT);
604  }
605 
606  bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
607  unsigned Depth = 0,
608  const Instruction *CxtI = nullptr) {
609  return llvm::isKnownToBeAPowerOfTwo(V, DL, OrZero, Depth, &AC, CxtI, &DT);
610  }
611 
612  bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0,
613  const Instruction *CxtI = nullptr) const {
614  return llvm::MaskedValueIsZero(V, Mask, DL, Depth, &AC, CxtI, &DT);
615  }
616 
617  unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0,
618  const Instruction *CxtI = nullptr) const {
619  return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT);
620  }
621 
622  OverflowResult computeOverflowForUnsignedMul(const Value *LHS,
623  const Value *RHS,
624  const Instruction *CxtI) const {
625  return llvm::computeOverflowForUnsignedMul(LHS, RHS, DL, &AC, CxtI, &DT);
626  }
627 
628  OverflowResult computeOverflowForSignedMul(const Value *LHS,
629  const Value *RHS,
630  const Instruction *CxtI) const {
631  return llvm::computeOverflowForSignedMul(LHS, RHS, DL, &AC, CxtI, &DT);
632  }
633 
634  OverflowResult computeOverflowForUnsignedAdd(const Value *LHS,
635  const Value *RHS,
636  const Instruction *CxtI) const {
637  return llvm::computeOverflowForUnsignedAdd(LHS, RHS, DL, &AC, CxtI, &DT);
638  }
639 
640  OverflowResult computeOverflowForSignedAdd(const Value *LHS,
641  const Value *RHS,
642  const Instruction *CxtI) const {
643  return llvm::computeOverflowForSignedAdd(LHS, RHS, DL, &AC, CxtI, &DT);
644  }
645 
646  OverflowResult computeOverflowForUnsignedSub(const Value *LHS,
647  const Value *RHS,
648  const Instruction *CxtI) const {
649  return llvm::computeOverflowForUnsignedSub(LHS, RHS, DL, &AC, CxtI, &DT);
650  }
651 
652  OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS,
653  const Instruction *CxtI) const {
654  return llvm::computeOverflowForSignedSub(LHS, RHS, DL, &AC, CxtI, &DT);
655  }
656 
657  /// Maximum size of array considered when transforming.
659 
660 private:
661  /// Performs a few simplifications for operators which are associative
662  /// or commutative.
663  bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
664 
665  /// Tries to simplify binary operations which some other binary
666  /// operation distributes over.
667  ///
668  /// It does this by either by factorizing out common terms (eg "(A*B)+(A*C)"
669  /// -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A
670  /// & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified
671  /// value, or null if it didn't simplify.
672  Value *SimplifyUsingDistributiveLaws(BinaryOperator &I);
673 
674  /// Tries to simplify add operations using the definition of remainder.
675  ///
676  /// The definition of remainder is X % C = X - (X / C ) * C. The add
677  /// expression X % C0 + (( X / C0 ) % C1) * C0 can be simplified to
678  /// X % (C0 * C1)
679  Value *SimplifyAddWithRemainder(BinaryOperator &I);
680 
681  // Binary Op helper for select operations where the expression can be
682  // efficiently reorganized.
683  Value *SimplifySelectsFeedingBinaryOp(BinaryOperator &I, Value *LHS,
684  Value *RHS);
685 
686  /// This tries to simplify binary operations by factorizing out common terms
687  /// (e. g. "(A*B)+(A*C)" -> "A*(B+C)").
688  Value *tryFactorization(BinaryOperator &, Instruction::BinaryOps, Value *,
689  Value *, Value *, Value *);
690 
691  /// Match a select chain which produces one of three values based on whether
692  /// the LHS is less than, equal to, or greater than RHS respectively.
693  /// Return true if we matched a three way compare idiom. The LHS, RHS, Less,
694  /// Equal and Greater values are saved in the matching process and returned to
695  /// the caller.
696  bool matchThreeWayIntCompare(SelectInst *SI, Value *&LHS, Value *&RHS,
698  ConstantInt *&Greater);
699 
700  /// Attempts to replace V with a simpler value based on the demanded
701  /// bits.
702  Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known,
703  unsigned Depth, Instruction *CxtI);
704  bool SimplifyDemandedBits(Instruction *I, unsigned Op,
705  const APInt &DemandedMask, KnownBits &Known,
706  unsigned Depth = 0);
707 
708  /// Helper routine of SimplifyDemandedUseBits. It computes KnownZero/KnownOne
709  /// bits. It also tries to handle simplifications that can be done based on
710  /// DemandedMask, but without modifying the Instruction.
711  Value *SimplifyMultipleUseDemandedBits(Instruction *I,
712  const APInt &DemandedMask,
713  KnownBits &Known,
714  unsigned Depth, Instruction *CxtI);
715 
716  /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
717  /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
718  Value *simplifyShrShlDemandedBits(
719  Instruction *Shr, const APInt &ShrOp1, Instruction *Shl,
720  const APInt &ShlOp1, const APInt &DemandedMask, KnownBits &Known);
721 
722  /// Tries to simplify operands to an integer instruction based on its
723  /// demanded bits.
724  bool SimplifyDemandedInstructionBits(Instruction &Inst);
725 
726  Value *simplifyAMDGCNMemoryIntrinsicDemanded(IntrinsicInst *II,
727  APInt DemandedElts,
728  int DmaskIdx = -1);
729 
730  Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
731  APInt &UndefElts, unsigned Depth = 0);
732 
733  /// Canonicalize the position of binops relative to shufflevector.
734  Instruction *foldShuffledBinop(BinaryOperator &Inst);
735 
736  /// Given a binary operator, cast instruction, or select which has a PHI node
737  /// as operand #0, see if we can fold the instruction into the PHI (which is
738  /// only possible if all operands to the PHI are constants).
739  Instruction *foldOpIntoPhi(Instruction &I, PHINode *PN);
740 
741  /// Given an instruction with a select as one operand and a constant as the
742  /// other operand, try to fold the binary operator into the select arguments.
743  /// This also works for Cast instructions, which obviously do not have a
744  /// second operand.
745  Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
746 
747  /// This is a convenience wrapper function for the above two functions.
748  Instruction *foldBinOpIntoSelectOrPhi(BinaryOperator &I);
749 
750  Instruction *foldAddWithConstant(BinaryOperator &Add);
751 
752  /// Try to rotate an operation below a PHI node, using PHI nodes for
753  /// its operands.
754  Instruction *FoldPHIArgOpIntoPHI(PHINode &PN);
755  Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN);
756  Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
757  Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
758  Instruction *FoldPHIArgZextsIntoPHI(PHINode &PN);
759 
760  /// If an integer typed PHI has only one use which is an IntToPtr operation,
761  /// replace the PHI with an existing pointer typed PHI if it exists. Otherwise
762  /// insert a new pointer typed PHI and replace the original one.
763  Instruction *FoldIntegerTypedPHI(PHINode &PN);
764 
765  /// Helper function for FoldPHIArgXIntoPHI() to set debug location for the
766  /// folded operation.
767  void PHIArgMergedDebugLoc(Instruction *Inst, PHINode &PN);
768 
769  Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
771  Instruction *foldAllocaCmp(ICmpInst &ICI, const AllocaInst *Alloca,
772  const Value *Other);
773  Instruction *foldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP,
774  GlobalVariable *GV, CmpInst &ICI,
775  ConstantInt *AndCst = nullptr);
776  Instruction *foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
777  Constant *RHSC);
778  Instruction *foldICmpAddOpConst(Value *X, ConstantInt *CI,
779  ICmpInst::Predicate Pred);
780  Instruction *foldICmpWithCastAndCast(ICmpInst &ICI);
781 
782  Instruction *foldICmpUsingKnownBits(ICmpInst &Cmp);
783  Instruction *foldICmpWithConstant(ICmpInst &Cmp);
784  Instruction *foldICmpInstWithConstant(ICmpInst &Cmp);
785  Instruction *foldICmpInstWithConstantNotInt(ICmpInst &Cmp);
786  Instruction *foldICmpBinOp(ICmpInst &Cmp);
787  Instruction *foldICmpEquality(ICmpInst &Cmp);
788  Instruction *foldICmpWithZero(ICmpInst &Cmp);
789 
790  Instruction *foldICmpSelectConstant(ICmpInst &Cmp, SelectInst *Select,
791  ConstantInt *C);
792  Instruction *foldICmpBitCastConstant(ICmpInst &Cmp, BitCastInst *Bitcast,
793  const APInt &C);
794  Instruction *foldICmpTruncConstant(ICmpInst &Cmp, TruncInst *Trunc,
795  const APInt &C);
796  Instruction *foldICmpAndConstant(ICmpInst &Cmp, BinaryOperator *And,
797  const APInt &C);
798  Instruction *foldICmpXorConstant(ICmpInst &Cmp, BinaryOperator *Xor,
799  const APInt &C);
800  Instruction *foldICmpOrConstant(ICmpInst &Cmp, BinaryOperator *Or,
801  const APInt &C);
802  Instruction *foldICmpMulConstant(ICmpInst &Cmp, BinaryOperator *Mul,
803  const APInt &C);
804  Instruction *foldICmpShlConstant(ICmpInst &Cmp, BinaryOperator *Shl,
805  const APInt &C);
806  Instruction *foldICmpShrConstant(ICmpInst &Cmp, BinaryOperator *Shr,
807  const APInt &C);
808  Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
809  const APInt &C);
810  Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,
811  const APInt &C);
812  Instruction *foldICmpSubConstant(ICmpInst &Cmp, BinaryOperator *Sub,
813  const APInt &C);
814  Instruction *foldICmpAddConstant(ICmpInst &Cmp, BinaryOperator *Add,
815  const APInt &C);
816  Instruction *foldICmpAndConstConst(ICmpInst &Cmp, BinaryOperator *And,
817  const APInt &C1);
818  Instruction *foldICmpAndShift(ICmpInst &Cmp, BinaryOperator *And,
819  const APInt &C1, const APInt &C2);
820  Instruction *foldICmpShrConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
821  const APInt &C2);
822  Instruction *foldICmpShlConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
823  const APInt &C2);
824 
825  Instruction *foldICmpBinOpEqualityWithConstant(ICmpInst &Cmp,
826  BinaryOperator *BO,
827  const APInt &C);
828  Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI, const APInt &C);
829 
830  // Helpers of visitSelectInst().
831  Instruction *foldSelectExtConst(SelectInst &Sel);
832  Instruction *foldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI);
833  Instruction *foldSelectIntoOp(SelectInst &SI, Value *, Value *);
834  Instruction *foldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1,
835  Value *A, Value *B, Instruction &Outer,
836  SelectPatternFlavor SPF2, Value *C);
837  Instruction *foldSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI);
838 
839  Instruction *OptAndOp(BinaryOperator *Op, ConstantInt *OpRHS,
840  ConstantInt *AndRHS, BinaryOperator &TheAnd);
841 
842  Value *insertRangeTest(Value *V, const APInt &Lo, const APInt &Hi,
843  bool isSigned, bool Inside);
844  Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI);
845  Instruction *MatchBSwap(BinaryOperator &I);
846  bool SimplifyStoreAtEndOfBlock(StoreInst &SI);
847 
848  Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI);
849  Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI);
850 
851  Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
852 
853  /// Returns a value X such that Val = X * Scale, or null if none.
854  ///
855  /// If the multiplication is known not to overflow then NoSignedWrap is set.
856  Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap);
857 };
858 
859 } // end namespace llvm
860 
861 #undef DEBUG_TYPE
862 
863 #endif // LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
Type * getVectorElementType() const
Definition: Type.h:368
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
Definition: Local.h:29
uint64_t CallInst * C
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:68
Instruction * InsertNewInstWith(Instruction *New, Instruction &Old)
Same as InsertNewInstBefore, but also sets the debug loc.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
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)
Return true if the given value is known to have exactly one bit set when defined. ...
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:875
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
This instruction extracts a struct member or array element value from an aggregate value...
Base class for instruction visitors.
Definition: InstVisitor.h:81
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
An instruction for ordering other memory operations.
Definition: Instructions.h:440
This class represents zero extension of integer types.
This class represents a function call, abstracting a target machine&#39;s calling convention.
static bool isCanonicalPredicate(CmpInst::Predicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
unsigned less or equal
Definition: InstrTypes.h:911
void Remove(Instruction *I)
A cache of @llvm.assume calls within a function.
This instruction constructs a fixed permutation of two input vectors.
void Add(Instruction *I)
Add - Add the specified instruction to the worklist if it isn&#39;t already in it.
This class represents a sign extension of integer types.
An instruction for reading from memory.
Definition: Instructions.h:164
uint64_t MaxArraySizeForCombine
Maximum size of array considered when transforming.
Hexagon Common GEP
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2187
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:227
static OverflowCheckFlavor IntrinsicIDToOverflowCheckFlavor(unsigned ID)
Returns the OverflowCheckFlavor corresponding to a overflow_with_op intrinsic.
This defines the Use class.
OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2176
This class represents a conversion between pointers from one address space to another.
static unsigned getComplexity(Value *V)
Assign a complexity or rank value to LLVM Values.
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
This class represents the LLVM &#39;select&#39; instruction.
OverflowCheckFlavor
Specific patterns of overflow check idioms that we match.
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:592
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
Class to represent struct types.
Definition: DerivedTypes.h:201
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
Instruction * eraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:731
The core instruction combiner logic.
static Constant * AddOne(Constant *C)
Add one to a Constant.
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:892
This class represents a cast from a pointer to an integer.
DominatorTree & getDominatorTree() const
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...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
This represents the llvm.va_start intrinsic.
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage any dbg.value intrinsics referr...
Definition: Local.cpp:1555
This instruction compares its operands according to the predicate given to the constructor.
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
An instruction for storing to memory.
Definition: Instructions.h:306
Instruction * visitInstruction(Instruction &I)
Specify what to return for unhandled instructions.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:439
This class represents a cast from floating point to signed integer.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:142
This class represents a truncation of integer types.
Class to represent pointers.
Definition: DerivedTypes.h:467
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Definition: Constants.cpp:328
const DataLayout & getDataLayout() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:837
This instruction inserts a single (scalar) element into a VectorType value.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:287
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void AddUsersToWorkList(Instruction &I)
AddUsersToWorkList - When an instruction is simplified, add all users of the instruction to the work ...
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
Definition: Constant.h:42
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if &#39;V & Mask&#39; is known to be zero.
InstCombiner(InstCombineWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, bool ExpensiveCombines, AliasAnalysis *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, const DataLayout &DL, LoopInfo *LI)
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:885
This class represents any memset intrinsic.
Instruction * CreateOverflowTuple(IntrinsicInst *II, Value *Result, Constant *Overflow)
Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value...
static Constant * get(StructType *T, ArrayRef< Constant *> V)
Definition: Constants.cpp:1011
op_range operands()
Definition: User.h:238
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:105
static bool isNot(const Value *V)
self_iterator getIterator()
Definition: ilist_node.h:82
This class represents a cast from an integer to a pointer.
InstCombineWorklist - This is the worklist management logic for InstCombine.
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1382
TargetLibraryInfo & getTargetLibraryInfo() const
InstCombineWorklist & Worklist
A worklist of the instructions that need to be simplified.
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:329
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
unsigned getNumOperands() const
Definition: User.h:192
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
SelectPatternFlavor
Specific patterns of select instructions we can match.
Provides information about what library functions are available for the current target.
unsigned ComputeNumSignBits(const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
This class represents a cast from floating point to unsigned integer.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:611
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:462
signed less or equal
Definition: InstrTypes.h:915
static bool isNeg(const Value *V)
Check if the given Value is a NEG, FNeg, or NOT instruction.
Class for arbitrary precision integers.
Definition: APInt.h:69
LoopInfo * getLoopInfo() const
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:290
OverflowResult
unsigned greater or equal
Definition: InstrTypes.h:909
KnownBits computeKnownBits(const Value *V, unsigned Depth, const Instruction *CxtI) const
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
#define I(x, y, z)
Definition: MD5.cpp:58
0 1 1 0 True if ordered and operands are unequal
Definition: InstrTypes.h:893
This instruction extracts a single (scalar) element from a VectorType value.
Instruction * InsertNewInstBefore(Instruction *New, Instruction &Old)
Inserts an instruction New before instruction Old.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const Instruction *CxtI) const
AssumptionCache & getAssumptionCache() const
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
Multiway switch.
This represents the llvm.va_copy intrinsic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
This class represents a truncation of floating point types.
LLVM Value Representation.
Definition: Value.h:73
static Constant * getSafeVectorConstantForIntDivRem(Constant *In)
Integer division/remainder require special handling to avoid undefined behavior.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
Invoke instruction.
IRTranslator LLVM IR MI
#define LLVM_DEBUG(X)
Definition: Debug.h:119
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:890
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
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 DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
The optimization diagnostic interface.
bool use_empty() const
Definition: Value.h:322
static Constant * get(ArrayRef< Constant *> V)
Definition: Constants.cpp:1046
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
signed greater or equal
Definition: InstrTypes.h:913
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
const BasicBlock * getParent() const
Definition: Instruction.h:67
an instruction to allocate memory on the stack
Definition: Instructions.h:60
This instruction inserts a struct field of array element value into an aggregate value.