LLVM 20.0.0git
InstCombineInternal.h
Go to the documentation of this file.
1//===- InstCombineInternal.h - InstCombine pass internals -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10///
11/// This file provides internal interfaces used to implement the InstCombine.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
16#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
17
18#include "llvm/ADT/Statistic.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/InstVisitor.h"
26#include "llvm/IR/Value.h"
27#include "llvm/Support/Debug.h"
31#include <cassert>
32
33#define DEBUG_TYPE "instcombine"
35
36// As a default, let's assume that we want to be aggressive,
37// and attempt to traverse with no limits in attempt to sink negation.
38static constexpr unsigned NegatorDefaultMaxDepth = ~0U;
39
40// Let's guesstimate that most often we will end up visiting/producing
41// fairly small number of new instructions.
42static constexpr unsigned NegatorMaxNodesSSO = 16;
43
44namespace llvm {
45
46class AAResults;
47class APInt;
48class AssumptionCache;
49class BlockFrequencyInfo;
50class DataLayout;
51class DominatorTree;
52class GEPOperator;
53class GlobalVariable;
54class OptimizationRemarkEmitter;
55class ProfileSummaryInfo;
56class TargetLibraryInfo;
57class User;
58
60 : public InstCombiner,
61 public InstVisitor<InstCombinerImpl, Instruction *> {
62public:
64 bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
68 ProfileSummaryInfo *PSI, const DataLayout &DL,
70 : InstCombiner(Worklist, Builder, MinimizeSize, AA, AC, TLI, TTI, DT, ORE,
71 BFI, BPI, PSI, DL, RPOT) {}
72
73 virtual ~InstCombinerImpl() = default;
74
75 /// Perform early cleanup and prepare the InstCombine worklist.
76 bool prepareWorklist(Function &F);
77
78 /// Run the combiner over the entire worklist until it is empty.
79 ///
80 /// \returns true if the IR is changed.
81 bool run();
82
83 // Visitation implementation - Implement instruction combining for different
84 // instruction types. The semantics are as follows:
85 // Return Value:
86 // null - No change was made
87 // I - Change was made, I is still valid, I may be dead though
88 // otherwise - Change was made, replace I with returned instruction
89 //
90 Instruction *visitFNeg(UnaryOperator &I);
91 Instruction *visitAdd(BinaryOperator &I);
92 Instruction *visitFAdd(BinaryOperator &I);
93 Value *OptimizePointerDifference(
94 Value *LHS, Value *RHS, Type *Ty, bool isNUW);
95 Instruction *visitSub(BinaryOperator &I);
96 Instruction *visitFSub(BinaryOperator &I);
97 Instruction *visitMul(BinaryOperator &I);
98 Instruction *foldPowiReassoc(BinaryOperator &I);
99 Instruction *foldFMulReassoc(BinaryOperator &I);
100 Instruction *visitFMul(BinaryOperator &I);
101 Instruction *visitURem(BinaryOperator &I);
102 Instruction *visitSRem(BinaryOperator &I);
103 Instruction *visitFRem(BinaryOperator &I);
104 bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I);
105 Instruction *commonIDivRemTransforms(BinaryOperator &I);
106 Instruction *commonIRemTransforms(BinaryOperator &I);
107 Instruction *commonIDivTransforms(BinaryOperator &I);
108 Instruction *visitUDiv(BinaryOperator &I);
109 Instruction *visitSDiv(BinaryOperator &I);
110 Instruction *visitFDiv(BinaryOperator &I);
111 Value *simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted);
112 Instruction *visitAnd(BinaryOperator &I);
113 Instruction *visitOr(BinaryOperator &I);
114 bool sinkNotIntoLogicalOp(Instruction &I);
115 bool sinkNotIntoOtherHandOfLogicalOp(Instruction &I);
116 Instruction *visitXor(BinaryOperator &I);
117 Instruction *visitShl(BinaryOperator &I);
118 Value *reassociateShiftAmtsOfTwoSameDirectionShifts(
119 BinaryOperator *Sh0, const SimplifyQuery &SQ,
120 bool AnalyzeForSignBitExtraction = false);
121 Instruction *canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
123 Instruction *foldVariableSignZeroExtensionOfVariableHighBitExtract(
124 BinaryOperator &OldAShr);
125 Instruction *visitAShr(BinaryOperator &I);
126 Instruction *visitLShr(BinaryOperator &I);
127 Instruction *commonShiftTransforms(BinaryOperator &I);
128 Instruction *visitFCmpInst(FCmpInst &I);
129 CmpInst *canonicalizeICmpPredicate(CmpInst &I);
130 Instruction *visitICmpInst(ICmpInst &I);
131 Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1,
133 Instruction *commonCastTransforms(CastInst &CI);
134 Instruction *visitTrunc(TruncInst &CI);
135 Instruction *visitZExt(ZExtInst &Zext);
136 Instruction *visitSExt(SExtInst &Sext);
137 Instruction *visitFPTrunc(FPTruncInst &CI);
138 Instruction *visitFPExt(CastInst &CI);
139 Instruction *visitFPToUI(FPToUIInst &FI);
140 Instruction *visitFPToSI(FPToSIInst &FI);
141 Instruction *visitUIToFP(CastInst &CI);
142 Instruction *visitSIToFP(CastInst &CI);
143 Instruction *visitPtrToInt(PtrToIntInst &CI);
144 Instruction *visitIntToPtr(IntToPtrInst &CI);
145 Instruction *visitBitCast(BitCastInst &CI);
146 Instruction *visitAddrSpaceCast(AddrSpaceCastInst &CI);
147 Instruction *foldItoFPtoI(CastInst &FI);
149 Instruction *visitCallInst(CallInst &CI);
150 Instruction *visitInvokeInst(InvokeInst &II);
151 Instruction *visitCallBrInst(CallBrInst &CBI);
152
153 Instruction *SliceUpIllegalIntegerPHI(PHINode &PN);
154 Instruction *visitPHINode(PHINode &PN);
155 Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
156 Instruction *visitGEPOfGEP(GetElementPtrInst &GEP, GEPOperator *Src);
157 Instruction *visitAllocaInst(AllocaInst &AI);
158 Instruction *visitAllocSite(Instruction &FI);
159 Instruction *visitFree(CallInst &FI, Value *FreedOp);
160 Instruction *visitLoadInst(LoadInst &LI);
161 Instruction *visitStoreInst(StoreInst &SI);
162 Instruction *visitAtomicRMWInst(AtomicRMWInst &SI);
163 Instruction *visitUnconditionalBranchInst(BranchInst &BI);
164 Instruction *visitBranchInst(BranchInst &BI);
165 Instruction *visitFenceInst(FenceInst &FI);
166 Instruction *visitSwitchInst(SwitchInst &SI);
167 Instruction *visitReturnInst(ReturnInst &RI);
168 Instruction *visitUnreachableInst(UnreachableInst &I);
170 foldAggregateConstructionIntoAggregateReuse(InsertValueInst &OrigIVI);
171 Instruction *visitInsertValueInst(InsertValueInst &IV);
172 Instruction *visitInsertElementInst(InsertElementInst &IE);
173 Instruction *visitExtractElementInst(ExtractElementInst &EI);
174 Instruction *simplifyBinOpSplats(ShuffleVectorInst &SVI);
175 Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI);
176 Instruction *visitExtractValueInst(ExtractValueInst &EV);
177 Instruction *visitLandingPadInst(LandingPadInst &LI);
178 Instruction *visitVAEndInst(VAEndInst &I);
179 Value *pushFreezeToPreventPoisonFromPropagating(FreezeInst &FI);
180 bool freezeOtherUses(FreezeInst &FI);
181 Instruction *foldFreezeIntoRecurrence(FreezeInst &I, PHINode *PN);
182 Instruction *visitFreeze(FreezeInst &I);
183
184 /// Specify what to return for unhandled instructions.
186
187 /// True when DB dominates all uses of DI except UI.
188 /// UI must be in the same block as DI.
189 /// The routine checks that the DI parent and DB are different.
190 bool dominatesAllUses(const Instruction *DI, const Instruction *UI,
191 const BasicBlock *DB) const;
192
193 /// Try to replace select with select operand SIOpd in SI-ICmp sequence.
194 bool replacedSelectWithOperand(SelectInst *SI, const ICmpInst *Icmp,
195 const unsigned SIOpd);
196
197 LoadInst *combineLoadToNewType(LoadInst &LI, Type *NewTy,
198 const Twine &Suffix = "");
199
201 FPClassTest Interested = fcAllFlags,
202 const Instruction *CtxI = nullptr,
203 unsigned Depth = 0) const {
205 Val, FMF, Interested, Depth,
206 getSimplifyQuery().getWithInstruction(CtxI));
207 }
208
210 FPClassTest Interested = fcAllFlags,
211 const Instruction *CtxI = nullptr,
212 unsigned Depth = 0) const {
214 Val, Interested, Depth, getSimplifyQuery().getWithInstruction(CtxI));
215 }
216
217 /// Check if fmul \p MulVal, +0.0 will yield +0.0 (or signed zero is
218 /// ignorable).
220 const Instruction *CtxI) const;
221
222 Constant *getLosslessTrunc(Constant *C, Type *TruncTy, unsigned ExtOp) {
223 Constant *TruncC = ConstantExpr::getTrunc(C, TruncTy);
224 Constant *ExtTruncC =
225 ConstantFoldCastOperand(ExtOp, TruncC, C->getType(), DL);
226 if (ExtTruncC && ExtTruncC == C)
227 return TruncC;
228 return nullptr;
229 }
230
232 return getLosslessTrunc(C, TruncTy, Instruction::ZExt);
233 }
234
236 return getLosslessTrunc(C, TruncTy, Instruction::SExt);
237 }
238
239 std::optional<std::pair<Intrinsic::ID, SmallVector<Value *, 3>>>
240 convertOrOfShiftsToFunnelShift(Instruction &Or);
241
242private:
243 bool annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI);
244 bool isDesirableIntType(unsigned BitWidth) const;
245 bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
246 bool shouldChangeType(Type *From, Type *To) const;
247 Value *dyn_castNegVal(Value *V) const;
248
249 /// Classify whether a cast is worth optimizing.
250 ///
251 /// This is a helper to decide whether the simplification of
252 /// logic(cast(A), cast(B)) to cast(logic(A, B)) should be performed.
253 ///
254 /// \param CI The cast we are interested in.
255 ///
256 /// \return true if this cast actually results in any code being generated and
257 /// if it cannot already be eliminated by some other transformation.
258 bool shouldOptimizeCast(CastInst *CI);
259
260 /// Try to optimize a sequence of instructions checking if an operation
261 /// on LHS and RHS overflows.
262 ///
263 /// If this overflow check is done via one of the overflow check intrinsics,
264 /// then CtxI has to be the call instruction calling that intrinsic. If this
265 /// overflow check is done by arithmetic followed by a compare, then CtxI has
266 /// to be the arithmetic instruction.
267 ///
268 /// If a simplification is possible, stores the simplified result of the
269 /// operation in OperationResult and result of the overflow check in
270 /// OverflowResult, and return true. If no simplification is possible,
271 /// returns false.
272 bool OptimizeOverflowCheck(Instruction::BinaryOps BinaryOp, bool IsSigned,
273 Value *LHS, Value *RHS,
274 Instruction &CtxI, Value *&OperationResult,
276
277 Instruction *visitCallBase(CallBase &Call);
278 Instruction *tryOptimizeCall(CallInst *CI);
279 bool transformConstExprCastCall(CallBase &Call);
280 Instruction *transformCallThroughTrampoline(CallBase &Call,
281 IntrinsicInst &Tramp);
282
283 // Return (a, b) if (LHS, RHS) is known to be (a, b) or (b, a).
284 // Otherwise, return std::nullopt
285 // Currently it matches:
286 // - LHS = (select c, a, b), RHS = (select c, b, a)
287 // - LHS = (phi [a, BB0], [b, BB1]), RHS = (phi [b, BB0], [a, BB1])
288 // - LHS = min(a, b), RHS = max(a, b)
289 std::optional<std::pair<Value *, Value *>> matchSymmetricPair(Value *LHS,
290 Value *RHS);
291
292 Value *simplifyMaskedLoad(IntrinsicInst &II);
293 Instruction *simplifyMaskedStore(IntrinsicInst &II);
294 Instruction *simplifyMaskedGather(IntrinsicInst &II);
295 Instruction *simplifyMaskedScatter(IntrinsicInst &II);
296
297 /// Transform (zext icmp) to bitwise / integer operations in order to
298 /// eliminate it.
299 ///
300 /// \param ICI The icmp of the (zext icmp) pair we are interested in.
301 /// \parem CI The zext of the (zext icmp) pair we are interested in.
302 ///
303 /// \return null if the transformation cannot be performed. If the
304 /// transformation can be performed the new instruction that replaces the
305 /// (zext icmp) pair will be returned.
306 Instruction *transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext);
307
308 Instruction *transformSExtICmp(ICmpInst *Cmp, SExtInst &Sext);
309
310 bool willNotOverflowSignedAdd(const WithCache<const Value *> &LHS,
312 const Instruction &CxtI) const {
313 return computeOverflowForSignedAdd(LHS, RHS, &CxtI) ==
314 OverflowResult::NeverOverflows;
315 }
316
317 bool willNotOverflowUnsignedAdd(const WithCache<const Value *> &LHS,
318 const WithCache<const Value *> &RHS,
319 const Instruction &CxtI) const {
320 return computeOverflowForUnsignedAdd(LHS, RHS, &CxtI) ==
321 OverflowResult::NeverOverflows;
322 }
323
324 bool willNotOverflowAdd(const Value *LHS, const Value *RHS,
325 const Instruction &CxtI, bool IsSigned) const {
326 return IsSigned ? willNotOverflowSignedAdd(LHS, RHS, CxtI)
327 : willNotOverflowUnsignedAdd(LHS, RHS, CxtI);
328 }
329
330 bool willNotOverflowSignedSub(const Value *LHS, const Value *RHS,
331 const Instruction &CxtI) const {
332 return computeOverflowForSignedSub(LHS, RHS, &CxtI) ==
333 OverflowResult::NeverOverflows;
334 }
335
336 bool willNotOverflowUnsignedSub(const Value *LHS, const Value *RHS,
337 const Instruction &CxtI) const {
338 return computeOverflowForUnsignedSub(LHS, RHS, &CxtI) ==
339 OverflowResult::NeverOverflows;
340 }
341
342 bool willNotOverflowSub(const Value *LHS, const Value *RHS,
343 const Instruction &CxtI, bool IsSigned) const {
344 return IsSigned ? willNotOverflowSignedSub(LHS, RHS, CxtI)
345 : willNotOverflowUnsignedSub(LHS, RHS, CxtI);
346 }
347
348 bool willNotOverflowSignedMul(const Value *LHS, const Value *RHS,
349 const Instruction &CxtI) const {
350 return computeOverflowForSignedMul(LHS, RHS, &CxtI) ==
351 OverflowResult::NeverOverflows;
352 }
353
354 bool willNotOverflowUnsignedMul(const Value *LHS, const Value *RHS,
355 const Instruction &CxtI,
356 bool IsNSW = false) const {
357 return computeOverflowForUnsignedMul(LHS, RHS, &CxtI, IsNSW) ==
358 OverflowResult::NeverOverflows;
359 }
360
361 bool willNotOverflowMul(const Value *LHS, const Value *RHS,
362 const Instruction &CxtI, bool IsSigned) const {
363 return IsSigned ? willNotOverflowSignedMul(LHS, RHS, CxtI)
364 : willNotOverflowUnsignedMul(LHS, RHS, CxtI);
365 }
366
367 bool willNotOverflow(BinaryOperator::BinaryOps Opcode, const Value *LHS,
368 const Value *RHS, const Instruction &CxtI,
369 bool IsSigned) const {
370 switch (Opcode) {
371 case Instruction::Add: return willNotOverflowAdd(LHS, RHS, CxtI, IsSigned);
372 case Instruction::Sub: return willNotOverflowSub(LHS, RHS, CxtI, IsSigned);
373 case Instruction::Mul: return willNotOverflowMul(LHS, RHS, CxtI, IsSigned);
374 default: llvm_unreachable("Unexpected opcode for overflow query");
375 }
376 }
377
378 Value *EmitGEPOffset(GEPOperator *GEP, bool RewriteGEP = false);
379 Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN);
380 Instruction *foldBitcastExtElt(ExtractElementInst &ExtElt);
381 Instruction *foldCastedBitwiseLogic(BinaryOperator &I);
382 Instruction *foldFBinOpOfIntCasts(BinaryOperator &I);
383 // Should only be called by `foldFBinOpOfIntCasts`.
384 Instruction *foldFBinOpOfIntCastsFromSign(
385 BinaryOperator &BO, bool OpsFromSigned, std::array<Value *, 2> IntOps,
386 Constant *Op1FpC, SmallVectorImpl<WithCache<const Value *>> &OpsKnown);
387 Instruction *foldBinopOfSextBoolToSelect(BinaryOperator &I);
388 Instruction *narrowBinOp(TruncInst &Trunc);
389 Instruction *narrowMaskedBinOp(BinaryOperator &And);
390 Instruction *narrowMathIfNoOverflow(BinaryOperator &I);
391 Instruction *narrowFunnelShift(TruncInst &Trunc);
392 Instruction *optimizeBitCastFromPhi(CastInst &CI, PHINode *PN);
393 Instruction *matchSAddSubSat(IntrinsicInst &MinMax1);
394 Instruction *foldNot(BinaryOperator &I);
395 Instruction *foldBinOpOfDisplacedShifts(BinaryOperator &I);
396
397 /// Determine if a pair of casts can be replaced by a single cast.
398 ///
399 /// \param CI1 The first of a pair of casts.
400 /// \param CI2 The second of a pair of casts.
401 ///
402 /// \return 0 if the cast pair cannot be eliminated, otherwise returns an
403 /// Instruction::CastOps value for a cast that can replace the pair, casting
404 /// CI1->getSrcTy() to CI2->getDstTy().
405 ///
406 /// \see CastInst::isEliminableCastPair
407 Instruction::CastOps isEliminableCastPair(const CastInst *CI1,
408 const CastInst *CI2);
409 Value *simplifyIntToPtrRoundTripCast(Value *Val);
410
411 Value *foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction &I,
412 bool IsAnd, bool IsLogical = false);
413 Value *foldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS, BinaryOperator &Xor);
414
415 Value *foldEqOfParts(Value *Cmp0, Value *Cmp1, bool IsAnd);
416
417 Value *foldAndOrOfICmpsUsingRanges(ICmpInst *ICmp1, ICmpInst *ICmp2,
418 bool IsAnd);
419
420 /// Optimize (fcmp)&(fcmp) or (fcmp)|(fcmp).
421 /// NOTE: Unlike most of instcombine, this returns a Value which should
422 /// already be inserted into the function.
423 Value *foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS, bool IsAnd,
424 bool IsLogicalSelect = false);
425
426 Instruction *foldLogicOfIsFPClass(BinaryOperator &Operator, Value *LHS,
427 Value *RHS);
428
429 Value *foldBooleanAndOr(Value *LHS, Value *RHS, Instruction &I, bool IsAnd,
430 bool IsLogical);
431
432 Value *reassociateBooleanAndOr(Value *LHS, Value *X, Value *Y, Instruction &I,
433 bool IsAnd, bool RHSIsLogical);
434
435 Instruction *
436 canonicalizeConditionalNegationViaMathToSelect(BinaryOperator &i);
437
438 Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
439 Instruction *CxtI, bool IsAnd,
440 bool IsLogical = false);
441 Value *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D,
442 bool InvertFalseVal = false);
443 Value *getSelectCondition(Value *A, Value *B, bool ABIsTheSame);
444
445 Instruction *foldLShrOverflowBit(BinaryOperator &I);
446 Instruction *foldExtractOfOverflowIntrinsic(ExtractValueInst &EV);
447 Instruction *foldIntrinsicWithOverflowCommon(IntrinsicInst *II);
448 Instruction *foldIntrinsicIsFPClass(IntrinsicInst &II);
449 Instruction *foldFPSignBitOps(BinaryOperator &I);
450 Instruction *foldFDivConstantDivisor(BinaryOperator &I);
451
452 // Optimize one of these forms:
453 // and i1 Op, SI / select i1 Op, i1 SI, i1 false (if IsAnd = true)
454 // or i1 Op, SI / select i1 Op, i1 true, i1 SI (if IsAnd = false)
455 // into simplier select instruction using isImpliedCondition.
456 Instruction *foldAndOrOfSelectUsingImpliedCond(Value *Op, SelectInst &SI,
457 bool IsAnd);
458
459 Instruction *hoistFNegAboveFMulFDiv(Value *FNegOp, Instruction &FMFSource);
460
461public:
462 /// Create and insert the idiom we use to indicate a block is unreachable
463 /// without having to rewrite the CFG from within InstCombine.
465 auto &Ctx = InsertAt->getContext();
466 auto *SI = new StoreInst(ConstantInt::getTrue(Ctx),
467 PoisonValue::get(PointerType::getUnqual(Ctx)),
468 /*isVolatile*/ false, Align(1));
469 InsertNewInstWith(SI, InsertAt->getIterator());
470 }
471
472 /// Combiner aware instruction erasure.
473 ///
474 /// When dealing with an instruction that has side effects or produces a void
475 /// value, we can't rely on DCE to delete the instruction. Instead, visit
476 /// methods should return the value returned by this function.
478 LLVM_DEBUG(dbgs() << "IC: ERASE " << I << '\n');
479 assert(I.use_empty() && "Cannot erase instruction that is used!");
481
482 // Make sure that we reprocess all operands now that we reduced their
483 // use counts.
484 SmallVector<Value *> Ops(I.operands());
485 Worklist.remove(&I);
486 DC.removeValue(&I);
487 I.eraseFromParent();
488 for (Value *Op : Ops)
489 Worklist.handleUseCountDecrement(Op);
490 MadeIRChange = true;
491 return nullptr; // Don't do anything with FI
492 }
493
494 OverflowResult computeOverflow(
495 Instruction::BinaryOps BinaryOp, bool IsSigned,
496 Value *LHS, Value *RHS, Instruction *CxtI) const;
497
498 /// Performs a few simplifications for operators which are associative
499 /// or commutative.
500 bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
501
502 /// Tries to simplify binary operations which some other binary
503 /// operation distributes over.
504 ///
505 /// It does this by either by factorizing out common terms (eg "(A*B)+(A*C)"
506 /// -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A
507 /// & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified
508 /// value, or null if it didn't simplify.
509 Value *foldUsingDistributiveLaws(BinaryOperator &I);
510
511 /// Tries to simplify add operations using the definition of remainder.
512 ///
513 /// The definition of remainder is X % C = X - (X / C ) * C. The add
514 /// expression X % C0 + (( X / C0 ) % C1) * C0 can be simplified to
515 /// X % (C0 * C1)
516 Value *SimplifyAddWithRemainder(BinaryOperator &I);
517
518 // Binary Op helper for select operations where the expression can be
519 // efficiently reorganized.
520 Value *SimplifySelectsFeedingBinaryOp(BinaryOperator &I, Value *LHS,
521 Value *RHS);
522
523 // If `I` has operand `(ctpop (not x))`, fold `I` with `(sub nuw nsw
524 // BitWidth(x), (ctpop x))`.
525 Instruction *tryFoldInstWithCtpopWithNot(Instruction *I);
526
527 // (Binop1 (Binop2 (logic_shift X, C), C1), (logic_shift Y, C))
528 // -> (logic_shift (Binop1 (Binop2 X, inv_logic_shift(C1, C)), Y), C)
529 // (Binop1 (Binop2 (logic_shift X, Amt), Mask), (logic_shift Y, Amt))
530 // -> (BinOp (logic_shift (BinOp X, Y)), Mask)
531 Instruction *foldBinOpShiftWithShift(BinaryOperator &I);
532
533 /// Tries to simplify binops of select and cast of the select condition.
534 ///
535 /// (Binop (cast C), (select C, T, F))
536 /// -> (select C, C0, C1)
537 Instruction *foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I);
538
539 /// This tries to simplify binary operations by factorizing out common terms
540 /// (e. g. "(A*B)+(A*C)" -> "A*(B+C)").
541 Value *tryFactorizationFolds(BinaryOperator &I);
542
543 /// Match a select chain which produces one of three values based on whether
544 /// the LHS is less than, equal to, or greater than RHS respectively.
545 /// Return true if we matched a three way compare idiom. The LHS, RHS, Less,
546 /// Equal and Greater values are saved in the matching process and returned to
547 /// the caller.
548 bool matchThreeWayIntCompare(SelectInst *SI, Value *&LHS, Value *&RHS,
549 ConstantInt *&Less, ConstantInt *&Equal,
550 ConstantInt *&Greater);
551
552 /// Attempts to replace I with a simpler value based on the demanded
553 /// bits.
554 Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask,
555 KnownBits &Known, unsigned Depth,
556 const SimplifyQuery &Q);
557 using InstCombiner::SimplifyDemandedBits;
558 bool SimplifyDemandedBits(Instruction *I, unsigned Op,
559 const APInt &DemandedMask, KnownBits &Known,
560 unsigned Depth, const SimplifyQuery &Q) override;
561
562 /// Helper routine of SimplifyDemandedUseBits. It computes KnownZero/KnownOne
563 /// bits. It also tries to handle simplifications that can be done based on
564 /// DemandedMask, but without modifying the Instruction.
565 Value *SimplifyMultipleUseDemandedBits(Instruction *I,
566 const APInt &DemandedMask,
567 KnownBits &Known, unsigned Depth,
568 const SimplifyQuery &Q);
569
570 /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
571 /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
572 Value *simplifyShrShlDemandedBits(
573 Instruction *Shr, const APInt &ShrOp1, Instruction *Shl,
574 const APInt &ShlOp1, const APInt &DemandedMask, KnownBits &Known);
575
576 /// Tries to simplify operands to an integer instruction based on its
577 /// demanded bits.
578 bool SimplifyDemandedInstructionBits(Instruction &Inst);
579 bool SimplifyDemandedInstructionBits(Instruction &Inst, KnownBits &Known);
580
581 Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
582 APInt &PoisonElts, unsigned Depth = 0,
583 bool AllowMultipleUsers = false) override;
584
585 /// Attempts to replace V with a simpler value based on the demanded
586 /// floating-point classes
587 Value *SimplifyDemandedUseFPClass(Value *V, FPClassTest DemandedMask,
588 KnownFPClass &Known, unsigned Depth,
589 Instruction *CxtI);
590 bool SimplifyDemandedFPClass(Instruction *I, unsigned Op,
591 FPClassTest DemandedMask, KnownFPClass &Known,
592 unsigned Depth = 0);
593
594 /// Common transforms for add / disjoint or
595 Instruction *foldAddLikeCommutative(Value *LHS, Value *RHS, bool NSW,
596 bool NUW);
597
598 /// Canonicalize the position of binops relative to shufflevector.
599 Instruction *foldVectorBinop(BinaryOperator &Inst);
601 Instruction *foldSelectShuffle(ShuffleVectorInst &Shuf);
602
603 /// Given a binary operator, cast instruction, or select which has a PHI node
604 /// as operand #0, see if we can fold the instruction into the PHI (which is
605 /// only possible if all operands to the PHI are constants).
606 Instruction *foldOpIntoPhi(Instruction &I, PHINode *PN,
607 bool AllowMultipleUses = false);
608
609 /// For a binary operator with 2 phi operands, try to hoist the binary
610 /// operation before the phi. This can result in fewer instructions in
611 /// patterns where at least one set of phi operands simplifies.
612 /// Example:
613 /// BB3: binop (phi [X, BB1], [C1, BB2]), (phi [Y, BB1], [C2, BB2])
614 /// -->
615 /// BB1: BO = binop X, Y
616 /// BB3: phi [BO, BB1], [(binop C1, C2), BB2]
617 Instruction *foldBinopWithPhiOperands(BinaryOperator &BO);
618
619 /// Given an instruction with a select as one operand and a constant as the
620 /// other operand, try to fold the binary operator into the select arguments.
621 /// This also works for Cast instructions, which obviously do not have a
622 /// second operand.
623 Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
624 bool FoldWithMultiUse = false);
625
626 /// This is a convenience wrapper function for the above two functions.
627 Instruction *foldBinOpIntoSelectOrPhi(BinaryOperator &I);
628
629 Instruction *foldAddWithConstant(BinaryOperator &Add);
630
631 Instruction *foldSquareSumInt(BinaryOperator &I);
632 Instruction *foldSquareSumFP(BinaryOperator &I);
633
634 /// Try to rotate an operation below a PHI node, using PHI nodes for
635 /// its operands.
636 Instruction *foldPHIArgOpIntoPHI(PHINode &PN);
637 Instruction *foldPHIArgBinOpIntoPHI(PHINode &PN);
638 Instruction *foldPHIArgInsertValueInstructionIntoPHI(PHINode &PN);
639 Instruction *foldPHIArgExtractValueInstructionIntoPHI(PHINode &PN);
640 Instruction *foldPHIArgGEPIntoPHI(PHINode &PN);
641 Instruction *foldPHIArgLoadIntoPHI(PHINode &PN);
642 Instruction *foldPHIArgZextsIntoPHI(PHINode &PN);
643 Instruction *foldPHIArgIntToPtrToPHI(PHINode &PN);
644
645 /// If the phi is within a phi web, which is formed by the def-use chain
646 /// of phis and all the phis in the web are only used in the other phis.
647 /// In this case, these phis are dead and we will remove all of them.
648 bool foldDeadPhiWeb(PHINode &PN);
649
650 /// If an integer typed PHI has only one use which is an IntToPtr operation,
651 /// replace the PHI with an existing pointer typed PHI if it exists. Otherwise
652 /// insert a new pointer typed PHI and replace the original one.
653 bool foldIntegerTypedPHI(PHINode &PN);
654
655 /// Helper function for FoldPHIArgXIntoPHI() to set debug location for the
656 /// folded operation.
657 void PHIArgMergedDebugLoc(Instruction *Inst, PHINode &PN);
658
659 Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, CmpPredicate Cond,
660 Instruction &I);
661 Instruction *foldSelectICmp(CmpPredicate Pred, SelectInst *SI, Value *RHS,
662 const ICmpInst &I);
663 bool foldAllocaCmp(AllocaInst *Alloca);
664 Instruction *foldCmpLoadFromIndexedGlobal(LoadInst *LI,
666 GlobalVariable *GV, CmpInst &ICI,
667 ConstantInt *AndCst = nullptr);
668 Instruction *foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
669 Constant *RHSC);
670 Instruction *foldICmpAddOpConst(Value *X, const APInt &C, CmpPredicate Pred);
671 Instruction *foldICmpWithCastOp(ICmpInst &ICmp);
672 Instruction *foldICmpWithZextOrSext(ICmpInst &ICmp);
673
674 Instruction *foldICmpUsingKnownBits(ICmpInst &Cmp);
676 Instruction *foldICmpWithConstant(ICmpInst &Cmp);
677 Instruction *foldICmpUsingBoolRange(ICmpInst &I);
678 Instruction *foldICmpInstWithConstant(ICmpInst &Cmp);
679 Instruction *foldICmpInstWithConstantNotInt(ICmpInst &Cmp);
680 Instruction *foldICmpInstWithConstantAllowPoison(ICmpInst &Cmp,
681 const APInt &C);
682 Instruction *foldICmpBinOp(ICmpInst &Cmp, const SimplifyQuery &SQ);
683 Instruction *foldICmpWithMinMax(Instruction &I, MinMaxIntrinsic *MinMax,
684 Value *Z, CmpPredicate Pred);
685 Instruction *foldICmpEquality(ICmpInst &Cmp);
686 Instruction *foldIRemByPowerOfTwoToBitTest(ICmpInst &I);
687 Instruction *foldSignBitTest(ICmpInst &I);
688 Instruction *foldICmpWithZero(ICmpInst &Cmp);
689
690 Value *foldMultiplicationOverflowCheck(ICmpInst &Cmp);
691
692 Instruction *foldICmpBinOpWithConstant(ICmpInst &Cmp, BinaryOperator *BO,
693 const APInt &C);
694 Instruction *foldICmpSelectConstant(ICmpInst &Cmp, SelectInst *Select,
695 ConstantInt *C);
696 Instruction *foldICmpTruncConstant(ICmpInst &Cmp, TruncInst *Trunc,
697 const APInt &C);
698 Instruction *foldICmpTruncWithTruncOrExt(ICmpInst &Cmp,
699 const SimplifyQuery &Q);
700 Instruction *foldICmpAndConstant(ICmpInst &Cmp, BinaryOperator *And,
701 const APInt &C);
702 Instruction *foldICmpXorConstant(ICmpInst &Cmp, BinaryOperator *Xor,
703 const APInt &C);
704 Instruction *foldICmpOrConstant(ICmpInst &Cmp, BinaryOperator *Or,
705 const APInt &C);
706 Instruction *foldICmpMulConstant(ICmpInst &Cmp, BinaryOperator *Mul,
707 const APInt &C);
708 Instruction *foldICmpShlConstant(ICmpInst &Cmp, BinaryOperator *Shl,
709 const APInt &C);
710 Instruction *foldICmpShrConstant(ICmpInst &Cmp, BinaryOperator *Shr,
711 const APInt &C);
712 Instruction *foldICmpSRemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
713 const APInt &C);
714 Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
715 const APInt &C);
716 Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,
717 const APInt &C);
718 Instruction *foldICmpSubConstant(ICmpInst &Cmp, BinaryOperator *Sub,
719 const APInt &C);
720 Instruction *foldICmpAddConstant(ICmpInst &Cmp, BinaryOperator *Add,
721 const APInt &C);
722 Instruction *foldICmpAndConstConst(ICmpInst &Cmp, BinaryOperator *And,
723 const APInt &C1);
724 Instruction *foldICmpAndShift(ICmpInst &Cmp, BinaryOperator *And,
725 const APInt &C1, const APInt &C2);
726 Instruction *foldICmpXorShiftConst(ICmpInst &Cmp, BinaryOperator *Xor,
727 const APInt &C);
728 Instruction *foldICmpShrConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
729 const APInt &C2);
730 Instruction *foldICmpShlConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
731 const APInt &C2);
732
733 Instruction *foldICmpBinOpEqualityWithConstant(ICmpInst &Cmp,
734 BinaryOperator *BO,
735 const APInt &C);
736 Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI, IntrinsicInst *II,
737 const APInt &C);
738 Instruction *foldICmpEqIntrinsicWithConstant(ICmpInst &ICI, IntrinsicInst *II,
739 const APInt &C);
740 Instruction *foldICmpBitCast(ICmpInst &Cmp);
741 Instruction *foldICmpWithTrunc(ICmpInst &Cmp);
742 Instruction *foldICmpCommutative(CmpPredicate Pred, Value *Op0, Value *Op1,
743 ICmpInst &CxtI);
744
745 // Helpers of visitSelectInst().
750 Instruction *foldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI);
751 Instruction *foldSelectIntoOp(SelectInst &SI, Value *, Value *);
753 Value *A, Value *B, Instruction &Outer,
758 unsigned Depth = 0);
759
760 Value *insertRangeTest(Value *V, const APInt &Lo, const APInt &Hi,
761 bool isSigned, bool Inside);
762 bool mergeStoreIntoSuccessor(StoreInst &SI);
763
764 /// Given an initial instruction, check to see if it is the root of a
765 /// bswap/bitreverse idiom. If so, return the equivalent bswap/bitreverse
766 /// intrinsic.
767 Instruction *matchBSwapOrBitReverse(Instruction &I, bool MatchBSwaps,
768 bool MatchBitReversals);
769
770 Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI);
771 Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI);
772
773 Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
774
775 bool tryToSinkInstruction(Instruction *I, BasicBlock *DestBlock);
776 void tryToSinkInstructionDbgValues(
777 Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
779 void tryToSinkInstructionDbgVariableRecords(
780 Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
782
783 bool removeInstructionsBeforeUnreachable(Instruction &I);
784 void addDeadEdge(BasicBlock *From, BasicBlock *To,
786 void handleUnreachableFrom(Instruction *I,
788 void handlePotentiallyDeadBlocks(SmallVectorImpl<BasicBlock *> &Worklist);
789 void handlePotentiallyDeadSuccessors(BasicBlock *BB, BasicBlock *LiveSucc);
790 void freelyInvertAllUsersOf(Value *V, Value *IgnoredUser = nullptr);
791};
792
793class Negator final {
794 /// Top-to-bottom, def-to-use negated instruction tree we produced.
796
798 BuilderTy Builder;
799
800 const DominatorTree &DT;
801
802 const bool IsTrulyNegation;
803
804 SmallDenseMap<Value *, Value *> NegationsCache;
805
806 Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT,
807 bool IsTrulyNegation);
808
809#if LLVM_ENABLE_STATS
810 unsigned NumValuesVisitedInThisNegator = 0;
811 ~Negator();
812#endif
813
814 using Result = std::pair<ArrayRef<Instruction *> /*NewInstructions*/,
815 Value * /*NegatedRoot*/>;
816
817 std::array<Value *, 2> getSortedOperandsOfBinOp(Instruction *I);
818
819 [[nodiscard]] Value *visitImpl(Value *V, bool IsNSW, unsigned Depth);
820
821 [[nodiscard]] Value *negate(Value *V, bool IsNSW, unsigned Depth);
822
823 /// Recurse depth-first and attempt to sink the negation.
824 /// FIXME: use worklist?
825 [[nodiscard]] std::optional<Result> run(Value *Root, bool IsNSW);
826
827 Negator(const Negator &) = delete;
828 Negator(Negator &&) = delete;
829 Negator &operator=(const Negator &) = delete;
830 Negator &operator=(Negator &&) = delete;
831
832public:
833 /// Attempt to negate \p Root. Retuns nullptr if negation can't be performed,
834 /// otherwise returns negated value.
835 [[nodiscard]] static Value *Negate(bool LHSIsZero, bool IsNSW, Value *Root,
836 InstCombinerImpl &IC);
837};
838
839} // end namespace llvm
840
841#undef DEBUG_TYPE
842
843#endif // LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool foldICmpWithDominatingICmp(CmpInst *Cmp, const TargetLowering &TLI)
For pattern like:
#define LLVM_LIBRARY_VISIBILITY
Definition: Compiler.h:133
static bool willNotOverflow(BinaryOpIntrinsic *BO, LazyValueInfo *LVI)
#define LLVM_DEBUG(...)
Definition: Debug.h:106
uint64_t Align
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int Opcode)
Hexagon Common GEP
IRTranslator LLVM IR MI
static constexpr unsigned NegatorMaxNodesSSO
static constexpr unsigned NegatorDefaultMaxDepth
This file provides the interface for the instcombine pass implementation.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
const uint64_t BitWidth
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const AddOperator *Add, const SimplifyQuery &SQ)
Value * RHS
Value * LHS
BinaryOperator * Mul
support::ulittle16_t & Lo
Definition: aarch32.cpp:204
support::ulittle16_t & Hi
Definition: aarch32.cpp:203
static const uint32_t IV[8]
Definition: blake3_impl.h:78
Class for arbitrary precision integers.
Definition: APInt.h:78
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
Definition: Instructions.h:63
This class represents any memset intrinsic.
A cache of @llvm.assume calls within a function.
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:704
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:177
This class represents a no-op cast from one type to another.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Conditional or Unconditional Branch instruction.
Analysis providing branch probability information.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:444
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:661
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:22
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
This instruction extracts a single (scalar) element from a VectorType value.
This instruction extracts a struct member or array element value from an aggregate value.
This instruction compares its operands according to the predicate given to the constructor.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
An instruction for ordering other memory operations.
Definition: Instructions.h:424
This class represents a freeze function that returns random concrete value if an operand is either a ...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:933
This instruction compares its operands according to the predicate given to the constructor.
This instruction inserts a single (scalar) element into a VectorType value.
This instruction inserts a struct field of array element value into an aggregate value.
Instruction * foldSelectToCmp(SelectInst &SI)
bool fmulByZeroIsZero(Value *MulVal, FastMathFlags FMF, const Instruction *CtxI) const
Check if fmul MulVal, +0.0 will yield +0.0 (or signed zero is ignorable).
virtual ~InstCombinerImpl()=default
KnownFPClass computeKnownFPClass(Value *Val, FastMathFlags FMF, FPClassTest Interested=fcAllFlags, const Instruction *CtxI=nullptr, unsigned Depth=0) const
Instruction * foldSelectEqualityTest(SelectInst &SI)
Instruction * foldSelectValueEquivalence(SelectInst &SI, CmpInst &CI)
InstCombinerImpl(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, BranchProbabilityInfo *BPI, ProfileSummaryInfo *PSI, const DataLayout &DL, ReversePostOrderTraversal< BasicBlock * > &RPOT)
Instruction * foldVectorSelect(SelectInst &Sel)
Instruction * foldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1, Value *A, Value *B, Instruction &Outer, SelectPatternFlavor SPF2, Value *C)
Constant * getLosslessUnsignedTrunc(Constant *C, Type *TruncTy)
bool replaceInInstruction(Value *V, Value *Old, Value *New, unsigned Depth=0)
Instruction * eraseInstFromFunction(Instruction &I) override
Combiner aware instruction erasure.
Instruction * foldSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI)
Constant * getLosslessTrunc(Constant *C, Type *TruncTy, unsigned ExtOp)
Instruction * visitInstruction(Instruction &I)
Specify what to return for unhandled instructions.
KnownFPClass computeKnownFPClass(Value *Val, FPClassTest Interested=fcAllFlags, const Instruction *CtxI=nullptr, unsigned Depth=0) const
Constant * getLosslessSignedTrunc(Constant *C, Type *TruncTy)
void CreateNonTerminatorUnreachable(Instruction *InsertAt)
Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the C...
Instruction * visitSelectInst(SelectInst &SI)
Instruction * foldSelectOfBools(SelectInst &SI)
Instruction * foldSelectExtConst(SelectInst &Sel)
The core instruction combiner logic.
Definition: InstCombiner.h:48
Base class for instruction visitors.
Definition: InstVisitor.h:78
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
This class represents a cast from an integer to a pointer.
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
Invoke instruction.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
Definition: Instructions.h:176
This class represents min/max intrinsics.
static Value * Negate(bool LHSIsZero, bool IsNSW, Value *Root, InstCombinerImpl &IC)
Attempt to negate Root.
The optimization diagnostic interface.
Analysis providing profile information.
This class represents a cast from a pointer to an integer.
Return a value (possibly void), from a function.
This class represents a sign extension of integer types.
This class represents the LLVM 'select' instruction.
This instruction constructs a fixed permutation of two input vectors.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
Multiway switch.
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This function has undefined behavior.
This represents the llvm.va_end intrinsic.
LLVM Value Representation.
Definition: Value.h:74
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1075
This class represents zero extension of integer types.
self_iterator getIterator()
Definition: ilist_node.h:132
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OverflowResult
void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
Definition: Utils.cpp:1683
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ, bool IsNSW=false)
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
SelectPatternFlavor
Specific patterns of select instructions we can match.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &SQ)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.