1 //===-- InstructionSimplify.h - Fold instructions into simpler forms ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares routines for folding instructions into simpler forms
11 // that do not require creating new instructions. This does constant folding
12 // ("add i32 1, 1" -> "2") but can also handle non-constant operands, either
13 // returning a constant ("and i32 %x, 0" -> "0") or an already existing value
14 // ("and i32 %x, %x" -> "%x").
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
19 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
27 /// SimplifyAddInst - Given operands for an Add, see if we can
28 /// fold the result. If not, this returns null.
29 Value *SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
30 const TargetData *TD = 0, const DominatorTree *DT = 0);
32 /// SimplifySubInst - Given operands for a Sub, see if we can
33 /// fold the result. If not, this returns null.
34 Value *SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
35 const TargetData *TD = 0, const DominatorTree *DT = 0);
37 /// SimplifyAndInst - Given operands for an And, see if we can
38 /// fold the result. If not, this returns null.
39 Value *SimplifyAndInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
40 const DominatorTree *DT = 0);
42 /// SimplifyMulInst - Given operands for a Mul, see if we can
43 /// fold the result. If not, this returns null.
44 Value *SimplifyMulInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
45 const DominatorTree *DT = 0);
47 /// SimplifyOrInst - Given operands for an Or, see if we can
48 /// fold the result. If not, this returns null.
49 Value *SimplifyOrInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
50 const DominatorTree *DT = 0);
52 /// SimplifyXorInst - Given operands for a Xor, see if we can
53 /// fold the result. If not, this returns null.
54 Value *SimplifyXorInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
55 const DominatorTree *DT = 0);
57 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
58 /// fold the result. If not, this returns null.
59 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
60 const TargetData *TD = 0,
61 const DominatorTree *DT = 0);
63 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
64 /// fold the result. If not, this returns null.
65 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
66 const TargetData *TD = 0,
67 const DominatorTree *DT = 0);
69 /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
70 /// the result. If not, this returns null.
71 Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
72 const TargetData *TD = 0,
73 const DominatorTree *DT = 0);
75 /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
76 /// fold the result. If not, this returns null.
77 Value *SimplifyGEPInst(Value * const *Ops, unsigned NumOps,
78 const TargetData *TD = 0, const DominatorTree *DT = 0);
80 //=== Helper functions for higher up the class hierarchy.
83 /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
84 /// fold the result. If not, this returns null.
85 Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
86 const TargetData *TD = 0, const DominatorTree *DT = 0);
88 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
89 /// fold the result. If not, this returns null.
90 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
91 const TargetData *TD = 0, const DominatorTree *DT = 0);
93 /// SimplifyInstruction - See if we can compute a simplified version of this
94 /// instruction. If not, this returns null.
95 Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0,
96 const DominatorTree *DT = 0);
99 /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then
100 /// delete the From instruction. In addition to a basic RAUW, this does a
101 /// recursive simplification of the updated instructions. This catches
102 /// things where one simplification exposes other opportunities. This only
103 /// simplifies and deletes scalar operations, it does not change the CFG.
105 void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
106 const TargetData *TD = 0,
107 const DominatorTree *DT = 0);
108 } // end namespace llvm