llvm.org GIT mirror llvm / 40b514d
Tidy up whitespace with clang-format prior to making significant changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208229 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
1 changed file(s) with 43 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
2222 #define DEBUG_TYPE "instcombine"
2323
2424 namespace llvm {
25 class CallSite;
26 class DataLayout;
27 class TargetLibraryInfo;
28 class DbgDeclareInst;
29 class MemIntrinsic;
30 class MemSetInst;
25 class CallSite;
26 class DataLayout;
27 class TargetLibraryInfo;
28 class DbgDeclareInst;
29 class MemIntrinsic;
30 class MemSetInst;
3131
3232 /// SelectPatternFlavor - We can match a variety of different patterns for
3333 /// select operations.
3434 enum SelectPatternFlavor {
3535 SPF_UNKNOWN = 0,
36 SPF_SMIN, SPF_UMIN,
37 SPF_SMAX, SPF_UMAX
38 //SPF_ABS - TODO.
36 SPF_SMIN,
37 SPF_UMIN,
38 SPF_SMAX,
39 SPF_UMAX
40 // SPF_ABS - TODO.
3941 };
4042
4143 /// getComplexity: Assign a complexity or rank value to LLVM Values...
4244 /// 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
4345 static inline unsigned getComplexity(Value *V) {
4446 if (isa(V)) {
45 if (BinaryOperator::isNeg(V) ||
46 BinaryOperator::isFNeg(V) ||
47 if (BinaryOperator::isNeg(V) || BinaryOperator::isFNeg(V) ||
4748 BinaryOperator::isNot(V))
4849 return 3;
4950 return 4;
5051 }
51 if (isa(V)) return 3;
52 if (isa(V))
53 return 3;
5254 return isa(V) ? (isa(V) ? 0 : 1) : 2;
5355 }
5456
6163 return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1));
6264 }
6365
64
6566 /// InstCombineIRInserter - This is an IRBuilder insertion helper that works
6667 /// just like the normal insertion helper, but also adds any new instructions
6768 /// to the instcombine worklist.
6869 class LLVM_LIBRARY_VISIBILITY InstCombineIRInserter
6970 : public IRBuilderDefaultInserter {
7071 InstCombineWorklist &Worklist;
72
7173 public:
7274 InstCombineIRInserter(InstCombineWorklist &WL) : Worklist(WL) {}
7375
74 void InsertHelper(Instruction *I, const Twine &Name,
75 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
76 void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB,
77 BasicBlock::iterator InsertPt) const {
7678 IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
7779 Worklist.Add(I);
7880 }
8082
8183 /// InstCombiner - The -instcombine pass.
8284 class LLVM_LIBRARY_VISIBILITY InstCombiner
83 : public FunctionPass,
84 public InstVisitor {
85 : public FunctionPass,
86 public InstVisitor {
8587 const DataLayout *DL;
8688 TargetLibraryInfo *TLI;
8789 bool MadeIRChange;
8890 LibCallSimplifier *Simplifier;
8991 bool MinimizeSize;
92
9093 public:
9194 /// Worklist - All of the instructions that need to be simplified.
9295 InstCombineWorklist Worklist;
145148 Instruction *visitAnd(BinaryOperator &I);
146149 Value *FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS);
147150 Value *FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS);
148 Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op,
149 Value *A, Value *B, Value *C);
150 Instruction *visitOr (BinaryOperator &I);
151 Instruction *FoldOrWithConstants(BinaryOperator &I, Value *Op, Value *A,
152 Value *B, Value *C);
153 Instruction *visitOr(BinaryOperator &I);
151154 Instruction *visitXor(BinaryOperator &I);
152155 Instruction *visitShl(BinaryOperator &I);
153156 Instruction *visitAShr(BinaryOperator &I);
161164 Instruction *visitFCmpInst(FCmpInst &I);
162165 Instruction *visitICmpInst(ICmpInst &I);
163166 Instruction *visitICmpInstWithCastAndCast(ICmpInst &ICI);
164 Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
165 Instruction *LHS,
167 Instruction *visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Instruction *LHS,
166168 ConstantInt *RHS);
167169 Instruction *FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
168170 ConstantInt *DivRHS);
189191 Instruction *visitIntToPtr(IntToPtrInst &CI);
190192 Instruction *visitBitCast(BitCastInst &CI);
191193 Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI);
192 Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI,
193 Instruction *FI);
194 Instruction *FoldSelectIntoOp(SelectInst &SI, Value*, Value*);
194 Instruction *FoldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI);
195 Instruction *FoldSelectIntoOp(SelectInst &SI, Value *, Value *);
195196 Instruction *FoldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1,
196197 Value *A, Value *B, Instruction &Outer,
197198 SelectPatternFlavor SPF2, Value *C);
223224 private:
224225 bool ShouldChangeType(Type *From, Type *To) const;
225226 Value *dyn_castNegVal(Value *V) const;
226 Value *dyn_castFNegVal(Value *V, bool NoSignedZero=false) const;
227 Value *dyn_castFNegVal(Value *V, bool NoSignedZero = false) const;
227228 Type *FindElementAtOffset(Type *PtrTy, int64_t Offset,
228 SmallVectorImpl*> &NewIndices);
229 SmallVectorImpl *> &NewIndices);
229230 Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
230231
231232 /// ShouldOptimizeCast - Return true if the cast from "V to Ty" actually
232233 /// results in any code being generated and is interesting to optimize out. If
233234 /// the cast can be eliminated by some other simple transformation, we prefer
234235 /// to do the simplification first.
235 bool ShouldOptimizeCast(Instruction::CastOps opcode,const Value *V,
236 bool ShouldOptimizeCast(Instruction::CastOps opcode, const Value *V,
236237 Type *Ty);
237238
238239 Instruction *visitCallSite(CallSite CS);
256257 assert(New && !New->getParent() &&
257258 "New instruction already inserted into a basic block!");
258259 BasicBlock *BB = Old.getParent();
259 BB->getInstList().insert(&Old, New); // Insert inst
260 BB->getInstList().insert(&Old, New); // Insert inst
260261 Worklist.Add(New);
261262 return New;
262263 }
276277 // modified.
277278 //
278279 Instruction *ReplaceInstUsesWith(Instruction &I, Value *V) {
279 Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
280 Worklist.AddUsersToWorkList(I); // Add all modified instrs to worklist.
280281
281282 // If we are replacing the instruction with itself, this must be in a
282283 // segment of unreachable code, so just clobber the instruction.
308309 Worklist.Remove(&I);
309310 I.eraseFromParent();
310311 MadeIRChange = true;
311 return nullptr; // Don't do anything with FI
312 }
313
314 void ComputeMaskedBits(Value *V, APInt &KnownZero,
315 APInt &KnownOne, unsigned Depth = 0) const {
312 return nullptr; // Don't do anything with FI
313 }
314
315 void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
316 unsigned Depth = 0) const {
316317 return llvm::ComputeMaskedBits(V, KnownZero, KnownOne, DL, Depth);
317318 }
318319
325326 }
326327
327328 private:
328
329329 /// SimplifyAssociativeOrCommutative - This performs a few simplifications for
330330 /// operators which are associative or commutative.
331331 bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
339339
340340 /// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
341341 /// based on the demanded bits.
342 Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
343 APInt& KnownZero, APInt& KnownOne,
344 unsigned Depth);
345 bool SimplifyDemandedBits(Use &U, APInt DemandedMask,
346 APInt& KnownZero, APInt& KnownOne,
347 unsigned Depth=0);
342 Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, APInt &KnownZero,
343 APInt &KnownOne, unsigned Depth);
344 bool SimplifyDemandedBits(Use &U, APInt DemandedMask, APInt &KnownZero,
345 APInt &KnownOne, unsigned Depth = 0);
348346 /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
349347 /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
350348 Value *SimplifyShrShlDemandedBits(Instruction *Lsr, Instruction *Sftl,
357355 bool SimplifyDemandedInstructionBits(Instruction &Inst);
358356
359357 Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
360 APInt& UndefElts, unsigned Depth = 0);
358 APInt &UndefElts, unsigned Depth = 0);
361359
362360 // FoldOpIntoPhi - Given a binary operator, cast instruction, or select
363361 // which has a PHI node as operand #0, see if we can fold the instruction
374372 Instruction *FoldPHIArgGEPIntoPHI(PHINode &PN);
375373 Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN);
376374
377
378375 Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
379376 ConstantInt *AndRHS, BinaryOperator &TheAnd);
380377
381378 Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
382379 bool isSub, Instruction &I);
383 Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
384 bool isSigned, bool Inside);
380 Value *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi, bool isSigned,
381 bool Inside);
385382 Instruction *PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI);
386383 Instruction *MatchBSwap(BinaryOperator &I);
387384 bool SimplifyStoreAtEndOfBlock(StoreInst &SI);
388385 Instruction *SimplifyMemTransfer(MemIntrinsic *MI);
389386 Instruction *SimplifyMemSet(MemSetInst *MI);
390387
391
392388 Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
393389
394390 /// Descale - Return a value X such that Val = X * Scale, or null if none. If