Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 1 | //===- InstCombine.h - Main InstCombine pass definition -------------------===// |
| 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 | #ifndef INSTCOMBINE_INSTCOMBINE_H |
| 11 | #define INSTCOMBINE_INSTCOMBINE_H |
| 12 | |
| 13 | #include "InstCombineWorklist.h" |
Duncan Sands | 4a544a7 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 14 | #include "llvm/IntrinsicInst.h" |
Jay Foad | 562b84b | 2011-04-11 09:35:34 +0000 | [diff] [blame] | 15 | #include "llvm/Operator.h" |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 16 | #include "llvm/Pass.h" |
| 17 | #include "llvm/Analysis/ValueTracking.h" |
| 18 | #include "llvm/Support/IRBuilder.h" |
| 19 | #include "llvm/Support/InstVisitor.h" |
| 20 | #include "llvm/Support/TargetFolder.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class CallSite; |
| 24 | class TargetData; |
Chris Lattner | 43fd901 | 2010-01-05 05:21:26 +0000 | [diff] [blame] | 25 | class DbgDeclareInst; |
| 26 | class MemIntrinsic; |
| 27 | class MemSetInst; |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 28 | |
| 29 | /// SelectPatternFlavor - We can match a variety of different patterns for |
| 30 | /// select operations. |
| 31 | enum SelectPatternFlavor { |
| 32 | SPF_UNKNOWN = 0, |
| 33 | SPF_SMIN, SPF_UMIN, |
| 34 | SPF_SMAX, SPF_UMAX |
| 35 | //SPF_ABS - TODO. |
| 36 | }; |
Chris Lattner | 02446fc | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 37 | |
| 38 | /// getComplexity: Assign a complexity or rank value to LLVM Values... |
| 39 | /// 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst |
| 40 | static inline unsigned getComplexity(Value *V) { |
| 41 | if (isa<Instruction>(V)) { |
| 42 | if (BinaryOperator::isNeg(V) || |
| 43 | BinaryOperator::isFNeg(V) || |
| 44 | BinaryOperator::isNot(V)) |
| 45 | return 3; |
| 46 | return 4; |
| 47 | } |
| 48 | if (isa<Argument>(V)) return 3; |
| 49 | return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2; |
| 50 | } |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | /// InstCombineIRInserter - This is an IRBuilder insertion helper that works |
| 54 | /// just like the normal insertion helper, but also adds any new instructions |
| 55 | /// to the instcombine worklist. |
Duncan Sands | 16d8f8b | 2010-05-11 20:16:09 +0000 | [diff] [blame] | 56 | class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 57 | : public IRBuilderDefaultInserter<true> { |
| 58 | InstCombineWorklist &Worklist; |
| 59 | public: |
| 60 | InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {} |
| 61 | |
| 62 | void InsertHelper(Instruction *I, const Twine &Name, |
| 63 | BasicBlock *BB, BasicBlock::iterator InsertPt) const { |
| 64 | IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt); |
| 65 | Worklist.Add(I); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | /// InstCombiner - The -instcombine pass. |
Duncan Sands | 16d8f8b | 2010-05-11 20:16:09 +0000 | [diff] [blame] | 70 | class LLVM_LIBRARY_VISIBILITY InstCombiner |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 71 | : public FunctionPass, |
| 72 | public InstVisitor<InstCombiner, Instruction*> { |
| 73 | TargetData *TD; |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 74 | bool MadeIRChange; |
| 75 | public: |
| 76 | /// Worklist - All of the instructions that need to be simplified. |
| 77 | InstCombineWorklist Worklist; |
| 78 | |
| 79 | /// Builder - This is an IRBuilder that automatically inserts new |
| 80 | /// instructions into the worklist when they are created. |
| 81 | typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy; |
| 82 | BuilderTy *Builder; |
| 83 | |
| 84 | static char ID; // Pass identification, replacement for typeid |
Owen Anderson | 081c34b | 2010-10-19 17:21:58 +0000 | [diff] [blame] | 85 | InstCombiner() : FunctionPass(ID), TD(0), Builder(0) { |
| 86 | initializeInstCombinerPass(*PassRegistry::getPassRegistry()); |
| 87 | } |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 88 | |
| 89 | public: |
| 90 | virtual bool runOnFunction(Function &F); |
| 91 | |
| 92 | bool DoOneIteration(Function &F, unsigned ItNum); |
| 93 | |
Chris Lattner | e0b4b72 | 2010-01-04 07:17:19 +0000 | [diff] [blame] | 94 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
| 95 | |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 96 | TargetData *getTargetData() const { return TD; } |
| 97 | |
| 98 | // Visitation implementation - Implement instruction combining for different |
| 99 | // instruction types. The semantics are as follows: |
| 100 | // Return Value: |
| 101 | // null - No change was made |
| 102 | // I - Change was made, I is still valid, I may be dead though |
| 103 | // otherwise - Change was made, replace I with returned instruction |
| 104 | // |
| 105 | Instruction *visitAdd(BinaryOperator &I); |
| 106 | Instruction *visitFAdd(BinaryOperator &I); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 107 | Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 108 | Instruction *visitSub(BinaryOperator &I); |
| 109 | Instruction *visitFSub(BinaryOperator &I); |
| 110 | Instruction *visitMul(BinaryOperator &I); |
| 111 | Instruction *visitFMul(BinaryOperator &I); |
| 112 | Instruction *visitURem(BinaryOperator &I); |
| 113 | Instruction *visitSRem(BinaryOperator &I); |
| 114 | Instruction *visitFRem(BinaryOperator &I); |
| 115 | bool SimplifyDivRemOfSelect(BinaryOperator &I); |
| 116 | Instruction *commonRemTransforms(BinaryOperator &I); |
| 117 | Instruction *commonIRemTransforms(BinaryOperator &I); |
| 118 | Instruction *commonDivTransforms(BinaryOperator &I); |
| 119 | Instruction *commonIDivTransforms(BinaryOperator &I); |
| 120 | Instruction *visitUDiv(BinaryOperator &I); |
| 121 | Instruction *visitSDiv(BinaryOperator &I); |
Frits van Bommel | 31726c1 | 2011-01-29 17:50:27 +0000 | [diff] [blame] | 122 | Instruction *visitFDiv(BinaryOperator &I); |
Chris Lattner | f34f48c | 2010-03-05 08:46:26 +0000 | [diff] [blame] | 123 | Value *FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS); |
| 124 | Value *FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 125 | Instruction *visitAnd(BinaryOperator &I); |
Chris Lattner | f34f48c | 2010-03-05 08:46:26 +0000 | [diff] [blame] | 126 | Value *FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS); |
| 127 | Value *FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 128 | Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op, |
| 129 | Value *A, Value *B, Value *C); |
| 130 | Instruction *visitOr (BinaryOperator &I); |
| 131 | Instruction *visitXor(BinaryOperator &I); |
| 132 | Instruction *visitShl(BinaryOperator &I); |
| 133 | Instruction *visitAShr(BinaryOperator &I); |
| 134 | Instruction *visitLShr(BinaryOperator &I); |
| 135 | Instruction *commonShiftTransforms(BinaryOperator &I); |
| 136 | Instruction *FoldFCmp_IntToFP_Cst(FCmpInst &I, Instruction *LHSI, |
| 137 | Constant *RHSC); |
| 138 | Instruction *FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, |
| 139 | GlobalVariable *GV, CmpInst &ICI, |
| 140 | ConstantInt *AndCst = 0); |
| 141 | Instruction *visitFCmpInst(FCmpInst &I); |
| 142 | Instruction *visitICmpInst(ICmpInst &I); |
| 143 | Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI); |
| 144 | Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI, |
| 145 | Instruction *LHS, |
| 146 | ConstantInt *RHS); |
| 147 | Instruction *FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI, |
| 148 | ConstantInt *DivRHS); |
Chris Lattner | 74542aa | 2011-02-13 07:43:07 +0000 | [diff] [blame] | 149 | Instruction *FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *DivI, |
| 150 | ConstantInt *DivRHS); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 151 | Instruction *FoldICmpAddOpCst(ICmpInst &ICI, Value *X, ConstantInt *CI, |
| 152 | ICmpInst::Predicate Pred, Value *TheAdd); |
| 153 | Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, |
| 154 | ICmpInst::Predicate Cond, Instruction &I); |
| 155 | Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1, |
| 156 | BinaryOperator &I); |
| 157 | Instruction *commonCastTransforms(CastInst &CI); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 158 | Instruction *commonPointerCastTransforms(CastInst &CI); |
| 159 | Instruction *visitTrunc(TruncInst &CI); |
| 160 | Instruction *visitZExt(ZExtInst &CI); |
| 161 | Instruction *visitSExt(SExtInst &CI); |
| 162 | Instruction *visitFPTrunc(FPTruncInst &CI); |
| 163 | Instruction *visitFPExt(CastInst &CI); |
| 164 | Instruction *visitFPToUI(FPToUIInst &FI); |
| 165 | Instruction *visitFPToSI(FPToSIInst &FI); |
| 166 | Instruction *visitUIToFP(CastInst &CI); |
| 167 | Instruction *visitSIToFP(CastInst &CI); |
| 168 | Instruction *visitPtrToInt(PtrToIntInst &CI); |
| 169 | Instruction *visitIntToPtr(IntToPtrInst &CI); |
| 170 | Instruction *visitBitCast(BitCastInst &CI); |
| 171 | Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI, |
| 172 | Instruction *FI); |
| 173 | Instruction *FoldSelectIntoOp(SelectInst &SI, Value*, Value*); |
| 174 | Instruction *FoldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1, |
| 175 | Value *A, Value *B, Instruction &Outer, |
| 176 | SelectPatternFlavor SPF2, Value *C); |
| 177 | Instruction *visitSelectInst(SelectInst &SI); |
| 178 | Instruction *visitSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI); |
| 179 | Instruction *visitCallInst(CallInst &CI); |
| 180 | Instruction *visitInvokeInst(InvokeInst &II); |
| 181 | |
| 182 | Instruction *SliceUpIllegalIntegerPHI(PHINode &PN); |
| 183 | Instruction *visitPHINode(PHINode &PN); |
| 184 | Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP); |
| 185 | Instruction *visitAllocaInst(AllocaInst &AI); |
Duncan Sands | 1d9b973 | 2010-05-27 19:09:06 +0000 | [diff] [blame] | 186 | Instruction *visitMalloc(Instruction &FI); |
Gabor Greif | 9169737 | 2010-06-24 12:21:15 +0000 | [diff] [blame] | 187 | Instruction *visitFree(CallInst &FI); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 188 | Instruction *visitLoadInst(LoadInst &LI); |
| 189 | Instruction *visitStoreInst(StoreInst &SI); |
| 190 | Instruction *visitBranchInst(BranchInst &BI); |
| 191 | Instruction *visitSwitchInst(SwitchInst &SI); |
| 192 | Instruction *visitInsertElementInst(InsertElementInst &IE); |
| 193 | Instruction *visitExtractElementInst(ExtractElementInst &EI); |
| 194 | Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI); |
| 195 | Instruction *visitExtractValueInst(ExtractValueInst &EV); |
| 196 | |
| 197 | // visitInstruction - Specify what to return for unhandled instructions... |
| 198 | Instruction *visitInstruction(Instruction &I) { return 0; } |
| 199 | |
| 200 | private: |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 201 | bool ShouldChangeType(Type *From, Type *To) const; |
Chris Lattner | 02446fc | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 202 | Value *dyn_castNegVal(Value *V) const; |
Chris Lattner | d12c27c | 2010-01-05 06:09:35 +0000 | [diff] [blame] | 203 | Value *dyn_castFNegVal(Value *V) const; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 204 | Type *FindElementAtOffset(Type *Ty, int64_t Offset, |
Chris Lattner | 80f43d3 | 2010-01-04 07:53:58 +0000 | [diff] [blame] | 205 | SmallVectorImpl<Value*> &NewIndices); |
| 206 | Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI); |
| 207 | |
Chris Lattner | 8c5ad3a | 2010-02-11 06:26:33 +0000 | [diff] [blame] | 208 | /// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually |
| 209 | /// results in any code being generated and is interesting to optimize out. If |
| 210 | /// the cast can be eliminated by some other simple transformation, we prefer |
| 211 | /// to do the simplification first. |
| 212 | bool ShouldOptimizeCast(Instruction::CastOps opcode,const Value *V, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 213 | Type *Ty); |
Chris Lattner | 02446fc | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 214 | |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 215 | Instruction *visitCallSite(CallSite CS); |
Eric Christopher | 27ceaa1 | 2010-03-06 10:50:38 +0000 | [diff] [blame] | 216 | Instruction *tryOptimizeCall(CallInst *CI, const TargetData *TD); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 217 | bool transformConstExprCastCall(CallSite CS); |
Duncan Sands | 4a544a7 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 218 | Instruction *transformCallThroughTrampoline(CallSite CS, |
| 219 | IntrinsicInst *Tramp); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 220 | Instruction *transformZExtICmp(ICmpInst *ICI, Instruction &CI, |
| 221 | bool DoXform = true); |
Benjamin Kramer | 0a30c42 | 2011-04-01 20:09:03 +0000 | [diff] [blame] | 222 | Instruction *transformSExtICmp(ICmpInst *ICI, Instruction &CI); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 223 | bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS); |
Chris Lattner | 02446fc | 2010-01-04 07:37:31 +0000 | [diff] [blame] | 224 | Value *EmitGEPOffset(User *GEP); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 225 | |
| 226 | public: |
| 227 | // InsertNewInstBefore - insert an instruction New before instruction Old |
| 228 | // in the program. Add the new instruction to the worklist. |
| 229 | // |
| 230 | Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) { |
| 231 | assert(New && New->getParent() == 0 && |
| 232 | "New instruction already inserted into a basic block!"); |
| 233 | BasicBlock *BB = Old.getParent(); |
| 234 | BB->getInstList().insert(&Old, New); // Insert inst |
| 235 | Worklist.Add(New); |
| 236 | return New; |
| 237 | } |
Eli Friedman | 6fd5a60 | 2011-05-19 01:20:42 +0000 | [diff] [blame] | 238 | |
| 239 | // InsertNewInstWith - same as InsertNewInstBefore, but also sets the |
| 240 | // debug loc. |
| 241 | // |
| 242 | Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) { |
| 243 | New->setDebugLoc(Old.getDebugLoc()); |
| 244 | return InsertNewInstBefore(New, Old); |
| 245 | } |
| 246 | |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 247 | // ReplaceInstUsesWith - This method is to be used when an instruction is |
| 248 | // found to be dead, replacable with another preexisting expression. Here |
| 249 | // we add all uses of I to the worklist, replace all uses of I with the new |
| 250 | // value, then return I, so that the inst combiner will know that I was |
| 251 | // modified. |
| 252 | // |
| 253 | Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) { |
| 254 | Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist. |
| 255 | |
| 256 | // If we are replacing the instruction with itself, this must be in a |
| 257 | // segment of unreachable code, so just clobber the instruction. |
| 258 | if (&I == V) |
| 259 | V = UndefValue::get(I.getType()); |
Frits van Bommel | f56762a | 2011-03-27 23:32:31 +0000 | [diff] [blame] | 260 | |
| 261 | DEBUG(errs() << "IC: Replacing " << I << "\n" |
| 262 | " with " << *V << '\n'); |
| 263 | |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 264 | I.replaceAllUsesWith(V); |
| 265 | return &I; |
| 266 | } |
| 267 | |
| 268 | // EraseInstFromFunction - When dealing with an instruction that has side |
| 269 | // effects or produces a void value, we can't rely on DCE to delete the |
| 270 | // instruction. Instead, visit methods should return the value returned by |
| 271 | // this function. |
| 272 | Instruction *EraseInstFromFunction(Instruction &I) { |
| 273 | DEBUG(errs() << "IC: ERASE " << I << '\n'); |
| 274 | |
| 275 | assert(I.use_empty() && "Cannot erase instruction that is used!"); |
| 276 | // Make sure that we reprocess all operands now that we reduced their |
| 277 | // use counts. |
| 278 | if (I.getNumOperands() < 8) { |
| 279 | for (User::op_iterator i = I.op_begin(), e = I.op_end(); i != e; ++i) |
| 280 | if (Instruction *Op = dyn_cast<Instruction>(*i)) |
| 281 | Worklist.Add(Op); |
| 282 | } |
| 283 | Worklist.Remove(&I); |
| 284 | I.eraseFromParent(); |
| 285 | MadeIRChange = true; |
| 286 | return 0; // Don't do anything with FI |
| 287 | } |
| 288 | |
| 289 | void ComputeMaskedBits(Value *V, const APInt &Mask, APInt &KnownZero, |
| 290 | APInt &KnownOne, unsigned Depth = 0) const { |
| 291 | return llvm::ComputeMaskedBits(V, Mask, KnownZero, KnownOne, TD, Depth); |
| 292 | } |
| 293 | |
| 294 | bool MaskedValueIsZero(Value *V, const APInt &Mask, |
| 295 | unsigned Depth = 0) const { |
| 296 | return llvm::MaskedValueIsZero(V, Mask, TD, Depth); |
| 297 | } |
| 298 | unsigned ComputeNumSignBits(Value *Op, unsigned Depth = 0) const { |
| 299 | return llvm::ComputeNumSignBits(Op, TD, Depth); |
| 300 | } |
| 301 | |
| 302 | private: |
| 303 | |
Duncan Sands | 096aa79 | 2010-11-13 15:10:37 +0000 | [diff] [blame] | 304 | /// SimplifyAssociativeOrCommutative - This performs a few simplifications for |
| 305 | /// operators which are associative or commutative. |
| 306 | bool SimplifyAssociativeOrCommutative(BinaryOperator &I); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 307 | |
Duncan Sands | 37bf92b | 2010-12-22 13:36:08 +0000 | [diff] [blame] | 308 | /// SimplifyUsingDistributiveLaws - This tries to simplify binary operations |
| 309 | /// which some other binary operation distributes over either by factorizing |
| 310 | /// out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this |
| 311 | /// results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is |
| 312 | /// a win). Returns the simplified value, or null if it didn't simplify. |
| 313 | Value *SimplifyUsingDistributiveLaws(BinaryOperator &I); |
Duncan Sands | 5057f38 | 2010-11-23 14:23:47 +0000 | [diff] [blame] | 314 | |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 315 | /// SimplifyDemandedUseBits - Attempts to replace V with a simpler value |
| 316 | /// based on the demanded bits. |
| 317 | Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, |
| 318 | APInt& KnownZero, APInt& KnownOne, |
| 319 | unsigned Depth); |
| 320 | bool SimplifyDemandedBits(Use &U, APInt DemandedMask, |
| 321 | APInt& KnownZero, APInt& KnownOne, |
| 322 | unsigned Depth=0); |
| 323 | |
| 324 | /// SimplifyDemandedInstructionBits - Inst is an integer instruction that |
| 325 | /// SimplifyDemandedBits knows about. See if the instruction has any |
| 326 | /// properties that allow us to simplify its operands. |
| 327 | bool SimplifyDemandedInstructionBits(Instruction &Inst); |
| 328 | |
| 329 | Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, |
| 330 | APInt& UndefElts, unsigned Depth = 0); |
| 331 | |
| 332 | // FoldOpIntoPhi - Given a binary operator, cast instruction, or select |
| 333 | // which has a PHI node as operand #0, see if we can fold the instruction |
| 334 | // into the PHI (which is only possible if all operands to the PHI are |
| 335 | // constants). |
| 336 | // |
Chris Lattner | 9922ccf | 2011-01-16 05:14:26 +0000 | [diff] [blame] | 337 | Instruction *FoldOpIntoPhi(Instruction &I); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 338 | |
| 339 | // FoldPHIArgOpIntoPHI - If all operands to a PHI node are the same "unary" |
| 340 | // operator and they all are only used by the PHI, PHI together their |
| 341 | // inputs, and do the operation once, to the result of the PHI. |
| 342 | Instruction *FoldPHIArgOpIntoPHI(PHINode &PN); |
| 343 | Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN); |
| 344 | Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN); |
| 345 | Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN); |
| 346 | |
| 347 | |
| 348 | Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS, |
| 349 | ConstantInt *AndRHS, BinaryOperator &TheAnd); |
| 350 | |
| 351 | Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask, |
| 352 | bool isSub, Instruction &I); |
Chris Lattner | f34f48c | 2010-03-05 08:46:26 +0000 | [diff] [blame] | 353 | Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi, |
| 354 | bool isSigned, bool Inside); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 355 | Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI); |
| 356 | Instruction *MatchBSwap(BinaryOperator &I); |
| 357 | bool SimplifyStoreAtEndOfBlock(StoreInst &SI); |
| 358 | Instruction *SimplifyMemTransfer(MemIntrinsic *MI); |
| 359 | Instruction *SimplifyMemSet(MemSetInst *MI); |
| 360 | |
| 361 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 362 | Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned); |
Chris Lattner | ac8f2fd | 2010-01-04 07:12:23 +0000 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | |
| 366 | |
| 367 | } // end namespace llvm. |
| 368 | |
| 369 | #endif |