Matt Arsenault | 52ddb7b | 2013-05-17 21:43:39 +0000 | [diff] [blame] | 1 | //===- InstCombine.h - Main InstCombine pass definition ---------*- C++ -*-===// |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H |
| 11 | #define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 12 | |
| 13 | #include "InstCombineWorklist.h" |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/AssumptionCache.h" |
Chandler Carruth | 5175b9a | 2015-01-20 08:35:24 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/LoopInfo.h" |
Chandler Carruth | 452a007 | 2014-03-04 11:59:06 +0000 | [diff] [blame] | 16 | #include "llvm/Analysis/TargetFolder.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/ValueTracking.h" |
Gerolf Hoflehner | ec6217c | 2014-11-21 23:36:44 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 19 | #include "llvm/IR/IRBuilder.h" |
Chandler Carruth | 7da14f1 | 2014-03-06 03:23:41 +0000 | [diff] [blame] | 20 | #include "llvm/IR/InstVisitor.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/IntrinsicInst.h" |
| 22 | #include "llvm/IR/Operator.h" |
Hal Finkel | 74c2f35 | 2014-09-07 12:44:26 +0000 | [diff] [blame] | 23 | #include "llvm/IR/PatternMatch.h" |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 24 | #include "llvm/Pass.h" |
Meador Inge | df796f8 | 2012-10-13 16:45:24 +0000 | [diff] [blame] | 25 | #include "llvm/Transforms/Utils/SimplifyLibCalls.h" |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 26 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 27 | #define DEBUG_TYPE "instcombine" |
| 28 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 29 | namespace llvm { |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 30 | class CallSite; |
| 31 | class DataLayout; |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 32 | class DominatorTree; |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 33 | class TargetLibraryInfo; |
| 34 | class DbgDeclareInst; |
| 35 | class MemIntrinsic; |
| 36 | class MemSetInst; |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 37 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 38 | /// \brief Specific patterns of select instructions we can match. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 39 | enum SelectPatternFlavor { |
| 40 | SPF_UNKNOWN = 0, |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 41 | SPF_SMIN, |
| 42 | SPF_UMIN, |
| 43 | SPF_SMAX, |
Dinesh Dwivedi | 3217b6c | 2014-06-06 06:54:45 +0000 | [diff] [blame] | 44 | SPF_UMAX, |
| 45 | SPF_ABS, |
| 46 | SPF_NABS |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 47 | }; |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 48 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 49 | /// \brief Assign a complexity or rank value to LLVM Values. |
| 50 | /// |
| 51 | /// This routine maps IR values to various complexity ranks: |
| 52 | /// 0 -> undef |
| 53 | /// 1 -> Constants |
| 54 | /// 2 -> Other non-instructions |
| 55 | /// 3 -> Arguments |
| 56 | /// 3 -> Unary operations |
| 57 | /// 4 -> Other instructions |
Chris Lattner | 2188e40 | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 58 | static inline unsigned getComplexity(Value *V) { |
| 59 | if (isa<Instruction>(V)) { |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 60 | if (BinaryOperator::isNeg(V) || BinaryOperator::isFNeg(V) || |
Chris Lattner | 2188e40 | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 61 | BinaryOperator::isNot(V)) |
| 62 | return 3; |
| 63 | return 4; |
| 64 | } |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 65 | if (isa<Argument>(V)) |
| 66 | return 3; |
Chris Lattner | 2188e40 | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 67 | return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2; |
| 68 | } |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 69 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 70 | /// \brief Add one to a Constant |
Benjamin Kramer | 970f495 | 2014-01-19 16:56:10 +0000 | [diff] [blame] | 71 | static inline Constant *AddOne(Constant *C) { |
| 72 | return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1)); |
| 73 | } |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 74 | /// \brief Subtract one from a Constant |
Benjamin Kramer | 970f495 | 2014-01-19 16:56:10 +0000 | [diff] [blame] | 75 | static inline Constant *SubOne(Constant *C) { |
| 76 | return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1)); |
| 77 | } |
| 78 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 79 | /// \brief An IRBuilder inserter that adds new instructions to the instcombine |
| 80 | /// worklist. |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 81 | class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 82 | : public IRBuilderDefaultInserter<true> { |
| 83 | InstCombineWorklist &Worklist; |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 84 | AssumptionCache *AC; |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 86 | public: |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 87 | InstCombineIRInserter(InstCombineWorklist &WL, AssumptionCache *AC) |
| 88 | : Worklist(WL), AC(AC) {} |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 89 | |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 90 | void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, |
| 91 | BasicBlock::iterator InsertPt) const { |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 92 | IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt); |
| 93 | Worklist.Add(I); |
Hal Finkel | 74c2f35 | 2014-09-07 12:44:26 +0000 | [diff] [blame] | 94 | |
| 95 | using namespace llvm::PatternMatch; |
Benjamin Kramer | 63207bc | 2014-10-25 18:09:01 +0000 | [diff] [blame] | 96 | if (match(I, m_Intrinsic<Intrinsic::assume>())) |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 97 | AC->registerAssumption(cast<CallInst>(I)); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 98 | } |
| 99 | }; |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 100 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 101 | /// \brief The core instruction combiner logic. |
| 102 | /// |
| 103 | /// This class provides both the logic to recursively visit instructions and |
| 104 | /// combine them, as well as the pass infrastructure for running this as part |
| 105 | /// of the LLVM pass pipeline. |
Duncan Sands | 6c5e435 | 2010-05-11 20:16:09 +0000 | [diff] [blame] | 106 | class LLVM_LIBRARY_VISIBILITY InstCombiner |
Chandler Carruth | 1edb9d6 | 2015-01-20 22:44:35 +0000 | [diff] [blame^] | 107 | : public InstVisitor<InstCombiner, Instruction *> { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 108 | AssumptionCache *AC; |
Rafael Espindola | aeff8a9 | 2014-02-24 23:12:18 +0000 | [diff] [blame] | 109 | const DataLayout *DL; |
Gerolf Hoflehner | c0b4c20 | 2014-10-07 00:16:12 +0000 | [diff] [blame] | 110 | TargetLibraryInfo *TLI; |
Gerolf Hoflehner | ec6217c | 2014-11-21 23:36:44 +0000 | [diff] [blame] | 111 | DominatorTree *DT; |
Chandler Carruth | 5175b9a | 2015-01-20 08:35:24 +0000 | [diff] [blame] | 112 | LoopInfo *LI; |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 113 | bool MadeIRChange; |
Meador Inge | df796f8 | 2012-10-13 16:45:24 +0000 | [diff] [blame] | 114 | LibCallSimplifier *Simplifier; |
Quentin Colombet | 3b2db0b | 2013-01-07 18:37:41 +0000 | [diff] [blame] | 115 | bool MinimizeSize; |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 116 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 117 | public: |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 118 | /// \brief A worklist of the instructions that need to be simplified. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 119 | InstCombineWorklist Worklist; |
| 120 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 121 | /// \brief An IRBuilder that automatically inserts new instructions into the |
| 122 | /// worklist. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 123 | typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy; |
| 124 | BuilderTy *Builder; |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 125 | |
Chandler Carruth | 1edb9d6 | 2015-01-20 22:44:35 +0000 | [diff] [blame^] | 126 | InstCombiner() : DL(nullptr), DT(nullptr), LI(nullptr), Builder(nullptr) { |
Quentin Colombet | 3b2db0b | 2013-01-07 18:37:41 +0000 | [diff] [blame] | 127 | MinimizeSize = false; |
Owen Anderson | 6c18d1a | 2010-10-19 17:21:58 +0000 | [diff] [blame] | 128 | } |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 129 | |
| 130 | public: |
Chandler Carruth | 1edb9d6 | 2015-01-20 22:44:35 +0000 | [diff] [blame^] | 131 | bool run(Function &F, AssumptionCache *AC, const DataLayout *DL, |
| 132 | TargetLibraryInfo *TLI, DominatorTree *DT, LoopInfo *LI); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 133 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 134 | bool DoOneIteration(Function &F, unsigned ItNum); |
| 135 | |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 136 | AssumptionCache *getAssumptionCache() const { return AC; } |
Hal Finkel | 74c2f35 | 2014-09-07 12:44:26 +0000 | [diff] [blame] | 137 | |
Rafael Espindola | aeff8a9 | 2014-02-24 23:12:18 +0000 | [diff] [blame] | 138 | const DataLayout *getDataLayout() const { return DL; } |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 139 | |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 140 | DominatorTree *getDominatorTree() const { return DT; } |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 141 | |
Chandler Carruth | 5175b9a | 2015-01-20 08:35:24 +0000 | [diff] [blame] | 142 | LoopInfo *getLoopInfo() const { return LI; } |
| 143 | |
Chad Rosier | 43a3306 | 2011-12-02 01:26:24 +0000 | [diff] [blame] | 144 | TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; } |
| 145 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 146 | // Visitation implementation - Implement instruction combining for different |
| 147 | // instruction types. The semantics are as follows: |
| 148 | // Return Value: |
| 149 | // null - No change was made |
| 150 | // I - Change was made, I is still valid, I may be dead though |
| 151 | // otherwise - Change was made, replace I with returned instruction |
| 152 | // |
| 153 | Instruction *visitAdd(BinaryOperator &I); |
| 154 | Instruction *visitFAdd(BinaryOperator &I); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 155 | Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 156 | Instruction *visitSub(BinaryOperator &I); |
| 157 | Instruction *visitFSub(BinaryOperator &I); |
| 158 | Instruction *visitMul(BinaryOperator &I); |
Benjamin Kramer | 76b15d0 | 2014-01-19 13:36:27 +0000 | [diff] [blame] | 159 | Value *foldFMulConst(Instruction *FMulOrDiv, Constant *C, |
Shuxin Yang | df0e61e | 2013-01-07 21:39:23 +0000 | [diff] [blame] | 160 | Instruction *InsertBefore); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 161 | Instruction *visitFMul(BinaryOperator &I); |
| 162 | Instruction *visitURem(BinaryOperator &I); |
| 163 | Instruction *visitSRem(BinaryOperator &I); |
| 164 | Instruction *visitFRem(BinaryOperator &I); |
| 165 | bool SimplifyDivRemOfSelect(BinaryOperator &I); |
| 166 | Instruction *commonRemTransforms(BinaryOperator &I); |
| 167 | Instruction *commonIRemTransforms(BinaryOperator &I); |
| 168 | Instruction *commonDivTransforms(BinaryOperator &I); |
| 169 | Instruction *commonIDivTransforms(BinaryOperator &I); |
| 170 | Instruction *visitUDiv(BinaryOperator &I); |
| 171 | Instruction *visitSDiv(BinaryOperator &I); |
Frits van Bommel | 2a55951 | 2011-01-29 17:50:27 +0000 | [diff] [blame] | 172 | Instruction *visitFDiv(BinaryOperator &I); |
Erik Eckstein | d181752 | 2014-12-03 10:39:15 +0000 | [diff] [blame] | 173 | Value *simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted); |
Chris Lattner | 067459c | 2010-03-05 08:46:26 +0000 | [diff] [blame] | 174 | Value *FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS); |
| 175 | Value *FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 176 | Instruction *visitAnd(BinaryOperator &I); |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 177 | Value *FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI); |
Chris Lattner | 067459c | 2010-03-05 08:46:26 +0000 | [diff] [blame] | 178 | Value *FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 179 | Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op, Value *A, |
| 180 | Value *B, Value *C); |
David Majnemer | 5d1aeba | 2014-08-21 05:14:48 +0000 | [diff] [blame] | 181 | Instruction *FoldXorWithConstants(BinaryOperator &I, Value *Op, Value *A, |
| 182 | Value *B, Value *C); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 183 | Instruction *visitOr(BinaryOperator &I); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 184 | Instruction *visitXor(BinaryOperator &I); |
| 185 | Instruction *visitShl(BinaryOperator &I); |
| 186 | Instruction *visitAShr(BinaryOperator &I); |
| 187 | Instruction *visitLShr(BinaryOperator &I); |
| 188 | Instruction *commonShiftTransforms(BinaryOperator &I); |
| 189 | Instruction *FoldFCmp_IntToFP_Cst(FCmpInst &I, Instruction *LHSI, |
| 190 | Constant *RHSC); |
| 191 | Instruction *FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, |
| 192 | GlobalVariable *GV, CmpInst &ICI, |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 193 | ConstantInt *AndCst = nullptr); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 194 | Instruction *visitFCmpInst(FCmpInst &I); |
| 195 | Instruction *visitICmpInst(ICmpInst &I); |
| 196 | Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 197 | Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Instruction *LHS, |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 198 | ConstantInt *RHS); |
| 199 | Instruction *FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI, |
| 200 | ConstantInt *DivRHS); |
Chris Lattner | d369f57 | 2011-02-13 07:43:07 +0000 | [diff] [blame] | 201 | Instruction *FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *DivI, |
| 202 | ConstantInt *DivRHS); |
Suyog Sarda | 3a8c2c1 | 2014-07-22 19:19:36 +0000 | [diff] [blame] | 203 | Instruction *FoldICmpCstShrCst(ICmpInst &I, Value *Op, Value *A, |
| 204 | ConstantInt *CI1, ConstantInt *CI2); |
David Majnemer | 59939ac | 2014-10-19 08:23:08 +0000 | [diff] [blame] | 205 | Instruction *FoldICmpCstShlCst(ICmpInst &I, Value *Op, Value *A, |
| 206 | ConstantInt *CI1, ConstantInt *CI2); |
Benjamin Kramer | 0e2d162 | 2013-09-20 22:12:42 +0000 | [diff] [blame] | 207 | Instruction *FoldICmpAddOpCst(Instruction &ICI, Value *X, ConstantInt *CI, |
| 208 | ICmpInst::Predicate Pred); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 209 | Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, |
| 210 | ICmpInst::Predicate Cond, Instruction &I); |
Matt Arsenault | fed3dc8 | 2014-04-14 21:50:37 +0000 | [diff] [blame] | 211 | Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1, |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 212 | BinaryOperator &I); |
| 213 | Instruction *commonCastTransforms(CastInst &CI); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 214 | Instruction *commonPointerCastTransforms(CastInst &CI); |
| 215 | Instruction *visitTrunc(TruncInst &CI); |
| 216 | Instruction *visitZExt(ZExtInst &CI); |
| 217 | Instruction *visitSExt(SExtInst &CI); |
| 218 | Instruction *visitFPTrunc(FPTruncInst &CI); |
| 219 | Instruction *visitFPExt(CastInst &CI); |
| 220 | Instruction *visitFPToUI(FPToUIInst &FI); |
| 221 | Instruction *visitFPToSI(FPToSIInst &FI); |
| 222 | Instruction *visitUIToFP(CastInst &CI); |
| 223 | Instruction *visitSIToFP(CastInst &CI); |
| 224 | Instruction *visitPtrToInt(PtrToIntInst &CI); |
| 225 | Instruction *visitIntToPtr(IntToPtrInst &CI); |
| 226 | Instruction *visitBitCast(BitCastInst &CI); |
Matt Arsenault | a9e95ab | 2013-11-15 05:45:08 +0000 | [diff] [blame] | 227 | Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 228 | Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI); |
| 229 | Instruction *FoldSelectIntoOp(SelectInst &SI, Value *, Value *); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 230 | Instruction *FoldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1, |
| 231 | Value *A, Value *B, Instruction &Outer, |
| 232 | SelectPatternFlavor SPF2, Value *C); |
| 233 | Instruction *visitSelectInst(SelectInst &SI); |
| 234 | Instruction *visitSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI); |
| 235 | Instruction *visitCallInst(CallInst &CI); |
| 236 | Instruction *visitInvokeInst(InvokeInst &II); |
| 237 | |
| 238 | Instruction *SliceUpIllegalIntegerPHI(PHINode &PN); |
| 239 | Instruction *visitPHINode(PHINode &PN); |
| 240 | Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP); |
| 241 | Instruction *visitAllocaInst(AllocaInst &AI); |
Nuno Lopes | 95cc4f3 | 2012-07-09 18:38:20 +0000 | [diff] [blame] | 242 | Instruction *visitAllocSite(Instruction &FI); |
Gabor Greif | 75f6943 | 2010-06-24 12:21:15 +0000 | [diff] [blame] | 243 | Instruction *visitFree(CallInst &FI); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 244 | Instruction *visitLoadInst(LoadInst &LI); |
| 245 | Instruction *visitStoreInst(StoreInst &SI); |
| 246 | Instruction *visitBranchInst(BranchInst &BI); |
| 247 | Instruction *visitSwitchInst(SwitchInst &SI); |
Hal Finkel | 93873cc1 | 2014-09-07 21:28:34 +0000 | [diff] [blame] | 248 | Instruction *visitReturnInst(ReturnInst &RI); |
Michael Zolotukhin | 7d6293a | 2014-05-07 14:30:18 +0000 | [diff] [blame] | 249 | Instruction *visitInsertValueInst(InsertValueInst &IV); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 250 | Instruction *visitInsertElementInst(InsertElementInst &IE); |
| 251 | Instruction *visitExtractElementInst(ExtractElementInst &EI); |
| 252 | Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI); |
| 253 | Instruction *visitExtractValueInst(ExtractValueInst &EV); |
Duncan Sands | 5c05579 | 2011-09-30 13:12:16 +0000 | [diff] [blame] | 254 | Instruction *visitLandingPadInst(LandingPadInst &LI); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 255 | |
| 256 | // visitInstruction - Specify what to return for unhandled instructions... |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 257 | Instruction *visitInstruction(Instruction &I) { return nullptr; } |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 258 | |
Gerolf Hoflehner | ec6217c | 2014-11-21 23:36:44 +0000 | [diff] [blame] | 259 | // True when DB dominates all uses of DI execpt UI. |
| 260 | // UI must be in the same block as DI. |
| 261 | // The routine checks that the DI parent and DB are different. |
| 262 | bool dominatesAllUses(const Instruction *DI, const Instruction *UI, |
| 263 | const BasicBlock *DB) const; |
| 264 | |
| 265 | // Replace select with select operand SIOpd in SI-ICmp sequence when possible |
| 266 | bool replacedSelectWithOperand(SelectInst *SI, const ICmpInst *Icmp, |
| 267 | const unsigned SIOpd); |
| 268 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 269 | private: |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 270 | bool ShouldChangeType(Type *From, Type *To) const; |
Chris Lattner | 2188e40 | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 271 | Value *dyn_castNegVal(Value *V) const; |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 272 | Value *dyn_castFNegVal(Value *V, bool NoSignedZero = false) const; |
Matt Arsenault | d79f7d9 | 2013-08-19 22:17:40 +0000 | [diff] [blame] | 273 | Type *FindElementAtOffset(Type *PtrTy, int64_t Offset, |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 274 | SmallVectorImpl<Value *> &NewIndices); |
Chris Lattner | 2b295a0 | 2010-01-04 07:53:58 +0000 | [diff] [blame] | 275 | Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 276 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 277 | /// \brief Classify whether a cast is worth optimizing. |
| 278 | /// |
| 279 | /// Returns true if the cast from "V to Ty" actually results in any code |
| 280 | /// being generated and is interesting to optimize out. If the cast can be |
| 281 | /// eliminated by some other simple transformation, we prefer to do the |
| 282 | /// simplification first. |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 283 | bool ShouldOptimizeCast(Instruction::CastOps opcode, const Value *V, |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 284 | Type *Ty); |
Chris Lattner | 2188e40 | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 285 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 286 | Instruction *visitCallSite(CallSite CS); |
Rafael Espindola | 37dc9e1 | 2014-02-21 00:06:31 +0000 | [diff] [blame] | 287 | Instruction *tryOptimizeCall(CallInst *CI, const DataLayout *DL); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 288 | bool transformConstExprCastCall(CallSite CS); |
Duncan Sands | a098436 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 289 | Instruction *transformCallThroughTrampoline(CallSite CS, |
| 290 | IntrinsicInst *Tramp); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 291 | Instruction *transformZExtICmp(ICmpInst *ICI, Instruction &CI, |
| 292 | bool DoXform = true); |
Benjamin Kramer | 398b8c5 | 2011-04-01 20:09:03 +0000 | [diff] [blame] | 293 | Instruction *transformSExtICmp(ICmpInst *ICI, Instruction &CI); |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 294 | bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS, Instruction *CxtI); |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 295 | bool WillNotOverflowSignedSub(Value *LHS, Value *RHS, Instruction *CxtI); |
| 296 | bool WillNotOverflowUnsignedSub(Value *LHS, Value *RHS, Instruction *CxtI); |
Erik Eckstein | a451b9b | 2014-12-17 07:29:19 +0000 | [diff] [blame] | 297 | bool WillNotOverflowSignedMul(Value *LHS, Value *RHS, Instruction *CxtI); |
Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 298 | Value *EmitGEPOffset(User *GEP); |
Anat Shemer | 0c95efa | 2013-04-18 19:35:39 +0000 | [diff] [blame] | 299 | Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN); |
Nick Lewycky | a2b7720 | 2013-05-31 00:59:42 +0000 | [diff] [blame] | 300 | Value *EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 301 | |
| 302 | public: |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 303 | /// \brief Inserts an instruction \p New before instruction \p Old |
| 304 | /// |
| 305 | /// Also adds the new instruction to the worklist and returns \p New so that |
| 306 | /// it is suitable for use as the return from the visitation patterns. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 307 | Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) { |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 308 | assert(New && !New->getParent() && |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 309 | "New instruction already inserted into a basic block!"); |
| 310 | BasicBlock *BB = Old.getParent(); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 311 | BB->getInstList().insert(&Old, New); // Insert inst |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 312 | Worklist.Add(New); |
| 313 | return New; |
| 314 | } |
Eli Friedman | 6efb64e | 2011-05-19 01:20:42 +0000 | [diff] [blame] | 315 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 316 | /// \brief Same as InsertNewInstBefore, but also sets the debug loc. |
Eli Friedman | 6efb64e | 2011-05-19 01:20:42 +0000 | [diff] [blame] | 317 | Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) { |
| 318 | New->setDebugLoc(Old.getDebugLoc()); |
| 319 | return InsertNewInstBefore(New, Old); |
| 320 | } |
| 321 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 322 | /// \brief A combiner-aware RAUW-like routine. |
| 323 | /// |
| 324 | /// This method is to be used when an instruction is found to be dead, |
| 325 | /// replacable with another preexisting expression. Here we add all uses of |
| 326 | /// I to the worklist, replace all uses of I with the new value, then return |
| 327 | /// I, so that the inst combiner will know that I was modified. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 328 | Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) { |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 329 | Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist. |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 330 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 331 | // If we are replacing the instruction with itself, this must be in a |
| 332 | // segment of unreachable code, so just clobber the instruction. |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 333 | if (&I == V) |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 334 | V = UndefValue::get(I.getType()); |
Frits van Bommel | d14d991 | 2011-03-27 23:32:31 +0000 | [diff] [blame] | 335 | |
Matt Arsenault | e6db760 | 2013-09-05 19:48:28 +0000 | [diff] [blame] | 336 | DEBUG(dbgs() << "IC: Replacing " << I << "\n" |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 337 | << " with " << *V << '\n'); |
Frits van Bommel | d14d991 | 2011-03-27 23:32:31 +0000 | [diff] [blame] | 338 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 339 | I.replaceAllUsesWith(V); |
| 340 | return &I; |
| 341 | } |
| 342 | |
Erik Eckstein | 096ff7d | 2014-12-11 08:02:30 +0000 | [diff] [blame] | 343 | /// Creates a result tuple for an overflow intrinsic \p II with a given |
| 344 | /// \p Result and a constant \p Overflow value. If \p ReUseName is true the |
| 345 | /// \p Result's name is taken from \p II. |
| 346 | Instruction *CreateOverflowTuple(IntrinsicInst *II, Value *Result, |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 347 | bool Overflow, bool ReUseName = true) { |
Erik Eckstein | 096ff7d | 2014-12-11 08:02:30 +0000 | [diff] [blame] | 348 | if (ReUseName) |
| 349 | Result->takeName(II); |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 350 | Constant *V[] = {UndefValue::get(Result->getType()), |
| 351 | Overflow ? Builder->getTrue() : Builder->getFalse()}; |
Erik Eckstein | 096ff7d | 2014-12-11 08:02:30 +0000 | [diff] [blame] | 352 | StructType *ST = cast<StructType>(II->getType()); |
| 353 | Constant *Struct = ConstantStruct::get(ST, V); |
| 354 | return InsertValueInst::Create(Struct, Result, 0); |
| 355 | } |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 356 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 357 | /// \brief Combiner aware instruction erasure. |
| 358 | /// |
| 359 | /// When dealing with an instruction that has side effects or produces a void |
| 360 | /// value, we can't rely on DCE to delete the instruction. Instead, visit |
| 361 | /// methods should return the value returned by this function. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 362 | Instruction *EraseInstFromFunction(Instruction &I) { |
Matt Arsenault | e6db760 | 2013-09-05 19:48:28 +0000 | [diff] [blame] | 363 | DEBUG(dbgs() << "IC: ERASE " << I << '\n'); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 364 | |
| 365 | assert(I.use_empty() && "Cannot erase instruction that is used!"); |
| 366 | // Make sure that we reprocess all operands now that we reduced their |
| 367 | // use counts. |
| 368 | if (I.getNumOperands() < 8) { |
| 369 | for (User::op_iterator i = I.op_begin(), e = I.op_end(); i != e; ++i) |
| 370 | if (Instruction *Op = dyn_cast<Instruction>(*i)) |
| 371 | Worklist.Add(Op); |
| 372 | } |
| 373 | Worklist.Remove(&I); |
| 374 | I.eraseFromParent(); |
| 375 | MadeIRChange = true; |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 376 | return nullptr; // Don't do anything with FI |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 377 | } |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 378 | |
Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 379 | void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 380 | unsigned Depth = 0, Instruction *CxtI = nullptr) const { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 381 | return llvm::computeKnownBits(V, KnownZero, KnownOne, DL, Depth, AC, CxtI, |
| 382 | DT); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 383 | } |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 384 | |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 385 | bool MaskedValueIsZero(Value *V, const APInt &Mask, unsigned Depth = 0, |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 386 | Instruction *CxtI = nullptr) const { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 387 | return llvm::MaskedValueIsZero(V, Mask, DL, Depth, AC, CxtI, DT); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 388 | } |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 389 | unsigned ComputeNumSignBits(Value *Op, unsigned Depth = 0, |
| 390 | Instruction *CxtI = nullptr) const { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 391 | return llvm::ComputeNumSignBits(Op, DL, Depth, AC, CxtI, DT); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 392 | } |
David Majnemer | 54c2ca2 | 2014-12-26 09:10:14 +0000 | [diff] [blame] | 393 | void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, |
| 394 | unsigned Depth = 0, Instruction *CxtI = nullptr) const { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 395 | return llvm::ComputeSignBit(V, KnownZero, KnownOne, DL, Depth, AC, CxtI, |
David Majnemer | 54c2ca2 | 2014-12-26 09:10:14 +0000 | [diff] [blame] | 396 | DT); |
| 397 | } |
David Majnemer | 491331a | 2015-01-02 07:29:43 +0000 | [diff] [blame] | 398 | OverflowResult computeOverflowForUnsignedMul(Value *LHS, Value *RHS, |
| 399 | const Instruction *CxtI) { |
Chandler Carruth | 66b3130 | 2015-01-04 12:03:27 +0000 | [diff] [blame] | 400 | return llvm::computeOverflowForUnsignedMul(LHS, RHS, DL, AC, CxtI, DT); |
David Majnemer | 491331a | 2015-01-02 07:29:43 +0000 | [diff] [blame] | 401 | } |
David Majnemer | 5310c1e | 2015-01-07 00:39:50 +0000 | [diff] [blame] | 402 | OverflowResult computeOverflowForUnsignedAdd(Value *LHS, Value *RHS, |
| 403 | const Instruction *CxtI) { |
| 404 | return llvm::computeOverflowForUnsignedAdd(LHS, RHS, DL, AC, CxtI, DT); |
| 405 | } |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 406 | |
| 407 | private: |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 408 | /// \brief Performs a few simplifications for operators which are associative |
| 409 | /// or commutative. |
Duncan Sands | 641baf1 | 2010-11-13 15:10:37 +0000 | [diff] [blame] | 410 | bool SimplifyAssociativeOrCommutative(BinaryOperator &I); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 411 | |
Chandler Carruth | b3d03df | 2015-01-20 21:10:35 +0000 | [diff] [blame] | 412 | /// \brief Tries to simplify binary operations which some other binary |
| 413 | /// operation distributes over. |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 414 | /// |
| 415 | /// It does this by either by factorizing out common terms (eg "(A*B)+(A*C)" |
| 416 | /// -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A |
| 417 | /// & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified |
| 418 | /// value, or null if it didn't simplify. |
Duncan Sands | fbb9ac3 | 2010-12-22 13:36:08 +0000 | [diff] [blame] | 419 | Value *SimplifyUsingDistributiveLaws(BinaryOperator &I); |
Duncan Sands | adc7771f | 2010-11-23 14:23:47 +0000 | [diff] [blame] | 420 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 421 | /// \brief Attempts to replace V with a simpler value based on the demanded |
| 422 | /// bits. |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 423 | Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, APInt &KnownZero, |
Hal Finkel | 60db058 | 2014-09-07 18:57:58 +0000 | [diff] [blame] | 424 | APInt &KnownOne, unsigned Depth, |
| 425 | Instruction *CxtI = nullptr); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 426 | bool SimplifyDemandedBits(Use &U, APInt DemandedMask, APInt &KnownZero, |
| 427 | APInt &KnownOne, unsigned Depth = 0); |
Shuxin Yang | 63e999e | 2012-12-04 00:04:54 +0000 | [diff] [blame] | 428 | /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded |
| 429 | /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence. |
| 430 | Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl, |
| 431 | APInt DemandedMask, APInt &KnownZero, |
| 432 | APInt &KnownOne); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 433 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 434 | /// \brief Tries to simplify operands to an integer instruction based on its |
| 435 | /// demanded bits. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 436 | bool SimplifyDemandedInstructionBits(Instruction &Inst); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 437 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 438 | Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 439 | APInt &UndefElts, unsigned Depth = 0); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 440 | |
Serge Pavlov | 9ef66a8 | 2014-05-11 08:46:12 +0000 | [diff] [blame] | 441 | Value *SimplifyVectorOp(BinaryOperator &Inst); |
Simon Pilgrim | be24ab3 | 2014-12-04 09:44:01 +0000 | [diff] [blame] | 442 | Value *SimplifyBSwap(BinaryOperator &Inst); |
Serge Pavlov | 9ef66a8 | 2014-05-11 08:46:12 +0000 | [diff] [blame] | 443 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 444 | // FoldOpIntoPhi - Given a binary operator, cast instruction, or select |
| 445 | // which has a PHI node as operand #0, see if we can fold the instruction |
| 446 | // into the PHI (which is only possible if all operands to the PHI are |
| 447 | // constants). |
| 448 | // |
Chris Lattner | ea7131a | 2011-01-16 05:14:26 +0000 | [diff] [blame] | 449 | Instruction *FoldOpIntoPhi(Instruction &I); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 450 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 451 | /// \brief Try to rotate an operation below a PHI node, using PHI nodes for |
| 452 | /// its operands. |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 453 | Instruction *FoldPHIArgOpIntoPHI(PHINode &PN); |
| 454 | Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN); |
| 455 | Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN); |
| 456 | Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN); |
| 457 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 458 | Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS, |
| 459 | ConstantInt *AndRHS, BinaryOperator &TheAnd); |
Jakub Staszak | 190db2f | 2013-01-14 23:16:36 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 461 | Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask, |
| 462 | bool isSub, Instruction &I); |
Chandler Carruth | d70cc60 | 2014-05-07 17:36:59 +0000 | [diff] [blame] | 463 | Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi, bool isSigned, |
| 464 | bool Inside); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 465 | Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI); |
| 466 | Instruction *MatchBSwap(BinaryOperator &I); |
| 467 | bool SimplifyStoreAtEndOfBlock(StoreInst &SI); |
| 468 | Instruction *SimplifyMemTransfer(MemIntrinsic *MI); |
| 469 | Instruction *SimplifyMemSet(MemSetInst *MI); |
| 470 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 471 | Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned); |
Duncan Sands | 533c8ae | 2012-10-23 08:28:26 +0000 | [diff] [blame] | 472 | |
Chandler Carruth | 3a62216 | 2015-01-20 19:27:58 +0000 | [diff] [blame] | 473 | /// \brief Returns a value X such that Val = X * Scale, or null if none. |
| 474 | /// |
| 475 | /// If the multiplication is known not to overflow then NoSignedWrap is set. |
Duncan Sands | 533c8ae | 2012-10-23 08:28:26 +0000 | [diff] [blame] | 476 | Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap); |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 479 | } // end namespace llvm. |
| 480 | |
Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 481 | #undef DEBUG_TYPE |
| 482 | |
Chris Lattner | 35522b7 | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 483 | #endif |