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 default:
77 llvm_unreachable("Unreachable!");
78 }
79}
80
81/// Given an instruction and a container, it fills all the relevant operands of
82/// that instruction, with respect to the Trunc expression graph optimizaton.
84 for (Use &Op : I->operands())
85 if (isRelevantOperand(I, Op.getOperandNo()))
86 Ops.push_back(Op.get());
87}
88
89bool TruncInstCombine::buildTruncExpressionGraph() {
90 SmallVector<Value *, 8> Worklist;
91 SmallVector<Instruction *, 8> Stack;
92 // Clear old instructions info.
93 InstInfoMap.clear();
94
95 Worklist.push_back(CurrentTruncInst->getOperand(0));
96
97 while (!Worklist.empty()) {
98 Value *Curr = Worklist.back();
99
100 if (isa<Constant>(Curr)) {
101 Worklist.pop_back();
102 continue;
103 }
104
105 auto *I = dyn_cast<Instruction>(Curr);
106 if (!I)
107 return false;
108
109 if (!Stack.empty() && Stack.back() == I) {
110 // Already handled all instruction operands, can remove it from both the
111 // Worklist and the Stack, and add it to the instruction info map.
112 Worklist.pop_back();
113 Stack.pop_back();
114 // Insert I to the Info map.
115 InstInfoMap.try_emplace(I);
116 continue;
117 }
118
119 if (InstInfoMap.count(I)) {
120 Worklist.pop_back();
121 continue;
122 }
123
124 // Add the instruction to the stack before start handling its operands.
125 Stack.push_back(I);
126
127 unsigned Opc = I->getOpcode();
128 switch (Opc) {
129 case Instruction::Trunc:
130 case Instruction::ZExt:
131 case Instruction::SExt:
132 // trunc(trunc(x)) -> trunc(x)
133 // trunc(ext(x)) -> ext(x) if the source type is smaller than the new dest
134 // trunc(ext(x)) -> trunc(x) if the source type is larger than the new
135 // dest
136 break;
137 case Instruction::Add:
138 case Instruction::Sub:
139 case Instruction::Mul:
140 case Instruction::And:
141 case Instruction::Or:
142 case Instruction::Xor:
143 case Instruction::Shl:
144 case Instruction::LShr:
145 case Instruction::AShr:
146 case Instruction::UDiv:
147 case Instruction::URem:
148 case Instruction::InsertElement:
149 case Instruction::ExtractElement:
150 case Instruction::Select: {
151 SmallVector<Value *, 2> Operands;
153 append_range(Worklist, Operands);
154 break;
155 }
156 case Instruction::PHI: {
157 SmallVector<Value *, 2> Operands;
159 // Add only operands not in Stack to prevent cycle
160 for (auto *Op : Operands)
161 if (!llvm::is_contained(Stack, Op))
162 Worklist.push_back(Op);
163 break;
164 }
165 default:
166 // TODO: Can handle more cases here:
167 // 1. shufflevector
168 // 2. sdiv, srem
169 // ...
170 return false;
171 }
172 }
173 return true;
174}
175
176unsigned TruncInstCombine::getMinBitWidth() {
177 SmallVector<Value *, 8> Worklist;
178 SmallVector<Instruction *, 8> Stack;
179
180 Value *Src = CurrentTruncInst->getOperand(0);
181 Type *DstTy = CurrentTruncInst->getType();
182 unsigned TruncBitWidth = DstTy->getScalarSizeInBits();
183 unsigned OrigBitWidth =
184 CurrentTruncInst->getOperand(0)->getType()->getScalarSizeInBits();
185
186 if (isa<Constant>(Src))
187 return TruncBitWidth;
188
189 Worklist.push_back(Src);
190 InstInfoMap[cast<Instruction>(Src)].ValidBitWidth = TruncBitWidth;
191
192 while (!Worklist.empty()) {
193 Value *Curr = Worklist.back();
194
195 if (isa<Constant>(Curr)) {
196 Worklist.pop_back();
197 continue;
198 }
199
200 // Otherwise, it must be an instruction.
201 auto *I = cast<Instruction>(Curr);
202
203 auto &Info = InstInfoMap[I];
204
205 SmallVector<Value *, 2> Operands;
207
208 if (!Stack.empty() && Stack.back() == I) {
209 // Already handled all instruction operands, can remove it from both, the
210 // Worklist and the Stack, and update MinBitWidth.
211 Worklist.pop_back();
212 Stack.pop_back();
213 for (auto *Operand : Operands)
214 if (auto *IOp = dyn_cast<Instruction>(Operand))
215 Info.MinBitWidth =
216 std::max(Info.MinBitWidth, InstInfoMap[IOp].MinBitWidth);
217 continue;
218 }
219
220 // Add the instruction to the stack before start handling its operands.
221 Stack.push_back(I);
222 unsigned ValidBitWidth = Info.ValidBitWidth;
223
224 // Update minimum bit-width before handling its operands. This is required
225 // when the instruction is part of a loop.
226 Info.MinBitWidth = std::max(Info.MinBitWidth, Info.ValidBitWidth);
227
228 for (auto *Operand : Operands)
229 if (auto *IOp = dyn_cast<Instruction>(Operand)) {
230 // If we already calculated the minimum bit-width for this valid
231 // bit-width, or for a smaller valid bit-width, then just keep the
232 // answer we already calculated.
233 unsigned IOpBitwidth = InstInfoMap.lookup(IOp).ValidBitWidth;
234 if (IOpBitwidth >= ValidBitWidth)
235 continue;
236 InstInfoMap[IOp].ValidBitWidth = ValidBitWidth;
237 Worklist.push_back(IOp);
238 }
239 }
240 unsigned MinBitWidth = InstInfoMap.lookup(cast<Instruction>(Src)).MinBitWidth;
241 assert(MinBitWidth >= TruncBitWidth);
242
243 if (MinBitWidth > TruncBitWidth) {
244 // In this case reducing expression with vector type might generate a new
245 // vector type, which is not preferable as it might result in generating
246 // sub-optimal code.
247 if (DstTy->isVectorTy())
248 return OrigBitWidth;
249 // Use the smallest integer type in the range [MinBitWidth, OrigBitWidth).
250 Type *Ty = DL.getSmallestLegalIntType(DstTy->getContext(), MinBitWidth);
251 // Update minimum bit-width with the new destination type bit-width if
252 // succeeded to find such, otherwise, with original bit-width.
253 MinBitWidth = Ty ? Ty->getScalarSizeInBits() : OrigBitWidth;
254 } else { // MinBitWidth == TruncBitWidth
255 // In this case the expression can be evaluated with the trunc instruction
256 // destination type, and trunc instruction can be omitted. However, we
257 // should not perform the evaluation if the original type is a legal scalar
258 // type and the target type is illegal.
259 bool FromLegal = MinBitWidth == 1 || DL.isLegalInteger(OrigBitWidth);
260 bool ToLegal = MinBitWidth == 1 || DL.isLegalInteger(MinBitWidth);
261 if (!DstTy->isVectorTy() && FromLegal && !ToLegal)
262 return OrigBitWidth;
263 }
264 return MinBitWidth;
265}
266
267Type *TruncInstCombine::getBestTruncatedType() {
268 if (!buildTruncExpressionGraph())
269 return nullptr;
270
271 // We don't want to duplicate instructions, which isn't profitable. Thus, we
272 // can't shrink something that has multiple uses, unless all uses can be
273 // reduced and all users are post-dominated by the trunc instruction,
274 // i.e., were visited during the expression evaluation.
275 unsigned DesiredBitWidth = 0;
276 for (auto Itr : InstInfoMap) {
277 Instruction *I = Itr.first;
278 if (I->hasOneUse())
279 continue;
280 bool IsExtInst = (isa<ZExtInst>(I) || isa<SExtInst>(I));
281 for (Use &U : I->uses())
282 if (auto *UI = dyn_cast<Instruction>(U.getUser()))
283 if (UI != CurrentTruncInst &&
284 (!InstInfoMap.count(UI) ||
285 !isRelevantOperand(UI, U.getOperandNo()))) {
286 if (!IsExtInst)
287 return nullptr;
288 // If this is an extension from the dest type, we can eliminate it,
289 // even if it has multiple users. Thus, update the DesiredBitWidth and
290 // validate all extension instructions agrees on same DesiredBitWidth.
291 unsigned ExtInstBitWidth =
292 I->getOperand(0)->getType()->getScalarSizeInBits();
293 if (DesiredBitWidth && DesiredBitWidth != ExtInstBitWidth)
294 return nullptr;
295 DesiredBitWidth = ExtInstBitWidth;
296 }
297 }
298
299 unsigned OrigBitWidth =
300 CurrentTruncInst->getOperand(0)->getType()->getScalarSizeInBits();
301
302 // Initialize MinBitWidth for shift instructions with the minimum number
303 // that is greater than shift amount (i.e. shift amount + 1).
304 // For `lshr` adjust MinBitWidth so that all potentially truncated
305 // bits of the value-to-be-shifted are zeros.
306 // For `ashr` adjust MinBitWidth so that all potentially truncated
307 // bits of the value-to-be-shifted are sign bits (all zeros or ones)
308 // and even one (first) untruncated bit is sign bit.
309 // Exit early if MinBitWidth is not less than original bitwidth.
310 for (auto &Itr : InstInfoMap) {
311 Instruction *I = Itr.first;
312 if (I->isShift()) {
313 KnownBits KnownRHS = computeKnownBits(I->getOperand(1));
314 unsigned MinBitWidth = KnownRHS.getMaxValue()
315 .uadd_sat(APInt(OrigBitWidth, 1))
316 .getLimitedValue(OrigBitWidth);
317 if (MinBitWidth == OrigBitWidth)
318 return nullptr;
319 if (I->getOpcode() == Instruction::LShr) {
320 KnownBits KnownLHS = computeKnownBits(I->getOperand(0));
321 MinBitWidth =
322 std::max(MinBitWidth, KnownLHS.getMaxValue().getActiveBits());
323 }
324 if (I->getOpcode() == Instruction::AShr) {
325 unsigned NumSignBits = ComputeNumSignBits(I->getOperand(0));
326 MinBitWidth = std::max(MinBitWidth, OrigBitWidth - NumSignBits + 1);
327 }
328 if (MinBitWidth >= OrigBitWidth)
329 return nullptr;
330 Itr.second.MinBitWidth = MinBitWidth;
331 }
332 if (I->getOpcode() == Instruction::UDiv ||
333 I->getOpcode() == Instruction::URem) {
334 unsigned MinBitWidth = 0;
335 for (const auto &Op : I->operands()) {
336 KnownBits Known = computeKnownBits(Op);
337 MinBitWidth =
338 std::max(Known.getMaxValue().getActiveBits(), MinBitWidth);
339 if (MinBitWidth >= OrigBitWidth)
340 return nullptr;
341 }
342 Itr.second.MinBitWidth = MinBitWidth;
343 }
344 }
345
346 // Calculate minimum allowed bit-width allowed for shrinking the currently
347 // visited truncate's operand.
348 unsigned MinBitWidth = getMinBitWidth();
349
350 // Check that we can shrink to smaller bit-width than original one and that
351 // it is similar to the DesiredBitWidth is such exists.
352 if (MinBitWidth >= OrigBitWidth ||
353 (DesiredBitWidth && DesiredBitWidth != MinBitWidth))
354 return nullptr;
355
356 return IntegerType::get(CurrentTruncInst->getContext(), MinBitWidth);
357}
358
359/// Given a reduced scalar type \p Ty and a \p V value, return a reduced type
360/// for \p V, according to its type, if it vector type, return the vector
361/// version of \p Ty, otherwise return \p Ty.
362static Type *getReducedType(Value *V, Type *Ty) {
363 assert(Ty && !Ty->isVectorTy() && "Expect Scalar Type");
364 if (auto *VTy = dyn_cast<VectorType>(V->getType()))
365 return VectorType::get(Ty, VTy->getElementCount());
366 return Ty;
367}
368
369Value *TruncInstCombine::getReducedOperand(Value *V, Type *SclTy) {
370 Type *Ty = getReducedType(V, SclTy);
371 if (auto *C = dyn_cast<Constant>(V)) {
373 // If we got a constantexpr back, try to simplify it with DL info.
374 return ConstantFoldConstant(C, DL, &TLI);
375 }
376
377 auto *I = cast<Instruction>(V);
378 Info Entry = InstInfoMap.lookup(I);
379 assert(Entry.NewValue);
380 return Entry.NewValue;
381}
382
383void TruncInstCombine::ReduceExpressionGraph(Type *SclTy) {
384 NumInstrsReduced += InstInfoMap.size();
385 // Pairs of old and new phi-nodes
387 for (auto &Itr : InstInfoMap) { // Forward
388 Instruction *I = Itr.first;
389 TruncInstCombine::Info &NodeInfo = Itr.second;
390
391 assert(!NodeInfo.NewValue && "Instruction has been evaluated");
392
393 IRBuilder<> Builder(I);
394 Value *Res = nullptr;
395 unsigned Opc = I->getOpcode();
396 switch (Opc) {
397 case Instruction::Trunc:
398 case Instruction::ZExt:
399 case Instruction::SExt: {
400 Type *Ty = getReducedType(I, SclTy);
401 // If the source type of the cast is the type we're trying for then we can
402 // just return the source. There's no need to insert it because it is not
403 // new.
404 if (I->getOperand(0)->getType() == Ty) {
405 assert(!isa<TruncInst>(I) && "Cannot reach here with TruncInst");
406 NodeInfo.NewValue = I->getOperand(0);
407 continue;
408 }
409 // Otherwise, must be the same type of cast, so just reinsert a new one.
410 // This also handles the case of zext(trunc(x)) -> zext(x).
411 Res = Builder.CreateIntCast(I->getOperand(0), Ty,
412 Opc == Instruction::SExt);
413
414 // Update Worklist entries with new value if needed.
415 // There are three possible changes to the Worklist:
416 // 1. Update Old-TruncInst -> New-TruncInst.
417 // 2. Remove Old-TruncInst (if New node is not TruncInst).
418 // 3. Add New-TruncInst (if Old node was not TruncInst).
419 auto *Entry = find(Worklist, I);
420 if (Entry != Worklist.end()) {
421 if (auto *NewCI = dyn_cast<TruncInst>(Res))
422 *Entry = NewCI;
423 else
424 Worklist.erase(Entry);
425 } else if (auto *NewCI = dyn_cast<TruncInst>(Res))
426 Worklist.push_back(NewCI);
427 break;
428 }
429 case Instruction::Add:
430 case Instruction::Sub:
431 case Instruction::Mul:
432 case Instruction::And:
433 case Instruction::Or:
434 case Instruction::Xor:
435 case Instruction::Shl:
436 case Instruction::LShr:
437 case Instruction::AShr:
438 case Instruction::UDiv:
439 case Instruction::URem: {
440 Value *LHS = getReducedOperand(I->getOperand(0), SclTy);
441 Value *RHS = getReducedOperand(I->getOperand(1), SclTy);
442 Res = Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS);
443 // Preserve `exact` flag since truncation doesn't change exactness
444 if (auto *PEO = dyn_cast<PossiblyExactOperator>(I))
445 if (auto *ResI = dyn_cast<Instruction>(Res))
446 ResI->setIsExact(PEO->isExact());
447 break;
448 }
449 case Instruction::ExtractElement: {
450 Value *Vec = getReducedOperand(I->getOperand(0), SclTy);
451 Value *Idx = I->getOperand(1);
452 Res = Builder.CreateExtractElement(Vec, Idx);
453 break;
454 }
455 case Instruction::InsertElement: {
456 Value *Vec = getReducedOperand(I->getOperand(0), SclTy);
457 Value *NewElt = getReducedOperand(I->getOperand(1), SclTy);
458 Value *Idx = I->getOperand(2);
459 Res = Builder.CreateInsertElement(Vec, NewElt, Idx);
460 break;
461 }
462 case Instruction::Select: {
463 Value *Op0 = I->getOperand(0);
464 Value *LHS = getReducedOperand(I->getOperand(1), SclTy);
465 Value *RHS = getReducedOperand(I->getOperand(2), SclTy);
466 Res = Builder.CreateSelect(Op0, LHS, RHS, "", I);
467 break;
468 }
469 case Instruction::PHI: {
470 Res = Builder.CreatePHI(getReducedType(I, SclTy), I->getNumOperands());
471 OldNewPHINodes.push_back(
472 std::make_pair(cast<PHINode>(I), cast<PHINode>(Res)));
473 break;
474 }
475 default:
476 llvm_unreachable("Unhandled instruction");
477 }
478
479 NodeInfo.NewValue = Res;
480 if (auto *ResI = dyn_cast<Instruction>(Res))
481 ResI->takeName(I);
482 }
483
484 for (auto &Node : OldNewPHINodes) {
485 PHINode *OldPN = Node.first;
486 PHINode *NewPN = Node.second;
487 for (auto Incoming : zip(OldPN->incoming_values(), OldPN->blocks()))
488 NewPN->addIncoming(getReducedOperand(std::get<0>(Incoming), SclTy),
489 std::get<1>(Incoming));
490 }
491
492 Value *Res = getReducedOperand(CurrentTruncInst->getOperand(0), SclTy);
493 Type *DstTy = CurrentTruncInst->getType();
494 if (Res->getType() != DstTy) {
495 IRBuilder<> Builder(CurrentTruncInst);
496 Res = Builder.CreateIntCast(Res, DstTy, false);
497 if (auto *ResI = dyn_cast<Instruction>(Res))
498 ResI->takeName(CurrentTruncInst);
499 }
500 CurrentTruncInst->replaceAllUsesWith(Res);
501
502 // Erase old expression graph, which was replaced by the reduced expression
503 // graph.
504 CurrentTruncInst->eraseFromParent();
505 // First, erase old phi-nodes and its uses
506 for (auto &Node : OldNewPHINodes) {
507 PHINode *OldPN = Node.first;
509 InstInfoMap.erase(OldPN);
510 OldPN->eraseFromParent();
511 }
512 // Now we have expression graph turned into dag.
513 // We iterate backward, which means we visit the instruction before we
514 // visit any of its operands, this way, when we get to the operand, we already
515 // removed the instructions (from the expression dag) that uses it.
516 for (auto &I : llvm::reverse(InstInfoMap)) {
517 // We still need to check that the instruction has no users before we erase
518 // it, because {SExt, ZExt}Inst Instruction might have other users that was
519 // not reduced, in such case, we need to keep that instruction.
520 if (I.first->use_empty())
521 I.first->eraseFromParent();
522 else
523 assert((isa<SExtInst>(I.first) || isa<ZExtInst>(I.first)) &&
524 "Only {SExt, ZExt}Inst might have unreduced users");
525 }
526}
527
529 bool MadeIRChange = false;
530
531 // Collect all TruncInst in the function into the Worklist for evaluating.
532 for (auto &BB : F) {
533 // Ignore unreachable basic block.
534 if (!DT.isReachableFromEntry(&BB))
535 continue;
536 for (auto &I : BB)
537 if (auto *CI = dyn_cast<TruncInst>(&I))
538 Worklist.push_back(CI);
539 }
540
541 // Process all TruncInst in the Worklist, for each instruction:
542 // 1. Check if it dominates an eligible expression graph to be reduced.
543 // 2. Create a reduced expression graph and replace the old one with it.
544 while (!Worklist.empty()) {
545 CurrentTruncInst = Worklist.pop_back_val();
546
547 if (Type *NewDstSclTy = getBestTruncatedType()) {
549 dbgs() << "ICE: TruncInstCombine reducing type of expression graph "
550 "dominated by: "
551 << CurrentTruncInst << '\n');
552 ReduceExpressionGraph(NewDstSclTy);
553 ++NumExprsReduced;
554 MadeIRChange = true;
555 }
556 }
557
558 return MadeIRChange;
559}
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:1537
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:476
LLVM_ABI APInt uadd_sat(const APInt &RHS) const
Definition APInt.cpp:2071
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:348
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:288
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:232
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:255
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