blob: d035c53f744b4e017bec70ffa2937c270b6836aa [file] [log] [blame]
Matt Arsenault52ddb7b2013-05-17 21:43:39 +00001//===- InstCombine.h - Main InstCombine pass definition ---------*- C++ -*-===//
Chris Lattner35522b72010-01-04 07:12:23 +00002//
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"
Chandler Carruth802d7552012-12-04 07:12:27 +000014#include "llvm/Analysis/ValueTracking.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000015#include "llvm/IR/IRBuilder.h"
16#include "llvm/IR/IntrinsicInst.h"
17#include "llvm/IR/Operator.h"
Chandler Carruthdbd69582012-11-30 03:08:41 +000018#include "llvm/InstVisitor.h"
Chris Lattner35522b72010-01-04 07:12:23 +000019#include "llvm/Pass.h"
Chris Lattner35522b72010-01-04 07:12:23 +000020#include "llvm/Support/TargetFolder.h"
Meador Ingedf796f82012-10-13 16:45:24 +000021#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
Chris Lattner35522b72010-01-04 07:12:23 +000022
23namespace llvm {
24 class CallSite;
Micah Villmowcdfe20b2012-10-08 16:38:25 +000025 class DataLayout;
Chad Rosiere6de63d2011-12-01 21:29:16 +000026 class TargetLibraryInfo;
Chris Lattner27acfcd2010-01-05 05:21:26 +000027 class DbgDeclareInst;
28 class MemIntrinsic;
29 class MemSetInst;
Jakub Staszak190db2f2013-01-14 23:16:36 +000030
Chris Lattner35522b72010-01-04 07:12:23 +000031/// SelectPatternFlavor - We can match a variety of different patterns for
32/// select operations.
33enum SelectPatternFlavor {
34 SPF_UNKNOWN = 0,
35 SPF_SMIN, SPF_UMIN,
36 SPF_SMAX, SPF_UMAX
37 //SPF_ABS - TODO.
38};
Jakub Staszak190db2f2013-01-14 23:16:36 +000039
Chris Lattner2188e402010-01-04 07:37:31 +000040/// getComplexity: Assign a complexity or rank value to LLVM Values...
41/// 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
42static inline unsigned getComplexity(Value *V) {
43 if (isa<Instruction>(V)) {
44 if (BinaryOperator::isNeg(V) ||
45 BinaryOperator::isFNeg(V) ||
46 BinaryOperator::isNot(V))
47 return 3;
48 return 4;
49 }
50 if (isa<Argument>(V)) return 3;
51 return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
52}
Chris Lattner35522b72010-01-04 07:12:23 +000053
Jakub Staszak190db2f2013-01-14 23:16:36 +000054
Chris Lattner35522b72010-01-04 07:12:23 +000055/// InstCombineIRInserter - This is an IRBuilder insertion helper that works
56/// just like the normal insertion helper, but also adds any new instructions
57/// to the instcombine worklist.
Jakub Staszak190db2f2013-01-14 23:16:36 +000058class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter
Chris Lattner35522b72010-01-04 07:12:23 +000059 : public IRBuilderDefaultInserter<true> {
60 InstCombineWorklist &Worklist;
61public:
62 InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {}
Jakub Staszak190db2f2013-01-14 23:16:36 +000063
Chris Lattner35522b72010-01-04 07:12:23 +000064 void InsertHelper(Instruction *I, const Twine &Name,
65 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
66 IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt);
67 Worklist.Add(I);
68 }
69};
Jakub Staszak190db2f2013-01-14 23:16:36 +000070
Chris Lattner35522b72010-01-04 07:12:23 +000071/// InstCombiner - The -instcombine pass.
Duncan Sands6c5e4352010-05-11 20:16:09 +000072class LLVM_LIBRARY_VISIBILITY InstCombiner
Chris Lattner35522b72010-01-04 07:12:23 +000073 : public FunctionPass,
74 public InstVisitor<InstCombiner, Instruction*> {
Micah Villmowcdfe20b2012-10-08 16:38:25 +000075 DataLayout *TD;
Chad Rosiere6de63d2011-12-01 21:29:16 +000076 TargetLibraryInfo *TLI;
Chris Lattner35522b72010-01-04 07:12:23 +000077 bool MadeIRChange;
Meador Ingedf796f82012-10-13 16:45:24 +000078 LibCallSimplifier *Simplifier;
Quentin Colombet3b2db0b2013-01-07 18:37:41 +000079 bool MinimizeSize;
Chris Lattner35522b72010-01-04 07:12:23 +000080public:
81 /// Worklist - All of the instructions that need to be simplified.
82 InstCombineWorklist Worklist;
83
84 /// Builder - This is an IRBuilder that automatically inserts new
85 /// instructions into the worklist when they are created.
86 typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy;
87 BuilderTy *Builder;
Jakub Staszak190db2f2013-01-14 23:16:36 +000088
Chris Lattner35522b72010-01-04 07:12:23 +000089 static char ID; // Pass identification, replacement for typeid
Owen Anderson6c18d1a2010-10-19 17:21:58 +000090 InstCombiner() : FunctionPass(ID), TD(0), Builder(0) {
Quentin Colombet3b2db0b2013-01-07 18:37:41 +000091 MinimizeSize = false;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000092 initializeInstCombinerPass(*PassRegistry::getPassRegistry());
93 }
Chris Lattner35522b72010-01-04 07:12:23 +000094
95public:
96 virtual bool runOnFunction(Function &F);
Jakub Staszak190db2f2013-01-14 23:16:36 +000097
Chris Lattner35522b72010-01-04 07:12:23 +000098 bool DoOneIteration(Function &F, unsigned ItNum);
99
Chris Lattner7e044912010-01-04 07:17:19 +0000100 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
Chad Rosiere6de63d2011-12-01 21:29:16 +0000101
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000102 DataLayout *getDataLayout() const { return TD; }
Chris Lattner35522b72010-01-04 07:12:23 +0000103
Chad Rosier43a33062011-12-02 01:26:24 +0000104 TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; }
105
Chris Lattner35522b72010-01-04 07:12:23 +0000106 // Visitation implementation - Implement instruction combining for different
107 // instruction types. The semantics are as follows:
108 // Return Value:
109 // null - No change was made
110 // I - Change was made, I is still valid, I may be dead though
111 // otherwise - Change was made, replace I with returned instruction
112 //
113 Instruction *visitAdd(BinaryOperator &I);
114 Instruction *visitFAdd(BinaryOperator &I);
Chris Lattner229907c2011-07-18 04:54:35 +0000115 Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty);
Chris Lattner35522b72010-01-04 07:12:23 +0000116 Instruction *visitSub(BinaryOperator &I);
117 Instruction *visitFSub(BinaryOperator &I);
118 Instruction *visitMul(BinaryOperator &I);
Shuxin Yangdf0e61e2013-01-07 21:39:23 +0000119 Value *foldFMulConst(Instruction *FMulOrDiv, ConstantFP *C,
120 Instruction *InsertBefore);
Chris Lattner35522b72010-01-04 07:12:23 +0000121 Instruction *visitFMul(BinaryOperator &I);
122 Instruction *visitURem(BinaryOperator &I);
123 Instruction *visitSRem(BinaryOperator &I);
124 Instruction *visitFRem(BinaryOperator &I);
125 bool SimplifyDivRemOfSelect(BinaryOperator &I);
126 Instruction *commonRemTransforms(BinaryOperator &I);
127 Instruction *commonIRemTransforms(BinaryOperator &I);
128 Instruction *commonDivTransforms(BinaryOperator &I);
129 Instruction *commonIDivTransforms(BinaryOperator &I);
130 Instruction *visitUDiv(BinaryOperator &I);
131 Instruction *visitSDiv(BinaryOperator &I);
Frits van Bommel2a559512011-01-29 17:50:27 +0000132 Instruction *visitFDiv(BinaryOperator &I);
Chris Lattner067459c2010-03-05 08:46:26 +0000133 Value *FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS);
134 Value *FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
Chris Lattner35522b72010-01-04 07:12:23 +0000135 Instruction *visitAnd(BinaryOperator &I);
Chris Lattner067459c2010-03-05 08:46:26 +0000136 Value *FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS);
137 Value *FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
Chris Lattner35522b72010-01-04 07:12:23 +0000138 Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op,
139 Value *A, Value *B, Value *C);
140 Instruction *visitOr (BinaryOperator &I);
141 Instruction *visitXor(BinaryOperator &I);
142 Instruction *visitShl(BinaryOperator &I);
143 Instruction *visitAShr(BinaryOperator &I);
144 Instruction *visitLShr(BinaryOperator &I);
145 Instruction *commonShiftTransforms(BinaryOperator &I);
146 Instruction *FoldFCmp_IntToFP_Cst(FCmpInst &I, Instruction *LHSI,
147 Constant *RHSC);
148 Instruction *FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP,
149 GlobalVariable *GV, CmpInst &ICI,
150 ConstantInt *AndCst = 0);
151 Instruction *visitFCmpInst(FCmpInst &I);
152 Instruction *visitICmpInst(ICmpInst &I);
153 Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI);
154 Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
155 Instruction *LHS,
156 ConstantInt *RHS);
157 Instruction *FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
158 ConstantInt *DivRHS);
Chris Lattnerd369f572011-02-13 07:43:07 +0000159 Instruction *FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *DivI,
160 ConstantInt *DivRHS);
Chris Lattner35522b72010-01-04 07:12:23 +0000161 Instruction *FoldICmpAddOpCst(ICmpInst &ICI, Value *X, ConstantInt *CI,
162 ICmpInst::Predicate Pred, Value *TheAdd);
163 Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
164 ICmpInst::Predicate Cond, Instruction &I);
165 Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
166 BinaryOperator &I);
167 Instruction *commonCastTransforms(CastInst &CI);
Chris Lattner35522b72010-01-04 07:12:23 +0000168 Instruction *commonPointerCastTransforms(CastInst &CI);
169 Instruction *visitTrunc(TruncInst &CI);
170 Instruction *visitZExt(ZExtInst &CI);
171 Instruction *visitSExt(SExtInst &CI);
172 Instruction *visitFPTrunc(FPTruncInst &CI);
173 Instruction *visitFPExt(CastInst &CI);
174 Instruction *visitFPToUI(FPToUIInst &FI);
175 Instruction *visitFPToSI(FPToSIInst &FI);
176 Instruction *visitUIToFP(CastInst &CI);
177 Instruction *visitSIToFP(CastInst &CI);
178 Instruction *visitPtrToInt(PtrToIntInst &CI);
179 Instruction *visitIntToPtr(IntToPtrInst &CI);
180 Instruction *visitBitCast(BitCastInst &CI);
181 Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI,
182 Instruction *FI);
183 Instruction *FoldSelectIntoOp(SelectInst &SI, Value*, Value*);
184 Instruction *FoldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1,
185 Value *A, Value *B, Instruction &Outer,
186 SelectPatternFlavor SPF2, Value *C);
187 Instruction *visitSelectInst(SelectInst &SI);
188 Instruction *visitSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI);
189 Instruction *visitCallInst(CallInst &CI);
190 Instruction *visitInvokeInst(InvokeInst &II);
191
192 Instruction *SliceUpIllegalIntegerPHI(PHINode &PN);
193 Instruction *visitPHINode(PHINode &PN);
194 Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
195 Instruction *visitAllocaInst(AllocaInst &AI);
Nuno Lopes95cc4f32012-07-09 18:38:20 +0000196 Instruction *visitAllocSite(Instruction &FI);
Gabor Greif75f69432010-06-24 12:21:15 +0000197 Instruction *visitFree(CallInst &FI);
Chris Lattner35522b72010-01-04 07:12:23 +0000198 Instruction *visitLoadInst(LoadInst &LI);
199 Instruction *visitStoreInst(StoreInst &SI);
200 Instruction *visitBranchInst(BranchInst &BI);
201 Instruction *visitSwitchInst(SwitchInst &SI);
202 Instruction *visitInsertElementInst(InsertElementInst &IE);
203 Instruction *visitExtractElementInst(ExtractElementInst &EI);
204 Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI);
205 Instruction *visitExtractValueInst(ExtractValueInst &EV);
Duncan Sands5c055792011-09-30 13:12:16 +0000206 Instruction *visitLandingPadInst(LandingPadInst &LI);
Chris Lattner35522b72010-01-04 07:12:23 +0000207
208 // visitInstruction - Specify what to return for unhandled instructions...
209 Instruction *visitInstruction(Instruction &I) { return 0; }
210
211private:
Chris Lattner229907c2011-07-18 04:54:35 +0000212 bool ShouldChangeType(Type *From, Type *To) const;
Chris Lattner2188e402010-01-04 07:37:31 +0000213 Value *dyn_castNegVal(Value *V) const;
Shuxin Yangf0537ab2013-01-09 00:13:41 +0000214 Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
Matt Arsenaultd79f7d92013-08-19 22:17:40 +0000215 Type *FindElementAtOffset(Type *PtrTy, int64_t Offset,
216 SmallVectorImpl<Value*> &NewIndices);
Chris Lattner2b295a02010-01-04 07:53:58 +0000217 Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000218
Chris Lattner4e8137d2010-02-11 06:26:33 +0000219 /// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually
220 /// results in any code being generated and is interesting to optimize out. If
221 /// the cast can be eliminated by some other simple transformation, we prefer
222 /// to do the simplification first.
223 bool ShouldOptimizeCast(Instruction::CastOps opcode,const Value *V,
Chris Lattner229907c2011-07-18 04:54:35 +0000224 Type *Ty);
Chris Lattner2188e402010-01-04 07:37:31 +0000225
Chris Lattner35522b72010-01-04 07:12:23 +0000226 Instruction *visitCallSite(CallSite CS);
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000227 Instruction *tryOptimizeCall(CallInst *CI, const DataLayout *TD);
Chris Lattner35522b72010-01-04 07:12:23 +0000228 bool transformConstExprCastCall(CallSite CS);
Duncan Sandsa0984362011-09-06 13:37:06 +0000229 Instruction *transformCallThroughTrampoline(CallSite CS,
230 IntrinsicInst *Tramp);
Chris Lattner35522b72010-01-04 07:12:23 +0000231 Instruction *transformZExtICmp(ICmpInst *ICI, Instruction &CI,
232 bool DoXform = true);
Benjamin Kramer398b8c52011-04-01 20:09:03 +0000233 Instruction *transformSExtICmp(ICmpInst *ICI, Instruction &CI);
Chris Lattner35522b72010-01-04 07:12:23 +0000234 bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS);
Nuno Lopesa2f6cec2012-05-22 17:19:09 +0000235 Value *EmitGEPOffset(User *GEP);
Anat Shemer0c95efa2013-04-18 19:35:39 +0000236 Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN);
Nick Lewyckya2b77202013-05-31 00:59:42 +0000237 Value *EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask);
Chris Lattner35522b72010-01-04 07:12:23 +0000238
239public:
240 // InsertNewInstBefore - insert an instruction New before instruction Old
241 // in the program. Add the new instruction to the worklist.
242 //
243 Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) {
244 assert(New && New->getParent() == 0 &&
245 "New instruction already inserted into a basic block!");
246 BasicBlock *BB = Old.getParent();
247 BB->getInstList().insert(&Old, New); // Insert inst
248 Worklist.Add(New);
249 return New;
250 }
Eli Friedman6efb64e2011-05-19 01:20:42 +0000251
Jakub Staszak190db2f2013-01-14 23:16:36 +0000252 // InsertNewInstWith - same as InsertNewInstBefore, but also sets the
Eli Friedman6efb64e2011-05-19 01:20:42 +0000253 // debug loc.
254 //
255 Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) {
256 New->setDebugLoc(Old.getDebugLoc());
257 return InsertNewInstBefore(New, Old);
258 }
259
Chris Lattner35522b72010-01-04 07:12:23 +0000260 // ReplaceInstUsesWith - This method is to be used when an instruction is
261 // found to be dead, replacable with another preexisting expression. Here
262 // we add all uses of I to the worklist, replace all uses of I with the new
263 // value, then return I, so that the inst combiner will know that I was
264 // modified.
265 //
266 Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
267 Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
Jakub Staszak190db2f2013-01-14 23:16:36 +0000268
Chris Lattner35522b72010-01-04 07:12:23 +0000269 // If we are replacing the instruction with itself, this must be in a
270 // segment of unreachable code, so just clobber the instruction.
Jakub Staszak190db2f2013-01-14 23:16:36 +0000271 if (&I == V)
Chris Lattner35522b72010-01-04 07:12:23 +0000272 V = UndefValue::get(I.getType());
Frits van Bommeld14d9912011-03-27 23:32:31 +0000273
274 DEBUG(errs() << "IC: Replacing " << I << "\n"
275 " with " << *V << '\n');
276
Chris Lattner35522b72010-01-04 07:12:23 +0000277 I.replaceAllUsesWith(V);
278 return &I;
279 }
280
281 // EraseInstFromFunction - When dealing with an instruction that has side
282 // effects or produces a void value, we can't rely on DCE to delete the
283 // instruction. Instead, visit methods should return the value returned by
284 // this function.
285 Instruction *EraseInstFromFunction(Instruction &I) {
286 DEBUG(errs() << "IC: ERASE " << I << '\n');
287
288 assert(I.use_empty() && "Cannot erase instruction that is used!");
289 // Make sure that we reprocess all operands now that we reduced their
290 // use counts.
291 if (I.getNumOperands() < 8) {
292 for (User::op_iterator i = I.op_begin(), e = I.op_end(); i != e; ++i)
293 if (Instruction *Op = dyn_cast<Instruction>(*i))
294 Worklist.Add(Op);
295 }
296 Worklist.Remove(&I);
297 I.eraseFromParent();
298 MadeIRChange = true;
299 return 0; // Don't do anything with FI
300 }
Jakub Staszak190db2f2013-01-14 23:16:36 +0000301
Rafael Espindolaba0a6ca2012-04-04 12:51:34 +0000302 void ComputeMaskedBits(Value *V, APInt &KnownZero,
Chris Lattner35522b72010-01-04 07:12:23 +0000303 APInt &KnownOne, unsigned Depth = 0) const {
Rafael Espindolaba0a6ca2012-04-04 12:51:34 +0000304 return llvm::ComputeMaskedBits(V, KnownZero, KnownOne, TD, Depth);
Chris Lattner35522b72010-01-04 07:12:23 +0000305 }
Jakub Staszak190db2f2013-01-14 23:16:36 +0000306
307 bool MaskedValueIsZero(Value *V, const APInt &Mask,
Chris Lattner35522b72010-01-04 07:12:23 +0000308 unsigned Depth = 0) const {
309 return llvm::MaskedValueIsZero(V, Mask, TD, Depth);
310 }
311 unsigned ComputeNumSignBits(Value *Op, unsigned Depth = 0) const {
312 return llvm::ComputeNumSignBits(Op, TD, Depth);
313 }
314
315private:
316
Duncan Sands641baf12010-11-13 15:10:37 +0000317 /// SimplifyAssociativeOrCommutative - This performs a few simplifications for
318 /// operators which are associative or commutative.
319 bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
Chris Lattner35522b72010-01-04 07:12:23 +0000320
Duncan Sandsfbb9ac32010-12-22 13:36:08 +0000321 /// SimplifyUsingDistributiveLaws - This tries to simplify binary operations
322 /// which some other binary operation distributes over either by factorizing
323 /// out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this
324 /// results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is
325 /// a win). Returns the simplified value, or null if it didn't simplify.
326 Value *SimplifyUsingDistributiveLaws(BinaryOperator &I);
Duncan Sandsadc7771f2010-11-23 14:23:47 +0000327
Chris Lattner35522b72010-01-04 07:12:23 +0000328 /// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
329 /// based on the demanded bits.
Jakub Staszak190db2f2013-01-14 23:16:36 +0000330 Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
Chris Lattner35522b72010-01-04 07:12:23 +0000331 APInt& KnownZero, APInt& KnownOne,
332 unsigned Depth);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000333 bool SimplifyDemandedBits(Use &U, APInt DemandedMask,
Chris Lattner35522b72010-01-04 07:12:23 +0000334 APInt& KnownZero, APInt& KnownOne,
335 unsigned Depth=0);
Shuxin Yang63e999e2012-12-04 00:04:54 +0000336 /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
337 /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
338 Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl,
339 APInt DemandedMask, APInt &KnownZero,
340 APInt &KnownOne);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000341
Chris Lattner35522b72010-01-04 07:12:23 +0000342 /// SimplifyDemandedInstructionBits - Inst is an integer instruction that
343 /// SimplifyDemandedBits knows about. See if the instruction has any
344 /// properties that allow us to simplify its operands.
345 bool SimplifyDemandedInstructionBits(Instruction &Inst);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000346
Chris Lattner35522b72010-01-04 07:12:23 +0000347 Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
348 APInt& UndefElts, unsigned Depth = 0);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000349
Chris Lattner35522b72010-01-04 07:12:23 +0000350 // FoldOpIntoPhi - Given a binary operator, cast instruction, or select
351 // which has a PHI node as operand #0, see if we can fold the instruction
352 // into the PHI (which is only possible if all operands to the PHI are
353 // constants).
354 //
Chris Lattnerea7131a2011-01-16 05:14:26 +0000355 Instruction *FoldOpIntoPhi(Instruction &I);
Chris Lattner35522b72010-01-04 07:12:23 +0000356
357 // FoldPHIArgOpIntoPHI - If all operands to a PHI node are the same "unary"
358 // operator and they all are only used by the PHI, PHI together their
359 // inputs, and do the operation once, to the result of the PHI.
360 Instruction *FoldPHIArgOpIntoPHI(PHINode &PN);
361 Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN);
362 Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
363 Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
364
Jakub Staszak190db2f2013-01-14 23:16:36 +0000365
Chris Lattner35522b72010-01-04 07:12:23 +0000366 Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
367 ConstantInt *AndRHS, BinaryOperator &TheAnd);
Jakub Staszak190db2f2013-01-14 23:16:36 +0000368
Chris Lattner35522b72010-01-04 07:12:23 +0000369 Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
370 bool isSub, Instruction &I);
Chris Lattner067459c2010-03-05 08:46:26 +0000371 Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
372 bool isSigned, bool Inside);
Chris Lattner35522b72010-01-04 07:12:23 +0000373 Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI);
374 Instruction *MatchBSwap(BinaryOperator &I);
375 bool SimplifyStoreAtEndOfBlock(StoreInst &SI);
376 Instruction *SimplifyMemTransfer(MemIntrinsic *MI);
377 Instruction *SimplifyMemSet(MemSetInst *MI);
378
379
Chris Lattner229907c2011-07-18 04:54:35 +0000380 Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
Duncan Sands533c8ae2012-10-23 08:28:26 +0000381
382 /// Descale - Return a value X such that Val = X * Scale, or null if none. If
383 /// the multiplication is known not to overflow then NoSignedWrap is set.
384 Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap);
Chris Lattner35522b72010-01-04 07:12:23 +0000385};
386
Jakub Staszak190db2f2013-01-14 23:16:36 +0000387
388
Chris Lattner35522b72010-01-04 07:12:23 +0000389} // end namespace llvm.
390
391#endif