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