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 LoopInfo;
55class OptimizationRemarkEmitter;
56class ProfileSummaryInfo;
57class TargetLibraryInfo;
58class User;
59
61 : public InstCombiner,
62 public InstVisitor<InstCombinerImpl, Instruction *> {
63public:
65 bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
69 ProfileSummaryInfo *PSI, const DataLayout &DL, LoopInfo *LI)
70 : InstCombiner(Worklist, Builder, MinimizeSize, AA, AC, TLI, TTI, DT, ORE,
71 BFI, BPI, PSI, DL, LI) {}
72
73 virtual ~InstCombinerImpl() = default;
74
75 /// Perform early cleanup and prepare the InstCombine worklist.
76 bool prepareWorklist(Function &F,
78
79 /// Run the combiner over the entire worklist until it is empty.
80 ///
81 /// \returns true if the IR is changed.
82 bool run();
83
84 // Visitation implementation - Implement instruction combining for different
85 // instruction types. The semantics are as follows:
86 // Return Value:
87 // null - No change was made
88 // I - Change was made, I is still valid, I may be dead though
89 // otherwise - Change was made, replace I with returned instruction
90 //
91 Instruction *visitFNeg(UnaryOperator &I);
92 Instruction *visitAdd(BinaryOperator &I);
93 Instruction *visitFAdd(BinaryOperator &I);
94 Value *OptimizePointerDifference(
95 Value *LHS, Value *RHS, Type *Ty, bool isNUW);
96 Instruction *visitSub(BinaryOperator &I);
97 Instruction *visitFSub(BinaryOperator &I);
98 Instruction *visitMul(BinaryOperator &I);
99 Instruction *foldPowiReassoc(BinaryOperator &I);
100 Instruction *foldFMulReassoc(BinaryOperator &I);
101 Instruction *visitFMul(BinaryOperator &I);
102 Instruction *visitURem(BinaryOperator &I);
103 Instruction *visitSRem(BinaryOperator &I);
104 Instruction *visitFRem(BinaryOperator &I);
105 bool simplifyDivRemOfSelectWithZeroOp(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(ICmpInst *Cmp0, ICmpInst *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 Instruction *
430 canonicalizeConditionalNegationViaMathToSelect(BinaryOperator &i);
431
432 Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
433 Instruction *CxtI, bool IsAnd,
434 bool IsLogical = false);
435 Value *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D,
436 bool InvertFalseVal = false);
437 Value *getSelectCondition(Value *A, Value *B, bool ABIsTheSame);
438
439 Instruction *foldLShrOverflowBit(BinaryOperator &I);
440 Instruction *foldExtractOfOverflowIntrinsic(ExtractValueInst &EV);
441 Instruction *foldIntrinsicWithOverflowCommon(IntrinsicInst *II);
442 Instruction *foldIntrinsicIsFPClass(IntrinsicInst &II);
443 Instruction *foldFPSignBitOps(BinaryOperator &I);
444 Instruction *foldFDivConstantDivisor(BinaryOperator &I);
445
446 // Optimize one of these forms:
447 // and i1 Op, SI / select i1 Op, i1 SI, i1 false (if IsAnd = true)
448 // or i1 Op, SI / select i1 Op, i1 true, i1 SI (if IsAnd = false)
449 // into simplier select instruction using isImpliedCondition.
450 Instruction *foldAndOrOfSelectUsingImpliedCond(Value *Op, SelectInst &SI,
451 bool IsAnd);
452
453 Instruction *hoistFNegAboveFMulFDiv(Value *FNegOp, Instruction &FMFSource);
454
455public:
456 /// Create and insert the idiom we use to indicate a block is unreachable
457 /// without having to rewrite the CFG from within InstCombine.
459 auto &Ctx = InsertAt->getContext();
460 auto *SI = new StoreInst(ConstantInt::getTrue(Ctx),
461 PoisonValue::get(PointerType::getUnqual(Ctx)),
462 /*isVolatile*/ false, Align(1));
463 InsertNewInstWith(SI, InsertAt->getIterator());
464 }
465
466 /// Combiner aware instruction erasure.
467 ///
468 /// When dealing with an instruction that has side effects or produces a void
469 /// value, we can't rely on DCE to delete the instruction. Instead, visit
470 /// methods should return the value returned by this function.
472 LLVM_DEBUG(dbgs() << "IC: ERASE " << I << '\n');
473 assert(I.use_empty() && "Cannot erase instruction that is used!");
475
476 // Make sure that we reprocess all operands now that we reduced their
477 // use counts.
478 SmallVector<Value *> Ops(I.operands());
479 Worklist.remove(&I);
480 DC.removeValue(&I);
481 I.eraseFromParent();
482 for (Value *Op : Ops)
483 Worklist.handleUseCountDecrement(Op);
484 MadeIRChange = true;
485 return nullptr; // Don't do anything with FI
486 }
487
488 OverflowResult computeOverflow(
489 Instruction::BinaryOps BinaryOp, bool IsSigned,
490 Value *LHS, Value *RHS, Instruction *CxtI) const;
491
492 /// Performs a few simplifications for operators which are associative
493 /// or commutative.
494 bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
495
496 /// Tries to simplify binary operations which some other binary
497 /// operation distributes over.
498 ///
499 /// It does this by either by factorizing out common terms (eg "(A*B)+(A*C)"
500 /// -> "A*(B+C)") or expanding out if this results in simplifications (eg: "A
501 /// & (B | C) -> (A&B) | (A&C)" if this is a win). Returns the simplified
502 /// value, or null if it didn't simplify.
503 Value *foldUsingDistributiveLaws(BinaryOperator &I);
504
505 /// Tries to simplify add operations using the definition of remainder.
506 ///
507 /// The definition of remainder is X % C = X - (X / C ) * C. The add
508 /// expression X % C0 + (( X / C0 ) % C1) * C0 can be simplified to
509 /// X % (C0 * C1)
510 Value *SimplifyAddWithRemainder(BinaryOperator &I);
511
512 // Binary Op helper for select operations where the expression can be
513 // efficiently reorganized.
514 Value *SimplifySelectsFeedingBinaryOp(BinaryOperator &I, Value *LHS,
515 Value *RHS);
516
517 // If `I` has operand `(ctpop (not x))`, fold `I` with `(sub nuw nsw
518 // BitWidth(x), (ctpop x))`.
519 Instruction *tryFoldInstWithCtpopWithNot(Instruction *I);
520
521 // (Binop1 (Binop2 (logic_shift X, C), C1), (logic_shift Y, C))
522 // -> (logic_shift (Binop1 (Binop2 X, inv_logic_shift(C1, C)), Y), C)
523 // (Binop1 (Binop2 (logic_shift X, Amt), Mask), (logic_shift Y, Amt))
524 // -> (BinOp (logic_shift (BinOp X, Y)), Mask)
525 Instruction *foldBinOpShiftWithShift(BinaryOperator &I);
526
527 /// Tries to simplify binops of select and cast of the select condition.
528 ///
529 /// (Binop (cast C), (select C, T, F))
530 /// -> (select C, C0, C1)
531 Instruction *foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I);
532
533 /// This tries to simplify binary operations by factorizing out common terms
534 /// (e. g. "(A*B)+(A*C)" -> "A*(B+C)").
535 Value *tryFactorizationFolds(BinaryOperator &I);
536
537 /// Match a select chain which produces one of three values based on whether
538 /// the LHS is less than, equal to, or greater than RHS respectively.
539 /// Return true if we matched a three way compare idiom. The LHS, RHS, Less,
540 /// Equal and Greater values are saved in the matching process and returned to
541 /// the caller.
542 bool matchThreeWayIntCompare(SelectInst *SI, Value *&LHS, Value *&RHS,
543 ConstantInt *&Less, ConstantInt *&Equal,
544 ConstantInt *&Greater);
545
546 /// Attempts to replace I with a simpler value based on the demanded
547 /// bits.
548 Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask,
549 KnownBits &Known, unsigned Depth,
550 const SimplifyQuery &Q);
551 using InstCombiner::SimplifyDemandedBits;
552 bool SimplifyDemandedBits(Instruction *I, unsigned Op,
553 const APInt &DemandedMask, KnownBits &Known,
554 unsigned Depth, const SimplifyQuery &Q) override;
555
556 /// Helper routine of SimplifyDemandedUseBits. It computes KnownZero/KnownOne
557 /// bits. It also tries to handle simplifications that can be done based on
558 /// DemandedMask, but without modifying the Instruction.
559 Value *SimplifyMultipleUseDemandedBits(Instruction *I,
560 const APInt &DemandedMask,
561 KnownBits &Known, unsigned Depth,
562 const SimplifyQuery &Q);
563
564 /// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
565 /// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.
566 Value *simplifyShrShlDemandedBits(
567 Instruction *Shr, const APInt &ShrOp1, Instruction *Shl,
568 const APInt &ShlOp1, const APInt &DemandedMask, KnownBits &Known);
569
570 /// Tries to simplify operands to an integer instruction based on its
571 /// demanded bits.
572 bool SimplifyDemandedInstructionBits(Instruction &Inst);
573 bool SimplifyDemandedInstructionBits(Instruction &Inst, KnownBits &Known);
574
575 Value *SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
576 APInt &PoisonElts, unsigned Depth = 0,
577 bool AllowMultipleUsers = false) override;
578
579 /// Attempts to replace V with a simpler value based on the demanded
580 /// floating-point classes
581 Value *SimplifyDemandedUseFPClass(Value *V, FPClassTest DemandedMask,
582 KnownFPClass &Known, unsigned Depth,
583 Instruction *CxtI);
584 bool SimplifyDemandedFPClass(Instruction *I, unsigned Op,
585 FPClassTest DemandedMask, KnownFPClass &Known,
586 unsigned Depth = 0);
587
588 /// Canonicalize the position of binops relative to shufflevector.
589 Instruction *foldVectorBinop(BinaryOperator &Inst);
591 Instruction *foldSelectShuffle(ShuffleVectorInst &Shuf);
592
593 /// Given a binary operator, cast instruction, or select which has a PHI node
594 /// as operand #0, see if we can fold the instruction into the PHI (which is
595 /// only possible if all operands to the PHI are constants).
596 Instruction *foldOpIntoPhi(Instruction &I, PHINode *PN);
597
598 /// For a binary operator with 2 phi operands, try to hoist the binary
599 /// operation before the phi. This can result in fewer instructions in
600 /// patterns where at least one set of phi operands simplifies.
601 /// Example:
602 /// BB3: binop (phi [X, BB1], [C1, BB2]), (phi [Y, BB1], [C2, BB2])
603 /// -->
604 /// BB1: BO = binop X, Y
605 /// BB3: phi [BO, BB1], [(binop C1, C2), BB2]
606 Instruction *foldBinopWithPhiOperands(BinaryOperator &BO);
607
608 /// Given an instruction with a select as one operand and a constant as the
609 /// other operand, try to fold the binary operator into the select arguments.
610 /// This also works for Cast instructions, which obviously do not have a
611 /// second operand.
612 Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
613 bool FoldWithMultiUse = false);
614
615 /// This is a convenience wrapper function for the above two functions.
616 Instruction *foldBinOpIntoSelectOrPhi(BinaryOperator &I);
617
618 Instruction *foldAddWithConstant(BinaryOperator &Add);
619
620 Instruction *foldSquareSumInt(BinaryOperator &I);
621 Instruction *foldSquareSumFP(BinaryOperator &I);
622
623 /// Try to rotate an operation below a PHI node, using PHI nodes for
624 /// its operands.
625 Instruction *foldPHIArgOpIntoPHI(PHINode &PN);
626 Instruction *foldPHIArgBinOpIntoPHI(PHINode &PN);
627 Instruction *foldPHIArgInsertValueInstructionIntoPHI(PHINode &PN);
628 Instruction *foldPHIArgExtractValueInstructionIntoPHI(PHINode &PN);
629 Instruction *foldPHIArgGEPIntoPHI(PHINode &PN);
630 Instruction *foldPHIArgLoadIntoPHI(PHINode &PN);
631 Instruction *foldPHIArgZextsIntoPHI(PHINode &PN);
632 Instruction *foldPHIArgIntToPtrToPHI(PHINode &PN);
633
634 /// If an integer typed PHI has only one use which is an IntToPtr operation,
635 /// replace the PHI with an existing pointer typed PHI if it exists. Otherwise
636 /// insert a new pointer typed PHI and replace the original one.
637 bool foldIntegerTypedPHI(PHINode &PN);
638
639 /// Helper function for FoldPHIArgXIntoPHI() to set debug location for the
640 /// folded operation.
641 void PHIArgMergedDebugLoc(Instruction *Inst, PHINode &PN);
642
643 Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
645 Instruction *foldSelectICmp(ICmpInst::Predicate Pred, SelectInst *SI,
646 Value *RHS, const ICmpInst &I);
647 bool foldAllocaCmp(AllocaInst *Alloca);
648 Instruction *foldCmpLoadFromIndexedGlobal(LoadInst *LI,
650 GlobalVariable *GV, CmpInst &ICI,
651 ConstantInt *AndCst = nullptr);
652 Instruction *foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
653 Constant *RHSC);
654 Instruction *foldICmpAddOpConst(Value *X, const APInt &C,
656 Instruction *foldICmpWithCastOp(ICmpInst &ICmp);
657 Instruction *foldICmpWithZextOrSext(ICmpInst &ICmp);
658
659 Instruction *foldICmpUsingKnownBits(ICmpInst &Cmp);
661 Instruction *foldICmpWithConstant(ICmpInst &Cmp);
662 Instruction *foldICmpUsingBoolRange(ICmpInst &I);
663 Instruction *foldICmpInstWithConstant(ICmpInst &Cmp);
664 Instruction *foldICmpInstWithConstantNotInt(ICmpInst &Cmp);
665 Instruction *foldICmpInstWithConstantAllowPoison(ICmpInst &Cmp,
666 const APInt &C);
667 Instruction *foldICmpBinOp(ICmpInst &Cmp, const SimplifyQuery &SQ);
668 Instruction *foldICmpWithMinMax(Instruction &I, MinMaxIntrinsic *MinMax,
669 Value *Z, ICmpInst::Predicate Pred);
670 Instruction *foldICmpEquality(ICmpInst &Cmp);
671 Instruction *foldIRemByPowerOfTwoToBitTest(ICmpInst &I);
672 Instruction *foldSignBitTest(ICmpInst &I);
673 Instruction *foldICmpWithZero(ICmpInst &Cmp);
674
675 Value *foldMultiplicationOverflowCheck(ICmpInst &Cmp);
676
677 Instruction *foldICmpBinOpWithConstant(ICmpInst &Cmp, BinaryOperator *BO,
678 const APInt &C);
679 Instruction *foldICmpSelectConstant(ICmpInst &Cmp, SelectInst *Select,
680 ConstantInt *C);
681 Instruction *foldICmpTruncConstant(ICmpInst &Cmp, TruncInst *Trunc,
682 const APInt &C);
683 Instruction *foldICmpTruncWithTruncOrExt(ICmpInst &Cmp,
684 const SimplifyQuery &Q);
685 Instruction *foldICmpAndConstant(ICmpInst &Cmp, BinaryOperator *And,
686 const APInt &C);
687 Instruction *foldICmpXorConstant(ICmpInst &Cmp, BinaryOperator *Xor,
688 const APInt &C);
689 Instruction *foldICmpOrConstant(ICmpInst &Cmp, BinaryOperator *Or,
690 const APInt &C);
691 Instruction *foldICmpMulConstant(ICmpInst &Cmp, BinaryOperator *Mul,
692 const APInt &C);
693 Instruction *foldICmpShlConstant(ICmpInst &Cmp, BinaryOperator *Shl,
694 const APInt &C);
695 Instruction *foldICmpShrConstant(ICmpInst &Cmp, BinaryOperator *Shr,
696 const APInt &C);
697 Instruction *foldICmpSRemConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
698 const APInt &C);
699 Instruction *foldICmpUDivConstant(ICmpInst &Cmp, BinaryOperator *UDiv,
700 const APInt &C);
701 Instruction *foldICmpDivConstant(ICmpInst &Cmp, BinaryOperator *Div,
702 const APInt &C);
703 Instruction *foldICmpSubConstant(ICmpInst &Cmp, BinaryOperator *Sub,
704 const APInt &C);
705 Instruction *foldICmpAddConstant(ICmpInst &Cmp, BinaryOperator *Add,
706 const APInt &C);
707 Instruction *foldICmpAndConstConst(ICmpInst &Cmp, BinaryOperator *And,
708 const APInt &C1);
709 Instruction *foldICmpAndShift(ICmpInst &Cmp, BinaryOperator *And,
710 const APInt &C1, const APInt &C2);
711 Instruction *foldICmpXorShiftConst(ICmpInst &Cmp, BinaryOperator *Xor,
712 const APInt &C);
713 Instruction *foldICmpShrConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
714 const APInt &C2);
715 Instruction *foldICmpShlConstConst(ICmpInst &I, Value *ShAmt, const APInt &C1,
716 const APInt &C2);
717
718 Instruction *foldICmpBinOpEqualityWithConstant(ICmpInst &Cmp,
719 BinaryOperator *BO,
720 const APInt &C);
721 Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI, IntrinsicInst *II,
722 const APInt &C);
723 Instruction *foldICmpEqIntrinsicWithConstant(ICmpInst &ICI, IntrinsicInst *II,
724 const APInt &C);
725 Instruction *foldICmpBitCast(ICmpInst &Cmp);
726 Instruction *foldICmpWithTrunc(ICmpInst &Cmp);
727 Instruction *foldICmpCommutative(ICmpInst::Predicate Pred, Value *Op0,
728 Value *Op1, ICmpInst &CxtI);
729
730 // Helpers of visitSelectInst().
734 Instruction *foldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI);
735 Instruction *foldSelectIntoOp(SelectInst &SI, Value *, Value *);
737 Value *A, Value *B, Instruction &Outer,
742 unsigned Depth = 0);
743
744 Value *insertRangeTest(Value *V, const APInt &Lo, const APInt &Hi,
745 bool isSigned, bool Inside);
746 bool mergeStoreIntoSuccessor(StoreInst &SI);
747
748 /// Given an initial instruction, check to see if it is the root of a
749 /// bswap/bitreverse idiom. If so, return the equivalent bswap/bitreverse
750 /// intrinsic.
751 Instruction *matchBSwapOrBitReverse(Instruction &I, bool MatchBSwaps,
752 bool MatchBitReversals);
753
754 Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI);
755 Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI);
756
757 Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned);
758
759 bool tryToSinkInstruction(Instruction *I, BasicBlock *DestBlock);
760 void tryToSinkInstructionDbgValues(
761 Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
763 void tryToSinkInstructionDbgVariableRecords(
764 Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
766
767 bool removeInstructionsBeforeUnreachable(Instruction &I);
768 void addDeadEdge(BasicBlock *From, BasicBlock *To,
770 void handleUnreachableFrom(Instruction *I,
772 void handlePotentiallyDeadBlocks(SmallVectorImpl<BasicBlock *> &Worklist);
773 void handlePotentiallyDeadSuccessors(BasicBlock *BB, BasicBlock *LiveSucc);
774 void freelyInvertAllUsersOf(Value *V, Value *IgnoredUser = nullptr);
775};
776
777class Negator final {
778 /// Top-to-bottom, def-to-use negated instruction tree we produced.
780
782 BuilderTy Builder;
783
784 const DominatorTree &DT;
785
786 const bool IsTrulyNegation;
787
788 SmallDenseMap<Value *, Value *> NegationsCache;
789
790 Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT,
791 bool IsTrulyNegation);
792
793#if LLVM_ENABLE_STATS
794 unsigned NumValuesVisitedInThisNegator = 0;
795 ~Negator();
796#endif
797
798 using Result = std::pair<ArrayRef<Instruction *> /*NewInstructions*/,
799 Value * /*NegatedRoot*/>;
800
801 std::array<Value *, 2> getSortedOperandsOfBinOp(Instruction *I);
802
803 [[nodiscard]] Value *visitImpl(Value *V, bool IsNSW, unsigned Depth);
804
805 [[nodiscard]] Value *negate(Value *V, bool IsNSW, unsigned Depth);
806
807 /// Recurse depth-first and attempt to sink the negation.
808 /// FIXME: use worklist?
809 [[nodiscard]] std::optional<Result> run(Value *Root, bool IsNSW);
810
811 Negator(const Negator &) = delete;
812 Negator(Negator &&) = delete;
813 Negator &operator=(const Negator &) = delete;
814 Negator &operator=(Negator &&) = delete;
815
816public:
817 /// Attempt to negate \p Root. Retuns nullptr if negation can't be performed,
818 /// otherwise returns negated value.
819 [[nodiscard]] static Value *Negate(bool LHSIsZero, bool IsNSW, Value *Root,
820 InstCombinerImpl &IC);
821};
822
823} // end namespace llvm
824
825#undef DEBUG_TYPE
826
827#endif // LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
amdgpu 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:127
static bool willNotOverflow(BinaryOpIntrinsic *BO, LazyValueInfo *LVI)
#define LLVM_DEBUG(X)
Definition: Debug.h:101
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
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:206
support::ulittle16_t & Hi
Definition: aarch32.cpp:205
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:61
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:696
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:1236
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:530
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:747
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:757
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
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:420
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:915
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 * foldVectorSelect(SelectInst &Sel)
Instruction * foldSelectValueEquivalence(SelectInst &SI, ICmpInst &ICI)
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)
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, LoopInfo *LI)
The core instruction combiner logic.
Definition: InstCombiner.h:47
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:174
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:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
An instruction for storing to memory.
Definition: Instructions.h:290
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:1678
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.