LLVM 24.0.0git
TruncInstCombine.cpp
Go to the documentation of this file.
1//===- TruncInstCombine.cpp -----------------------------------------------===//
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// TruncInstCombine - looks for expression graphs post-dominated by TruncInst
10// and for each eligible graph, it will create a reduced bit-width expression,
11// replace the old expression with this new one and remove the old expression.
12// Eligible expression graph is such that:
13// 1. Contains only supported instructions.
14// 2. Supported leaves: ZExtInst, SExtInst, TruncInst and Constant value.
15// 3. Can be evaluated into type with reduced legal bit-width.
16// 4. All instructions in the graph must not have users outside the graph.
17// The only exception is for {ZExt, SExt}Inst with operand type equal to
18// the new reduced type evaluated in (3).
19//
20// The motivation for this optimization is that evaluating and expression using
21// smaller bit-width is preferable, especially for vectorization where we can
22// fit more values in one vectorized instruction. In addition, this optimization
23// may decrease the number of cast instructions, but will not increase it.
24//
25//===----------------------------------------------------------------------===//
26
28#include "llvm/ADT/STLExtras.h"
29#include "llvm/ADT/Statistic.h"
31#include "llvm/IR/DataLayout.h"
32#include "llvm/IR/Dominators.h"
33#include "llvm/IR/IRBuilder.h"
34#include "llvm/IR/Instruction.h"
36
37using namespace llvm;
38
39#define DEBUG_TYPE "aggressive-instcombine"
40
41STATISTIC(NumExprsReduced, "Number of truncations eliminated by reducing bit "
42 "width of expression graph");
43STATISTIC(NumInstrsReduced,
44 "Number of instructions whose bit width was reduced");
45
46/// Return whether operand \p OpNo of \p I is reducible.
47static bool isRelevantOperand(const Instruction *I, unsigned OpNo) {
48 unsigned Opc = I->getOpcode();
49 switch (Opc) {
50 case Instruction::Trunc:
51 case Instruction::ZExt:
52 case Instruction::SExt:
53 // These CastInst are considered leaves of the evaluated expression, thus,
54 // their operands are not relevent.
55 return false;
56 case Instruction::Add:
57 case Instruction::Sub:
58 case Instruction::Mul:
59 case Instruction::And:
60 case Instruction::Or:
61 case Instruction::Xor:
62 case Instruction::Shl:
63 case Instruction::LShr:
64 case Instruction::AShr:
65 case Instruction::UDiv:
66 case Instruction::URem:
67 return true;
68 case Instruction::InsertElement:
69 return OpNo < 2;
70 case Instruction::ExtractElement:
71 return OpNo == 0;
72 case Instruction::Select:
73 return OpNo != 0;
74 case Instruction::PHI:
75 return true;
76 case Instruction::ShuffleVector:
77 return true;
78 default:
79 llvm_unreachable("Unreachable!");
80 }
81}
82
83/// Given an instruction and a container, it fills all the relevant operands of
84/// that instruction, with respect to the Trunc expression graph optimizaton.
86 for (Use &Op : I->operands())
87 if (isRelevantOperand(I, Op.getOperandNo()))
88 Ops.push_back(Op.get());
89}
90
91bool TruncInstCombine::buildTruncExpressionGraph() {
92 SmallVector<Value *, 8> Worklist;
93 SmallVector<Instruction *, 8> Stack;
94 // Clear old instructions info.
95 InstInfoMap.clear();
96
97 Worklist.push_back(CurrentTruncInst->getOperand(0));
98
99 while (!Worklist.empty()) {
100 Value *Curr = Worklist.back();
101
102 if (isa<Constant>(Curr)) {
103 Worklist.pop_back();
104 continue;
105 }
106
107 auto *I = dyn_cast<Instruction>(Curr);
108 if (!I)
109 return false;
110
111 if (!Stack.empty() && Stack.back() == I) {
112 // Already handled all instruction operands, can remove it from both the
113 // Worklist and the Stack, and add it to the instruction info map.
114 Worklist.pop_back();
115 Stack.pop_back();
116 // Insert I to the Info map.
117 InstInfoMap.try_emplace(I);
118 continue;
119 }
120
121 if (InstInfoMap.count(I)) {
122 Worklist.pop_back();
123 continue;
124 }
125
126 // Add the instruction to the stack before start handling its operands.
127 Stack.push_back(I);
128
129 unsigned Opc = I->getOpcode();
130 switch (Opc) {
131 case Instruction::Trunc:
132 case Instruction::ZExt:
133 case Instruction::SExt:
134 // trunc(trunc(x)) -> trunc(x)
135 // trunc(ext(x)) -> ext(x) if the source type is smaller than the new dest
136 // trunc(ext(x)) -> trunc(x) if the source type is larger than the new
137 // dest
138 break;
139 case Instruction::Add:
140 case Instruction::Sub:
141 case Instruction::Mul:
142 case Instruction::And:
143 case Instruction::Or:
144 case Instruction::Xor:
145 case Instruction::Shl:
146 case Instruction::LShr:
147 case Instruction::AShr:
148 case Instruction::UDiv:
149 case Instruction::URem:
150 case Instruction::InsertElement:
151 case Instruction::ExtractElement:
152 case Instruction::Select:
153 case Instruction::ShuffleVector: {
154 SmallVector<Value *, 2> Operands;
156 append_range(Worklist, Operands);
157 break;
158 }
159 case Instruction::PHI: {
160 SmallVector<Value *, 2> Operands;
162 // Add only operands not in Stack to prevent cycle
163 for (auto *Op : Operands)
164 if (!llvm::is_contained(Stack, Op))
165 Worklist.push_back(Op);
166 break;
167 }
168 default:
169 // TODO: Can handle more cases here:
170 // 1. sdiv, srem
171 // ...
172 return false;
173 }
174 }
175 return true;
176}
177
178unsigned TruncInstCombine::getMinBitWidth() {
179 SmallVector<Value *, 8> Worklist;
180 SmallVector<Instruction *, 8> Stack;
181
182 Value *Src = CurrentTruncInst->getOperand(0);
183 Type *DstTy = CurrentTruncInst->getType();
184 unsigned TruncBitWidth = DstTy->getScalarSizeInBits();
185 unsigned OrigBitWidth =
186 CurrentTruncInst->getOperand(0)->getType()->getScalarSizeInBits();
187
188 if (isa<Constant>(Src))
189 return TruncBitWidth;
190
191 Worklist.push_back(Src);
192 InstInfoMap[cast<Instruction>(Src)].ValidBitWidth = TruncBitWidth;
193
194 while (!Worklist.empty()) {
195 Value *Curr = Worklist.back();
196
197 if (isa<Constant>(Curr)) {
198 Worklist.pop_back();
199 continue;
200 }
201
202 // Otherwise, it must be an instruction.
203 auto *I = cast<Instruction>(Curr);
204
205 auto &Info = InstInfoMap[I];
206
207 SmallVector<Value *, 2> Operands;
209
210 if (!Stack.empty() && Stack.back() == I) {
211 // Already handled all instruction operands, can remove it from both, the
212 // Worklist and the Stack, and update MinBitWidth.
213 Worklist.pop_back();
214 Stack.pop_back();
215 for (auto *Operand : Operands)
216 if (auto *IOp = dyn_cast<Instruction>(Operand))
217 Info.MinBitWidth =
218 std::max(Info.MinBitWidth, InstInfoMap[IOp].MinBitWidth);
219 continue;
220 }
221
222 // Add the instruction to the stack before start handling its operands.
223 Stack.push_back(I);
224 unsigned ValidBitWidth = Info.ValidBitWidth;
225
226 // Update minimum bit-width before handling its operands. This is required
227 // when the instruction is part of a loop.
228 Info.MinBitWidth = std::max(Info.MinBitWidth, Info.ValidBitWidth);
229
230 for (auto *Operand : Operands)
231 if (auto *IOp = dyn_cast<Instruction>(Operand)) {
232 // If we already calculated the minimum bit-width for this valid
233 // bit-width, or for a smaller valid bit-width, then just keep the
234 // answer we already calculated.
235 unsigned IOpBitwidth = InstInfoMap.lookup(IOp).ValidBitWidth;
236 if (IOpBitwidth >= ValidBitWidth)
237 continue;
238 InstInfoMap[IOp].ValidBitWidth = ValidBitWidth;
239 Worklist.push_back(IOp);
240 }
241 }
242 unsigned MinBitWidth = InstInfoMap.lookup(cast<Instruction>(Src)).MinBitWidth;
243 assert(MinBitWidth >= TruncBitWidth);
244
245 if (MinBitWidth > TruncBitWidth) {
246 // In this case reducing expression with vector type might generate a new
247 // vector type, which is not preferable as it might result in generating
248 // sub-optimal code.
249 if (DstTy->isVectorTy())
250 return OrigBitWidth;
251 // Use the smallest integer type in the range [MinBitWidth, OrigBitWidth).
252 Type *Ty = DL.getSmallestLegalIntType(DstTy->getContext(), MinBitWidth);
253 // Update minimum bit-width with the new destination type bit-width if
254 // succeeded to find such, otherwise, with original bit-width.
255 MinBitWidth = Ty ? Ty->getScalarSizeInBits() : OrigBitWidth;
256 } else { // MinBitWidth == TruncBitWidth
257 // In this case the expression can be evaluated with the trunc instruction
258 // destination type, and trunc instruction can be omitted. However, we
259 // should not perform the evaluation if the original type is a legal scalar
260 // type and the target type is illegal.
261 bool FromLegal = MinBitWidth == 1 || DL.isLegalInteger(OrigBitWidth);
262 bool ToLegal = MinBitWidth == 1 || DL.isLegalInteger(MinBitWidth);
263 if (!DstTy->isVectorTy() && FromLegal && !ToLegal)
264 return OrigBitWidth;
265 }
266 return MinBitWidth;
267}
268
269Type *TruncInstCombine::getBestTruncatedType() {
270 if (!buildTruncExpressionGraph())
271 return nullptr;
272
273 // We don't want to duplicate instructions, which isn't profitable. Thus, we
274 // can't shrink something that has multiple uses, unless all uses can be
275 // reduced and all users are post-dominated by the trunc instruction,
276 // i.e., were visited during the expression evaluation.
277 unsigned DesiredBitWidth = 0;
278 for (auto Itr : InstInfoMap) {
279 Instruction *I = Itr.first;
280 if (I->hasOneUse())
281 continue;
282 bool IsExtInst = (isa<ZExtInst>(I) || isa<SExtInst>(I));
283 for (Use &U : I->uses())
284 if (auto *UI = dyn_cast<Instruction>(U.getUser()))
285 if (UI != CurrentTruncInst &&
286 (!InstInfoMap.count(UI) ||
287 !isRelevantOperand(UI, U.getOperandNo()))) {
288 if (!IsExtInst)
289 return nullptr;
290 // If this is an extension from the dest type, we can eliminate it,
291 // even if it has multiple users. Thus, update the DesiredBitWidth and
292 // validate all extension instructions agrees on same DesiredBitWidth.
293 unsigned ExtInstBitWidth =
294 I->getOperand(0)->getType()->getScalarSizeInBits();
295 if (DesiredBitWidth && DesiredBitWidth != ExtInstBitWidth)
296 return nullptr;
297 DesiredBitWidth = ExtInstBitWidth;
298 }
299 }
300
301 unsigned OrigBitWidth =
302 CurrentTruncInst->getOperand(0)->getType()->getScalarSizeInBits();
303
304 // Initialize MinBitWidth for shift instructions with the minimum number
305 // that is greater than shift amount (i.e. shift amount + 1).
306 // For `lshr` adjust MinBitWidth so that all potentially truncated
307 // bits of the value-to-be-shifted are zeros.
308 // For `ashr` adjust MinBitWidth so that all potentially truncated
309 // bits of the value-to-be-shifted are sign bits (all zeros or ones)
310 // and even one (first) untruncated bit is sign bit.
311 // Exit early if MinBitWidth is not less than original bitwidth.
312 for (auto &Itr : InstInfoMap) {
313 Instruction *I = Itr.first;
314 if (I->isShift()) {
315 KnownBits KnownRHS = computeKnownBits(I->getOperand(1));
316 unsigned MinBitWidth = KnownRHS.getMaxValue()
317 .uadd_sat(APInt(OrigBitWidth, 1))
318 .getLimitedValue(OrigBitWidth);
319 if (MinBitWidth == OrigBitWidth)
320 return nullptr;
321 if (I->getOpcode() == Instruction::LShr) {
322 KnownBits KnownLHS = computeKnownBits(I->getOperand(0));
323 MinBitWidth =
324 std::max(MinBitWidth, KnownLHS.getMaxValue().getActiveBits());
325 }
326 if (I->getOpcode() == Instruction::AShr) {
327 unsigned NumSignBits = ComputeNumSignBits(I->getOperand(0));
328 MinBitWidth = std::max(MinBitWidth, OrigBitWidth - NumSignBits + 1);
329 }
330 if (MinBitWidth >= OrigBitWidth)
331 return nullptr;
332 Itr.second.MinBitWidth = MinBitWidth;
333 }
334 if (I->getOpcode() == Instruction::UDiv ||
335 I->getOpcode() == Instruction::URem) {
336 unsigned MinBitWidth = 0;
337 for (const auto &Op : I->operands()) {
338 KnownBits Known = computeKnownBits(Op);
339 MinBitWidth =
340 std::max(Known.getMaxValue().getActiveBits(), MinBitWidth);
341 if (MinBitWidth >= OrigBitWidth)
342 return nullptr;
343 }
344 Itr.second.MinBitWidth = MinBitWidth;
345 }
346 }
347
348 // Calculate minimum allowed bit-width allowed for shrinking the currently
349 // visited truncate's operand.
350 unsigned MinBitWidth = getMinBitWidth();
351
352 // Check that we can shrink to smaller bit-width than original one and that
353 // it is similar to the DesiredBitWidth is such exists.
354 if (MinBitWidth >= OrigBitWidth ||
355 (DesiredBitWidth && DesiredBitWidth != MinBitWidth))
356 return nullptr;
357 return IntegerType::get(CurrentTruncInst->getContext(), MinBitWidth);
358}
359
360/// Given a reduced scalar type \p Ty and a \p V value, return a reduced type
361/// for \p V, according to its type, if it vector type, return the vector
362/// version of \p Ty, otherwise return \p Ty.
363static Type *getReducedType(Value *V, Type *Ty) {
364 assert(Ty && !Ty->isVectorTy() && "Expect Scalar Type");
365 if (auto *VTy = dyn_cast<VectorType>(V->getType()))
366 return VectorType::get(Ty, VTy->getElementCount());
367 return Ty;
368}
369
370Value *TruncInstCombine::getReducedOperand(Value *V, Type *SclTy) {
371 Type *Ty = getReducedType(V, SclTy);
372 if (auto *C = dyn_cast<Constant>(V)) {
374 // If we got a constantexpr back, try to simplify it with DL info.
375 return ConstantFoldConstant(C, DL, &TLI);
376 }
377
378 auto *I = cast<Instruction>(V);
379 Info Entry = InstInfoMap.lookup(I);
380 assert(Entry.NewValue);
381 return Entry.NewValue;
382}
383
384void TruncInstCombine::ReduceExpressionGraph(Type *SclTy) {
385 NumInstrsReduced += InstInfoMap.size();
386 // Pairs of old and new phi-nodes
388 for (auto &Itr : InstInfoMap) { // Forward
389 Instruction *I = Itr.first;
390 TruncInstCombine::Info &NodeInfo = Itr.second;
391
392 assert(!NodeInfo.NewValue && "Instruction has been evaluated");
393
394 IRBuilder<> Builder(I);
395 Value *Res = nullptr;
396 unsigned Opc = I->getOpcode();
397 switch (Opc) {
398 case Instruction::Trunc:
399 case Instruction::ZExt:
400 case Instruction::SExt: {
401 Type *Ty = getReducedType(I, SclTy);
402 // If the source type of the cast is the type we're trying for then we can
403 // just return the source. There's no need to insert it because it is not
404 // new.
405 if (I->getOperand(0)->getType() == Ty) {
406 assert(!isa<TruncInst>(I) && "Cannot reach here with TruncInst");
407 NodeInfo.NewValue = I->getOperand(0);
408 continue;
409 }
410 // Otherwise, must be the same type of cast, so just reinsert a new one.
411 // This also handles the case of zext(trunc(x)) -> zext(x).
412 Res = Builder.CreateIntCast(I->getOperand(0), Ty,
413 Opc == Instruction::SExt);
414
415 // Update Worklist entries with new value if needed.
416 // There are three possible changes to the Worklist:
417 // 1. Update Old-TruncInst -> New-TruncInst.
418 // 2. Remove Old-TruncInst (if New node is not TruncInst).
419 // 3. Add New-TruncInst (if Old node was not TruncInst).
420 auto *Entry = find(Worklist, I);
421 if (Entry != Worklist.end()) {
422 if (auto *NewCI = dyn_cast<TruncInst>(Res))
423 *Entry = NewCI;
424 else
425 Worklist.erase(Entry);
426 } else if (auto *NewCI = dyn_cast<TruncInst>(Res))
427 Worklist.push_back(NewCI);
428 break;
429 }
430 case Instruction::Add:
431 case Instruction::Sub:
432 case Instruction::Mul:
433 case Instruction::And:
434 case Instruction::Or:
435 case Instruction::Xor:
436 case Instruction::Shl:
437 case Instruction::LShr:
438 case Instruction::AShr:
439 case Instruction::UDiv:
440 case Instruction::URem: {
441 Value *LHS = getReducedOperand(I->getOperand(0), SclTy);
442 Value *RHS = getReducedOperand(I->getOperand(1), SclTy);
443 Res = Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS);
444 // Preserve `exact` flag since truncation doesn't change exactness
445 if (auto *PEO = dyn_cast<PossiblyExactOperator>(I))
446 if (auto *ResI = dyn_cast<Instruction>(Res))
447 ResI->setIsExact(PEO->isExact());
448 break;
449 }
450 case Instruction::ExtractElement: {
451 Value *Vec = getReducedOperand(I->getOperand(0), SclTy);
452 Value *Idx = I->getOperand(1);
453 Res = Builder.CreateExtractElement(Vec, Idx);
454 break;
455 }
456 case Instruction::InsertElement: {
457 Value *Vec = getReducedOperand(I->getOperand(0), SclTy);
458 Value *NewElt = getReducedOperand(I->getOperand(1), SclTy);
459 Value *Idx = I->getOperand(2);
460 Res = Builder.CreateInsertElement(Vec, NewElt, Idx);
461 break;
462 }
463 case Instruction::Select: {
464 Value *Op0 = I->getOperand(0);
465 Value *LHS = getReducedOperand(I->getOperand(1), SclTy);
466 Value *RHS = getReducedOperand(I->getOperand(2), SclTy);
467 Res = Builder.CreateSelect(Op0, LHS, RHS, "", I);
468 break;
469 }
470 case Instruction::ShuffleVector: {
471 Value *LHS = getReducedOperand(I->getOperand(0), SclTy);
472 Value *RHS = getReducedOperand(I->getOperand(1), SclTy);
474 Res = Builder.CreateShuffleVector(LHS, RHS, SI->getShuffleMask());
475 break;
476 }
477 case Instruction::PHI: {
478 Res = Builder.CreatePHI(getReducedType(I, SclTy), I->getNumOperands());
479 OldNewPHINodes.push_back(
480 std::make_pair(cast<PHINode>(I), cast<PHINode>(Res)));
481 break;
482 }
483 default:
484 llvm_unreachable("Unhandled instruction");
485 }
486
487 NodeInfo.NewValue = Res;
488 if (auto *ResI = dyn_cast<Instruction>(Res))
489 ResI->takeName(I);
490 }
491
492 for (auto &Node : OldNewPHINodes) {
493 PHINode *OldPN = Node.first;
494 PHINode *NewPN = Node.second;
495 for (auto Incoming : zip(OldPN->incoming_values(), OldPN->blocks()))
496 NewPN->addIncoming(getReducedOperand(std::get<0>(Incoming), SclTy),
497 std::get<1>(Incoming));
498 }
499
500 Value *Res = getReducedOperand(CurrentTruncInst->getOperand(0), SclTy);
501 Type *DstTy = CurrentTruncInst->getType();
502 if (Res->getType() != DstTy) {
503 IRBuilder<> Builder(CurrentTruncInst);
504 Res = Builder.CreateIntCast(Res, DstTy, false);
505 if (auto *ResI = dyn_cast<Instruction>(Res))
506 ResI->takeName(CurrentTruncInst);
507 }
508 CurrentTruncInst->replaceAllUsesWith(Res);
509
510 // Erase old expression graph, which was replaced by the reduced expression
511 // graph.
512 CurrentTruncInst->eraseFromParent();
513 // First, erase old phi-nodes and its uses
514 for (auto &Node : OldNewPHINodes) {
515 PHINode *OldPN = Node.first;
517 InstInfoMap.erase(OldPN);
518 OldPN->eraseFromParent();
519 }
520 // Now we have expression graph turned into dag.
521 // We iterate backward, which means we visit the instruction before we
522 // visit any of its operands, this way, when we get to the operand, we already
523 // removed the instructions (from the expression dag) that uses it.
524 for (auto &I : llvm::reverse(InstInfoMap)) {
525 // We still need to check that the instruction has no users before we erase
526 // it, because {SExt, ZExt}Inst Instruction might have other users that was
527 // not reduced, in such case, we need to keep that instruction.
528 if (I.first->use_empty())
529 I.first->eraseFromParent();
530 else
531 assert((isa<SExtInst>(I.first) || isa<ZExtInst>(I.first)) &&
532 "Only {SExt, ZExt}Inst might have unreduced users");
533 }
534}
535
537 bool MadeIRChange = false;
538
539 // Collect all TruncInst in the function into the Worklist for evaluating.
540 for (auto &BB : F) {
541 // Ignore unreachable basic block.
542 if (!DT.isReachableFromEntry(&BB))
543 continue;
544 for (auto &I : BB)
545 if (auto *CI = dyn_cast<TruncInst>(&I))
546 Worklist.push_back(CI);
547 }
548
549 // Process all TruncInst in the Worklist, for each instruction:
550 // 1. Check if it dominates an eligible expression graph to be reduced.
551 // 2. Create a reduced expression graph and replace the old one with it.
552 while (!Worklist.empty()) {
553 CurrentTruncInst = Worklist.pop_back_val();
554
555 if (Type *NewDstSclTy = getBestTruncatedType()) {
557 dbgs() << "ICE: TruncInstCombine reducing type of expression graph "
558 "dominated by: "
559 << CurrentTruncInst << '\n');
560 ReduceExpressionGraph(NewDstSclTy);
561 ++NumExprsReduced;
562 MadeIRChange = true;
563 }
564 }
565
566 return MadeIRChange;
567}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
SI Fold Operands
This file contains some templates that are useful if you are working with the STL at all.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
static Type * getReducedType(Value *V, Type *Ty)
Given a reduced scalar type Ty and a V value, return a reduced type for V, according to its type,...
static void getRelevantOperands(Instruction *I, SmallVectorImpl< Value * > &Ops)
Given an instruction and a container, it fills all the relevant operands of that instruction,...
static bool isRelevantOperand(const Instruction *I, unsigned OpNo)
Return whether operand OpNo of I is reducible.
Value * RHS
Value * LHS
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition APInt.h:1533
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:472
LLVM_ABI APInt uadd_sat(const APInt &RHS) const
Definition APInt.cpp:2074
static LLVM_ABI Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:338
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
iterator_range< const_block_iterator > blocks() const
op_range incoming_values()
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
bool run(Function &F)
Perform TruncInst pattern optimization on given function.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition Type.h:130
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Definition Value.cpp:400
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Entry
Definition COFF.h:862
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:830
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1765
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition KnownBits.h:146