1263508Sdim//===- InstCombine.h - Main InstCombine pass definition ---------*- C++ -*-===//
2202375Srdivacky//
3202375Srdivacky//                     The LLVM Compiler Infrastructure
4202375Srdivacky//
5202375Srdivacky// This file is distributed under the University of Illinois Open Source
6202375Srdivacky// License. See LICENSE.TXT for details.
7202375Srdivacky//
8202375Srdivacky//===----------------------------------------------------------------------===//
9202375Srdivacky
10202375Srdivacky#ifndef INSTCOMBINE_INSTCOMBINE_H
11202375Srdivacky#define INSTCOMBINE_INSTCOMBINE_H
12202375Srdivacky
13202375Srdivacky#include "InstCombineWorklist.h"
14249423Sdim#include "llvm/Analysis/ValueTracking.h"
15249423Sdim#include "llvm/IR/IRBuilder.h"
16249423Sdim#include "llvm/IR/IntrinsicInst.h"
17249423Sdim#include "llvm/IR/Operator.h"
18249423Sdim#include "llvm/InstVisitor.h"
19202375Srdivacky#include "llvm/Pass.h"
20202375Srdivacky#include "llvm/Support/TargetFolder.h"
21243830Sdim#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
22202375Srdivacky
23202375Srdivackynamespace llvm {
24202375Srdivacky  class CallSite;
25243830Sdim  class DataLayout;
26234353Sdim  class TargetLibraryInfo;
27202375Srdivacky  class DbgDeclareInst;
28202375Srdivacky  class MemIntrinsic;
29202375Srdivacky  class MemSetInst;
30249423Sdim
31202375Srdivacky/// SelectPatternFlavor - We can match a variety of different patterns for
32202375Srdivacky/// select operations.
33202375Srdivackyenum SelectPatternFlavor {
34202375Srdivacky  SPF_UNKNOWN = 0,
35202375Srdivacky  SPF_SMIN, SPF_UMIN,
36202375Srdivacky  SPF_SMAX, SPF_UMAX
37202375Srdivacky  //SPF_ABS - TODO.
38202375Srdivacky};
39249423Sdim
40202375Srdivacky/// getComplexity:  Assign a complexity or rank value to LLVM Values...
41202375Srdivacky///   0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
42202375Srdivackystatic inline unsigned getComplexity(Value *V) {
43202375Srdivacky  if (isa<Instruction>(V)) {
44202375Srdivacky    if (BinaryOperator::isNeg(V) ||
45202375Srdivacky        BinaryOperator::isFNeg(V) ||
46202375Srdivacky        BinaryOperator::isNot(V))
47202375Srdivacky      return 3;
48202375Srdivacky    return 4;
49202375Srdivacky  }
50202375Srdivacky  if (isa<Argument>(V)) return 3;
51202375Srdivacky  return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
52202375Srdivacky}
53202375Srdivacky
54249423Sdim
55202375Srdivacky/// InstCombineIRInserter - This is an IRBuilder insertion helper that works
56202375Srdivacky/// just like the normal insertion helper, but also adds any new instructions
57202375Srdivacky/// to the instcombine worklist.
58249423Sdimclass LLVM_LIBRARY_VISIBILITY InstCombineIRInserter
59202375Srdivacky    : public IRBuilderDefaultInserter<true> {
60202375Srdivacky  InstCombineWorklist &Worklist;
61202375Srdivackypublic:
62202375Srdivacky  InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {}
63249423Sdim
64202375Srdivacky  void InsertHelper(Instruction *I, const Twine &Name,
65202375Srdivacky                    BasicBlock *BB, BasicBlock::iterator InsertPt) const {
66202375Srdivacky    IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt);
67202375Srdivacky    Worklist.Add(I);
68202375Srdivacky  }
69202375Srdivacky};
70249423Sdim
71202375Srdivacky/// InstCombiner - The -instcombine pass.
72208599Srdivackyclass LLVM_LIBRARY_VISIBILITY InstCombiner
73202375Srdivacky                             : public FunctionPass,
74202375Srdivacky                               public InstVisitor<InstCombiner, Instruction*> {
75243830Sdim  DataLayout *TD;
76234353Sdim  TargetLibraryInfo *TLI;
77202375Srdivacky  bool MadeIRChange;
78243830Sdim  LibCallSimplifier *Simplifier;
79249423Sdim  bool MinimizeSize;
80202375Srdivackypublic:
81202375Srdivacky  /// Worklist - All of the instructions that need to be simplified.
82202375Srdivacky  InstCombineWorklist Worklist;
83202375Srdivacky
84202375Srdivacky  /// Builder - This is an IRBuilder that automatically inserts new
85202375Srdivacky  /// instructions into the worklist when they are created.
86202375Srdivacky  typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy;
87202375Srdivacky  BuilderTy *Builder;
88249423Sdim
89202375Srdivacky  static char ID; // Pass identification, replacement for typeid
90218893Sdim  InstCombiner() : FunctionPass(ID), TD(0), Builder(0) {
91249423Sdim    MinimizeSize = false;
92218893Sdim    initializeInstCombinerPass(*PassRegistry::getPassRegistry());
93218893Sdim  }
94202375Srdivacky
95202375Srdivackypublic:
96202375Srdivacky  virtual bool runOnFunction(Function &F);
97249423Sdim
98202375Srdivacky  bool DoOneIteration(Function &F, unsigned ItNum);
99202375Srdivacky
100202375Srdivacky  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
101234353Sdim
102243830Sdim  DataLayout *getDataLayout() const { return TD; }
103202375Srdivacky
104234353Sdim  TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; }
105234353Sdim
106202375Srdivacky  // Visitation implementation - Implement instruction combining for different
107202375Srdivacky  // instruction types.  The semantics are as follows:
108202375Srdivacky  // Return Value:
109202375Srdivacky  //    null        - No change was made
110202375Srdivacky  //     I          - Change was made, I is still valid, I may be dead though
111202375Srdivacky  //   otherwise    - Change was made, replace I with returned instruction
112202375Srdivacky  //
113202375Srdivacky  Instruction *visitAdd(BinaryOperator &I);
114202375Srdivacky  Instruction *visitFAdd(BinaryOperator &I);
115226633Sdim  Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty);
116202375Srdivacky  Instruction *visitSub(BinaryOperator &I);
117202375Srdivacky  Instruction *visitFSub(BinaryOperator &I);
118202375Srdivacky  Instruction *visitMul(BinaryOperator &I);
119249423Sdim  Value *foldFMulConst(Instruction *FMulOrDiv, ConstantFP *C,
120249423Sdim                       Instruction *InsertBefore);
121202375Srdivacky  Instruction *visitFMul(BinaryOperator &I);
122202375Srdivacky  Instruction *visitURem(BinaryOperator &I);
123202375Srdivacky  Instruction *visitSRem(BinaryOperator &I);
124202375Srdivacky  Instruction *visitFRem(BinaryOperator &I);
125202375Srdivacky  bool SimplifyDivRemOfSelect(BinaryOperator &I);
126202375Srdivacky  Instruction *commonRemTransforms(BinaryOperator &I);
127202375Srdivacky  Instruction *commonIRemTransforms(BinaryOperator &I);
128202375Srdivacky  Instruction *commonDivTransforms(BinaryOperator &I);
129202375Srdivacky  Instruction *commonIDivTransforms(BinaryOperator &I);
130202375Srdivacky  Instruction *visitUDiv(BinaryOperator &I);
131202375Srdivacky  Instruction *visitSDiv(BinaryOperator &I);
132202375Srdivacky  Instruction *visitFDiv(BinaryOperator &I);
133204792Srdivacky  Value *FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS);
134204792Srdivacky  Value *FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
135202375Srdivacky  Instruction *visitAnd(BinaryOperator &I);
136204792Srdivacky  Value *FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS);
137204792Srdivacky  Value *FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
138202375Srdivacky  Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op,
139202375Srdivacky                                   Value *A, Value *B, Value *C);
140202375Srdivacky  Instruction *visitOr (BinaryOperator &I);
141202375Srdivacky  Instruction *visitXor(BinaryOperator &I);
142202375Srdivacky  Instruction *visitShl(BinaryOperator &I);
143202375Srdivacky  Instruction *visitAShr(BinaryOperator &I);
144202375Srdivacky  Instruction *visitLShr(BinaryOperator &I);
145202375Srdivacky  Instruction *commonShiftTransforms(BinaryOperator &I);
146202375Srdivacky  Instruction *FoldFCmp_IntToFP_Cst(FCmpInst &I, Instruction *LHSI,
147202375Srdivacky                                    Constant *RHSC);
148202375Srdivacky  Instruction *FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP,
149202375Srdivacky                                            GlobalVariable *GV, CmpInst &ICI,
150202375Srdivacky                                            ConstantInt *AndCst = 0);
151202375Srdivacky  Instruction *visitFCmpInst(FCmpInst &I);
152202375Srdivacky  Instruction *visitICmpInst(ICmpInst &I);
153202375Srdivacky  Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI);
154202375Srdivacky  Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
155202375Srdivacky                                              Instruction *LHS,
156202375Srdivacky                                              ConstantInt *RHS);
157202375Srdivacky  Instruction *FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
158202375Srdivacky                              ConstantInt *DivRHS);
159218893Sdim  Instruction *FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *DivI,
160218893Sdim                              ConstantInt *DivRHS);
161263508Sdim  Instruction *FoldICmpAddOpCst(Instruction &ICI, Value *X, ConstantInt *CI,
162263508Sdim                                ICmpInst::Predicate Pred);
163202375Srdivacky  Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
164202375Srdivacky                           ICmpInst::Predicate Cond, Instruction &I);
165202375Srdivacky  Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
166202375Srdivacky                                   BinaryOperator &I);
167202375Srdivacky  Instruction *commonCastTransforms(CastInst &CI);
168202375Srdivacky  Instruction *commonPointerCastTransforms(CastInst &CI);
169202375Srdivacky  Instruction *visitTrunc(TruncInst &CI);
170202375Srdivacky  Instruction *visitZExt(ZExtInst &CI);
171202375Srdivacky  Instruction *visitSExt(SExtInst &CI);
172202375Srdivacky  Instruction *visitFPTrunc(FPTruncInst &CI);
173202375Srdivacky  Instruction *visitFPExt(CastInst &CI);
174202375Srdivacky  Instruction *visitFPToUI(FPToUIInst &FI);
175202375Srdivacky  Instruction *visitFPToSI(FPToSIInst &FI);
176202375Srdivacky  Instruction *visitUIToFP(CastInst &CI);
177202375Srdivacky  Instruction *visitSIToFP(CastInst &CI);
178202375Srdivacky  Instruction *visitPtrToInt(PtrToIntInst &CI);
179202375Srdivacky  Instruction *visitIntToPtr(IntToPtrInst &CI);
180202375Srdivacky  Instruction *visitBitCast(BitCastInst &CI);
181263508Sdim  Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI);
182202375Srdivacky  Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI,
183202375Srdivacky                              Instruction *FI);
184202375Srdivacky  Instruction *FoldSelectIntoOp(SelectInst &SI, Value*, Value*);
185202375Srdivacky  Instruction *FoldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1,
186202375Srdivacky                            Value *A, Value *B, Instruction &Outer,
187202375Srdivacky                            SelectPatternFlavor SPF2, Value *C);
188202375Srdivacky  Instruction *visitSelectInst(SelectInst &SI);
189202375Srdivacky  Instruction *visitSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI);
190202375Srdivacky  Instruction *visitCallInst(CallInst &CI);
191202375Srdivacky  Instruction *visitInvokeInst(InvokeInst &II);
192202375Srdivacky
193202375Srdivacky  Instruction *SliceUpIllegalIntegerPHI(PHINode &PN);
194202375Srdivacky  Instruction *visitPHINode(PHINode &PN);
195202375Srdivacky  Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
196202375Srdivacky  Instruction *visitAllocaInst(AllocaInst &AI);
197239462Sdim  Instruction *visitAllocSite(Instruction &FI);
198210299Sed  Instruction *visitFree(CallInst &FI);
199202375Srdivacky  Instruction *visitLoadInst(LoadInst &LI);
200202375Srdivacky  Instruction *visitStoreInst(StoreInst &SI);
201202375Srdivacky  Instruction *visitBranchInst(BranchInst &BI);
202202375Srdivacky  Instruction *visitSwitchInst(SwitchInst &SI);
203202375Srdivacky  Instruction *visitInsertElementInst(InsertElementInst &IE);
204202375Srdivacky  Instruction *visitExtractElementInst(ExtractElementInst &EI);
205202375Srdivacky  Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI);
206202375Srdivacky  Instruction *visitExtractValueInst(ExtractValueInst &EV);
207226633Sdim  Instruction *visitLandingPadInst(LandingPadInst &LI);
208202375Srdivacky
209202375Srdivacky  // visitInstruction - Specify what to return for unhandled instructions...
210202375Srdivacky  Instruction *visitInstruction(Instruction &I) { return 0; }
211202375Srdivacky
212202375Srdivackyprivate:
213226633Sdim  bool ShouldChangeType(Type *From, Type *To) const;
214202375Srdivacky  Value *dyn_castNegVal(Value *V) const;
215249423Sdim  Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
216263508Sdim  Type *FindElementAtOffset(Type *PtrTy, int64_t Offset,
217263508Sdim                            SmallVectorImpl<Value*> &NewIndices);
218202375Srdivacky  Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
219249423Sdim
220203954Srdivacky  /// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually
221203954Srdivacky  /// results in any code being generated and is interesting to optimize out. If
222203954Srdivacky  /// the cast can be eliminated by some other simple transformation, we prefer
223203954Srdivacky  /// to do the simplification first.
224203954Srdivacky  bool ShouldOptimizeCast(Instruction::CastOps opcode,const Value *V,
225226633Sdim                          Type *Ty);
226202375Srdivacky
227202375Srdivacky  Instruction *visitCallSite(CallSite CS);
228243830Sdim  Instruction *tryOptimizeCall(CallInst *CI, const DataLayout *TD);
229202375Srdivacky  bool transformConstExprCastCall(CallSite CS);
230226633Sdim  Instruction *transformCallThroughTrampoline(CallSite CS,
231226633Sdim                                              IntrinsicInst *Tramp);
232202375Srdivacky  Instruction *transformZExtICmp(ICmpInst *ICI, Instruction &CI,
233202375Srdivacky                                 bool DoXform = true);
234221345Sdim  Instruction *transformSExtICmp(ICmpInst *ICI, Instruction &CI);
235202375Srdivacky  bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS);
236202375Srdivacky  Value *EmitGEPOffset(User *GEP);
237251662Sdim  Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN);
238263508Sdim  Value *EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask);
239202375Srdivacky
240202375Srdivackypublic:
241202375Srdivacky  // InsertNewInstBefore - insert an instruction New before instruction Old
242202375Srdivacky  // in the program.  Add the new instruction to the worklist.
243202375Srdivacky  //
244202375Srdivacky  Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) {
245202375Srdivacky    assert(New && New->getParent() == 0 &&
246202375Srdivacky           "New instruction already inserted into a basic block!");
247202375Srdivacky    BasicBlock *BB = Old.getParent();
248202375Srdivacky    BB->getInstList().insert(&Old, New);  // Insert inst
249202375Srdivacky    Worklist.Add(New);
250202375Srdivacky    return New;
251202375Srdivacky  }
252223017Sdim
253249423Sdim  // InsertNewInstWith - same as InsertNewInstBefore, but also sets the
254223017Sdim  // debug loc.
255223017Sdim  //
256223017Sdim  Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) {
257223017Sdim    New->setDebugLoc(Old.getDebugLoc());
258223017Sdim    return InsertNewInstBefore(New, Old);
259223017Sdim  }
260223017Sdim
261202375Srdivacky  // ReplaceInstUsesWith - This method is to be used when an instruction is
262202375Srdivacky  // found to be dead, replacable with another preexisting expression.  Here
263202375Srdivacky  // we add all uses of I to the worklist, replace all uses of I with the new
264202375Srdivacky  // value, then return I, so that the inst combiner will know that I was
265202375Srdivacky  // modified.
266202375Srdivacky  //
267202375Srdivacky  Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
268202375Srdivacky    Worklist.AddUsersToWorkList(I);   // Add all modified instrs to worklist.
269249423Sdim
270202375Srdivacky    // If we are replacing the instruction with itself, this must be in a
271202375Srdivacky    // segment of unreachable code, so just clobber the instruction.
272249423Sdim    if (&I == V)
273202375Srdivacky      V = UndefValue::get(I.getType());
274221345Sdim
275263508Sdim    DEBUG(dbgs() << "IC: Replacing " << I << "\n"
276221345Sdim                    "    with " << *V << '\n');
277221345Sdim
278202375Srdivacky    I.replaceAllUsesWith(V);
279202375Srdivacky    return &I;
280202375Srdivacky  }
281202375Srdivacky
282202375Srdivacky  // EraseInstFromFunction - When dealing with an instruction that has side
283202375Srdivacky  // effects or produces a void value, we can't rely on DCE to delete the
284202375Srdivacky  // instruction.  Instead, visit methods should return the value returned by
285202375Srdivacky  // this function.
286202375Srdivacky  Instruction *EraseInstFromFunction(Instruction &I) {
287263508Sdim    DEBUG(dbgs() << "IC: ERASE " << I << '\n');
288202375Srdivacky
289202375Srdivacky    assert(I.use_empty() && "Cannot erase instruction that is used!");
290202375Srdivacky    // Make sure that we reprocess all operands now that we reduced their
291202375Srdivacky    // use counts.
292202375Srdivacky    if (I.getNumOperands() < 8) {
293202375Srdivacky      for (User::op_iterator i = I.op_begin(), e = I.op_end(); i != e; ++i)
294202375Srdivacky        if (Instruction *Op = dyn_cast<Instruction>(*i))
295202375Srdivacky          Worklist.Add(Op);
296202375Srdivacky    }
297202375Srdivacky    Worklist.Remove(&I);
298202375Srdivacky    I.eraseFromParent();
299202375Srdivacky    MadeIRChange = true;
300202375Srdivacky    return 0;  // Don't do anything with FI
301202375Srdivacky  }
302249423Sdim
303234353Sdim  void ComputeMaskedBits(Value *V, APInt &KnownZero,
304202375Srdivacky                         APInt &KnownOne, unsigned Depth = 0) const {
305234353Sdim    return llvm::ComputeMaskedBits(V, KnownZero, KnownOne, TD, Depth);
306202375Srdivacky  }
307249423Sdim
308249423Sdim  bool MaskedValueIsZero(Value *V, const APInt &Mask,
309202375Srdivacky                         unsigned Depth = 0) const {
310202375Srdivacky    return llvm::MaskedValueIsZero(V, Mask, TD, Depth);
311202375Srdivacky  }
312202375Srdivacky  unsigned ComputeNumSignBits(Value *Op, unsigned Depth = 0) const {
313202375Srdivacky    return llvm::ComputeNumSignBits(Op, TD, Depth);
314202375Srdivacky  }
315202375Srdivacky
316202375Srdivackyprivate:
317202375Srdivacky
318218893Sdim  /// SimplifyAssociativeOrCommutative - This performs a few simplifications for
319218893Sdim  /// operators which are associative or commutative.
320218893Sdim  bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
321202375Srdivacky
322218893Sdim  /// SimplifyUsingDistributiveLaws - This tries to simplify binary operations
323218893Sdim  /// which some other binary operation distributes over either by factorizing
324218893Sdim  /// out common terms (eg "(A*B)+(A*C)" -> "A*(B+C)") or expanding out if this
325218893Sdim  /// results in simplifications (eg: "A & (B | C) -> (A&B) | (A&C)" if this is
326218893Sdim  /// a win).  Returns the simplified value, or null if it didn't simplify.
327218893Sdim  Value *SimplifyUsingDistributiveLaws(BinaryOperator &I);
328218893Sdim
329202375Srdivacky  /// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
330202375Srdivacky  /// based on the demanded bits.
331249423Sdim  Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
332202375Srdivacky                                 APInt& KnownZero, APInt& KnownOne,
333202375Srdivacky                                 unsigned Depth);
334249423Sdim  bool SimplifyDemandedBits(Use &U, APInt DemandedMask,
335202375Srdivacky                            APInt& KnownZero, APInt& KnownOne,
336202375Srdivacky                            unsigned Depth=0);
337249423Sdim  /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
338249423Sdim  /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
339249423Sdim  Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl,
340249423Sdim                                    APInt DemandedMask, APInt &KnownZero,
341249423Sdim                                    APInt &KnownOne);
342249423Sdim
343202375Srdivacky  /// SimplifyDemandedInstructionBits - Inst is an integer instruction that
344202375Srdivacky  /// SimplifyDemandedBits knows about.  See if the instruction has any
345202375Srdivacky  /// properties that allow us to simplify its operands.
346202375Srdivacky  bool SimplifyDemandedInstructionBits(Instruction &Inst);
347249423Sdim
348202375Srdivacky  Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
349202375Srdivacky                                    APInt& UndefElts, unsigned Depth = 0);
350249423Sdim
351202375Srdivacky  // FoldOpIntoPhi - Given a binary operator, cast instruction, or select
352202375Srdivacky  // which has a PHI node as operand #0, see if we can fold the instruction
353202375Srdivacky  // into the PHI (which is only possible if all operands to the PHI are
354202375Srdivacky  // constants).
355202375Srdivacky  //
356218893Sdim  Instruction *FoldOpIntoPhi(Instruction &I);
357202375Srdivacky
358202375Srdivacky  // FoldPHIArgOpIntoPHI - If all operands to a PHI node are the same "unary"
359202375Srdivacky  // operator and they all are only used by the PHI, PHI together their
360202375Srdivacky  // inputs, and do the operation once, to the result of the PHI.
361202375Srdivacky  Instruction *FoldPHIArgOpIntoPHI(PHINode &PN);
362202375Srdivacky  Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN);
363202375Srdivacky  Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
364202375Srdivacky  Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
365202375Srdivacky
366249423Sdim
367202375Srdivacky  Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
368202375Srdivacky                        ConstantInt *AndRHS, BinaryOperator &TheAnd);
369249423Sdim
370202375Srdivacky  Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
371202375Srdivacky                            bool isSub, Instruction &I);
372204792Srdivacky  Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
373204792Srdivacky                         bool isSigned, bool Inside);
374202375Srdivacky  Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI);
375202375Srdivacky  Instruction *MatchBSwap(BinaryOperator &I);
376202375Srdivacky  bool SimplifyStoreAtEndOfBlock(StoreInst &SI);
377202375Srdivacky  Instruction *SimplifyMemTransfer(MemIntrinsic *MI);
378202375Srdivacky  Instruction *SimplifyMemSet(MemSetInst *MI);
379202375Srdivacky
380202375Srdivacky
381226633Sdim  Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
382243830Sdim
383243830Sdim  /// Descale - Return a value X such that Val = X * Scale, or null if none.  If
384243830Sdim  /// the multiplication is known not to overflow then NoSignedWrap is set.
385243830Sdim  Value *Descale(Value *Val, APInt Scale, bool &NoSignedWrap);
386202375Srdivacky};
387202375Srdivacky
388249423Sdim
389249423Sdim
390202375Srdivacky} // end namespace llvm.
391202375Srdivacky
392202375Srdivacky#endif
393