LLVM 24.0.0git
X86LowerAMXType.cpp
Go to the documentation of this file.
1//===- Target/X86/X86LowerAMXType.cpp - -------------------------*- 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 Pass to transform <256 x i32> load/store
10/// <256 x i32> is bitcasted to x86_amx on X86, and AMX instruction set only
11/// provides simple operation on x86_amx. The basic elementwise operation
12/// is not supported by AMX. Since x86_amx is bitcasted from vector <256 x i32>
13/// and only AMX intrinsics can operate on the type, we need transform
14/// load/store <256 x i32> instruction to AMX load/store. If the bitcast can
15/// not be combined with load/store, we transform the bitcast to amx load/store
16/// and <256 x i32> store/load.
17///
18/// If Front End not use O0 but the Mid/Back end use O0, (e.g. "Clang -O2 -S
19/// -emit-llvm t.c" + "llc t.ll") we should make sure the amx data is volatile,
20/// because that is necessary for AMX fast register allocation. (In Fast
21/// registera allocation, register will be allocated before spill/reload, so
22/// there is no additional register for amx to identify the step in spill.)
23/// The volatileTileData() will handle this case.
24/// e.g.
25/// ----------------------------------------------------------
26/// | def %td = ... |
27/// | ... |
28/// | "use %td" |
29/// ----------------------------------------------------------
30/// will transfer to -->
31/// ----------------------------------------------------------
32/// | def %td = ... |
33/// | call void @llvm.x86.tilestored64.internal(mem, %td) |
34/// | ... |
35/// | %td2 = call x86_amx @llvm.x86.tileloadd64.internal(mem)|
36/// | "use %td2" |
37/// ----------------------------------------------------------
38//
39//===----------------------------------------------------------------------===//
40//
41#include "X86.h"
43#include "llvm/ADT/SetVector.h"
46#include "llvm/CodeGen/Passes.h"
49#include "llvm/IR/Analysis.h"
50#include "llvm/IR/DataLayout.h"
51#include "llvm/IR/Function.h"
52#include "llvm/IR/IRBuilder.h"
55#include "llvm/IR/IntrinsicsX86.h"
56#include "llvm/IR/PassManager.h"
59#include "llvm/Pass.h"
63
64#include <map>
65
66using namespace llvm;
67using namespace PatternMatch;
68
69#define DEBUG_TYPE "x86-lower-amx-type"
70
76
77static bool isAMXIntrinsic(Value *I) {
79 if (!II)
80 return false;
81 if (isAMXCast(II))
82 return false;
83 // Check if return type or parameter is x86_amx. If it is x86_amx
84 // the intrinsic must be x86 amx intrinsics.
85 if (II->getType()->isX86_AMXTy())
86 return true;
87 for (Value *V : II->args()) {
88 if (V->getType()->isX86_AMXTy())
89 return true;
90 }
91
92 return false;
93}
94
95static bool containsAMXCode(Function &F) {
96 for (BasicBlock &BB : F)
97 for (Instruction &I : BB)
98 if (I.getType()->isX86_AMXTy())
99 return true;
100 return false;
101}
102
103// Check if the instruction is an ACE-only intrinsic.
104// ACE (Palette 2) doesn't have TILELOADD/TILESTORED instructions,
105// so volatile tile data transformation should skip ACE intrinsics.
108 if (!II)
109 return false;
110 switch (II->getIntrinsicID()) {
111 // ACE outer product intrinsics
112 case Intrinsic::x86_acev1_top2bf16ps_internal:
113 case Intrinsic::x86_acev1_top4buud_internal:
114 case Intrinsic::x86_acev1_top4busd_internal:
115 case Intrinsic::x86_acev1_top4bssd_internal:
116 case Intrinsic::x86_acev1_top4bsud_internal:
117 // ACE mixed precision intrinsics
118 case Intrinsic::x86_acev1_top4mxhf8ps_internal:
119 case Intrinsic::x86_acev1_top4mxbhf8ps_internal:
120 case Intrinsic::x86_acev1_top4mxhbf8ps_internal:
121 case Intrinsic::x86_acev1_top4mxbf8ps_internal:
122 case Intrinsic::x86_acev1_top4mxbssps_internal:
123 // ACE tile movement intrinsics
124 case Intrinsic::x86_acev1_tilemovcolinsert_internal:
125 case Intrinsic::x86_acev1_tilemovrowinsert_internal:
126 // ACE spellings of the AMX-shared intrinsics
127 case Intrinsic::x86_acev1_tilezero_internal:
128 case Intrinsic::x86_acev1_tcvtrowps2bf16h_internal:
129 case Intrinsic::x86_acev1_tcvtrowps2bf16l_internal:
130 case Intrinsic::x86_acev1_tcvtrowps2phh_internal:
131 case Intrinsic::x86_acev1_tcvtrowps2phl_internal:
132 case Intrinsic::x86_acev1_tcvtrowd2ps_internal:
133 case Intrinsic::x86_acev1_tilemovrowextract_internal:
134 return true;
135 default:
136 return false;
137 }
138}
139
140// Check if PHI node has any ACE-only intrinsic as incoming value.
142 for (unsigned I = 0, E = PHI->getNumIncomingValues(); I != E; ++I) {
143 Value *Op = PHI->getIncomingValue(I);
144 if (auto *Inst = dyn_cast<Instruction>(Op)) {
145 if (isACEOnlyIntrinsic(Inst))
146 return true;
147 }
148 }
149 return false;
150}
151
153 Type *Ty) {
154 Function &F = *BB->getParent();
155 const DataLayout &DL = F.getDataLayout();
156
157 LLVMContext &Ctx = Builder.getContext();
158 auto AllocaAlignment = DL.getPrefTypeAlign(Type::getX86_AMXTy(Ctx));
159 unsigned AllocaAS = DL.getAllocaAddrSpace();
160 AllocaInst *AllocaRes =
161 new AllocaInst(Ty, AllocaAS, "", F.getEntryBlock().begin());
162 AllocaRes->setAlignment(AllocaAlignment);
163 return AllocaRes;
164}
165
167 for (Instruction &I : F.getEntryBlock())
168 if (!isa<AllocaInst>(&I))
169 return &I;
170 llvm_unreachable("No terminator in the entry block!");
171}
172
173static Value *getRowFromCol(Instruction *II, Value *V, unsigned Granularity) {
174 IRBuilder<> Builder(II);
175 Value *RealRow = nullptr;
176 if (isa<ConstantInt>(V))
177 RealRow =
178 Builder.getInt16((cast<ConstantInt>(V)->getSExtValue()) / Granularity);
179 else if (isa<Instruction>(V)) {
180 // When it is not a const value and it is not a function argument, we
181 // create Row after the definition of V instead of
182 // before II. For example, II is %118, we try to getshape for %117:
183 // %117 = call x86_amx @llvm.x86.cast.vector.to.tile.v256i32(<256 x
184 // i32> %115).
185 // %118 = call x86_amx @llvm.x86.tdpbf16ps.internal(i16
186 // %104, i16 %105, i16 %106, x86_amx %110, x86_amx %114, x86_amx
187 // %117).
188 // If we create %row = udiv i16 %106, 4 before %118(aka. II), then its
189 // definition is after its user(new tileload for %117).
190 // So, the best choice is to create %row right after the definition of
191 // %106.
192 Builder.SetInsertPoint(cast<Instruction>(V));
193 RealRow = Builder.CreateUDiv(V, Builder.getInt16(4));
194 cast<Instruction>(RealRow)->moveAfter(cast<Instruction>(V));
195 } else {
196 // When it is not a const value and it is a function argument, we create
197 // Row at the entry bb.
198 IRBuilder<> NewBuilder(
199 getFirstNonAllocaInTheEntryBlock(*II->getFunction()));
200 RealRow = NewBuilder.CreateUDiv(V, NewBuilder.getInt16(Granularity));
201 }
202 return RealRow;
203}
204
205// TODO: Refine the row and col-in-bytes of tile to row and col of matrix.
206std::pair<Value *, Value *> getShape(IntrinsicInst *II, unsigned OpNo) {
207 Value *Row = nullptr, *Col = nullptr;
208 switch (II->getIntrinsicID()) {
209 default:
210 llvm_unreachable("Expect amx intrinsics");
211 case Intrinsic::x86_tileloadd64_internal:
212 case Intrinsic::x86_tileloaddt164_internal:
213 case Intrinsic::x86_tilestored64_internal:
214 case Intrinsic::x86_tileloaddrs64_internal:
215 case Intrinsic::x86_tileloaddrst164_internal: {
216 Row = II->getArgOperand(0);
217 Col = II->getArgOperand(1);
218 break;
219 }
220 // a * b + c
221 // The shape depends on which operand.
222 case Intrinsic::x86_tcmmimfp16ps_internal:
223 case Intrinsic::x86_tcmmrlfp16ps_internal:
224 case Intrinsic::x86_tdpbssd_internal:
225 case Intrinsic::x86_tdpbsud_internal:
226 case Intrinsic::x86_tdpbusd_internal:
227 case Intrinsic::x86_tdpbuud_internal:
228 case Intrinsic::x86_tdpbf16ps_internal:
229 case Intrinsic::x86_tdpfp16ps_internal:
230 case Intrinsic::x86_tdpbf8ps_internal:
231 case Intrinsic::x86_tdpbhf8ps_internal:
232 case Intrinsic::x86_tdphbf8ps_internal:
233 case Intrinsic::x86_tdphf8ps_internal: {
234 switch (OpNo) {
235 case 3:
236 Row = II->getArgOperand(0);
237 Col = II->getArgOperand(1);
238 break;
239 case 4:
240 Row = II->getArgOperand(0);
241 Col = II->getArgOperand(2);
242 break;
243 case 5:
244 Row = getRowFromCol(II, II->getArgOperand(2), 4);
245 Col = II->getArgOperand(1);
246 break;
247 }
248 break;
249 }
250 case Intrinsic::x86_tcvtrowd2ps_internal:
251 case Intrinsic::x86_tcvtrowps2bf16h_internal:
252 case Intrinsic::x86_tcvtrowps2bf16l_internal:
253 case Intrinsic::x86_tcvtrowps2phh_internal:
254 case Intrinsic::x86_tcvtrowps2phl_internal:
255 case Intrinsic::x86_tilemovrow_internal:
256 case Intrinsic::x86_acev1_tcvtrowps2bf16h_internal:
257 case Intrinsic::x86_acev1_tcvtrowps2bf16l_internal:
258 case Intrinsic::x86_acev1_tcvtrowps2phh_internal:
259 case Intrinsic::x86_acev1_tcvtrowps2phl_internal:
260 case Intrinsic::x86_acev1_tcvtrowd2ps_internal:
261 case Intrinsic::x86_acev1_tilemovrowextract_internal: {
262 assert(OpNo == 2 && "Illegal Operand Number.");
263 Row = II->getArgOperand(0);
264 Col = II->getArgOperand(1);
265 break;
266 }
267 // ACE internal intrinsics - outer products with ZMM sources
268 // Pattern: (m, n, acc_tile, zmm1, zmm2) -> acc_tile += zmm1 * zmm2
269 // The accumulator is the only tile, so it is the only operand a shape can be
270 // asked for; the sources are ZMMs of a fixed size.
271 case Intrinsic::x86_acev1_top2bf16ps_internal:
272 case Intrinsic::x86_acev1_top4buud_internal:
273 case Intrinsic::x86_acev1_top4busd_internal:
274 case Intrinsic::x86_acev1_top4bssd_internal:
275 case Intrinsic::x86_acev1_top4bsud_internal: {
276 assert(OpNo == 2 && "Illegal Operand Number.");
277 Row = II->getArgOperand(0);
278 Col = II->getArgOperand(1);
279 break;
280 }
281 // ACE TOP4MX intrinsics - mixed precision with BSR index
282 case Intrinsic::x86_acev1_top4mxhf8ps_internal:
283 case Intrinsic::x86_acev1_top4mxbhf8ps_internal:
284 case Intrinsic::x86_acev1_top4mxhbf8ps_internal:
285 case Intrinsic::x86_acev1_top4mxbf8ps_internal:
286 case Intrinsic::x86_acev1_top4mxbssps_internal: {
287 assert(OpNo == 3 && "Illegal Operand Number.");
288 Row = II->getArgOperand(0);
289 Col = II->getArgOperand(1);
290 break;
291 }
292 // ACE TILEMOV intrinsics - move ZMM into one row or column of a tile
293 // Pattern: (m, n, tile, zmm_src, idx) -> tile
294 case Intrinsic::x86_acev1_tilemovcolinsert_internal:
295 case Intrinsic::x86_acev1_tilemovrowinsert_internal: {
296 assert(OpNo == 2 && "Illegal Operand Number.");
297 Row = II->getArgOperand(0);
298 Col = II->getArgOperand(1);
299 break;
300 }
301 }
302
303 return std::make_pair(Row, Col);
304}
305
306// Walk through casts and PHIs to the intrinsic that will consume the tile,
307// reporting which operand it arrives as.
308static IntrinsicInst *getTileConsumer(PHINode *Phi, unsigned &OpNo) {
309 Use &U = *(Phi->use_begin());
310 OpNo = U.getOperandNo();
311 User *V = U.getUser();
312 // TODO We don't traverse all users. To make the algorithm simple, here we
313 // just traverse the first user. If we can find shape, then return the shape,
314 // otherwise just return nullptr and the optimization for undef/zero will be
315 // abandoned.
316 while (V) {
318 if (V->use_empty())
319 break;
320 Use &U = *(V->use_begin());
321 OpNo = U.getOperandNo();
322 V = U.getUser();
323 } else if (isAMXIntrinsic(V)) {
324 return cast<IntrinsicInst>(V);
325 } else if (isa<PHINode>(V)) {
326 if (V->use_empty())
327 break;
328 Use &U = *(V->use_begin());
329 V = U.getUser();
330 } else {
331 break;
332 }
333 }
334
335 return nullptr;
336}
337
338// Which tilezero spelling to synthesize follows from the intrinsic that will
339// consume the tile, not from the subtarget: a function built for an ACE target
340// can still contain plain AMX code, which needs palette 1.
342 return Consumer && isACEOnlyIntrinsic(Consumer)
343 ? Intrinsic::x86_acev1_tilezero_internal
344 : Intrinsic::x86_tilezero_internal;
345}
346
347// A palette 2 tile is 16 rows of 64 bytes, which is 16 lanes of i32 per row.
348static constexpr unsigned ACENumTileRows = 16;
349static constexpr unsigned ACERowNumElts = 16;
350
351// Palette 2 has no TILELOADD, so build the tile a row at a time.
353 Value *Row, Value *Col) {
354 Type *RowsTy = FixedVectorType::get(Builder.getInt32Ty(),
356 Value *Rows = Builder.CreateBitCast(Vec, RowsTy);
357 // The first write's source is dead, but a constant cannot be an argument.
358 Value *Tile = Builder.CreateIntrinsic(Intrinsic::x86_acev1_tilezero_internal,
359 {}, {Row, Col});
360 for (unsigned R = 0; R != ACENumTileRows; ++R) {
362 for (unsigned E = 0; E != ACERowNumElts; ++E)
363 Mask.push_back(R * ACERowNumElts + E);
364 Tile = Builder.CreateIntrinsic(
365 Intrinsic::x86_acev1_tilemovrowinsert_internal, {},
366 {Row, Col, Tile, Builder.CreateShuffleVector(Rows, Mask),
367 Builder.getInt32(R)});
368 }
369 return Tile;
370}
371
372// Palette 2 has no TILESTORED, so read the tile back a row at a time.
374 Value *Row, Value *Col, Type *VecTy) {
376 for (unsigned R = 0; R != ACENumTileRows; ++R)
377 Rows.push_back(
378 Builder.CreateIntrinsic(Intrinsic::x86_acev1_tilemovrowextract_internal,
379 {}, {Row, Col, Tile, Builder.getInt32(R)}));
380
381 // Join the rows in pairs, so the shuffles form a tree and not a chain.
382 for (unsigned Width = ACENumTileRows; Width != 1; Width /= 2) {
383 unsigned NumElts =
384 cast<FixedVectorType>(Rows[0]->getType())->getNumElements();
386 for (unsigned E = 0; E != 2 * NumElts; ++E)
387 Mask.push_back(E);
388 for (unsigned I = 0; I != Width / 2; ++I)
389 Rows[I] = Builder.CreateShuffleVector(Rows[2 * I], Rows[2 * I + 1], Mask);
390 }
391 return Builder.CreateBitCast(Rows[0], VecTy);
392}
393
394namespace {
395class X86LowerAMXType {
396 Function &Func;
397
398 // In AMX intrinsics we let Shape = {Row, Col}, but the
399 // RealCol = Col / ElementSize. We may use the RealCol
400 // as a new Row for other new created AMX intrinsics.
401 std::map<Value *, Value *> Col2Row;
402
403public:
404 X86LowerAMXType(Function &F) : Func(F) {}
405 bool visit();
406 void combineLoadBitcast(LoadInst *LD, BitCastInst *Bitcast);
407 void combineBitcastStore(BitCastInst *Bitcast, StoreInst *ST);
408 bool transformBitcast(BitCastInst *Bitcast);
409};
410
411// %src = load <256 x i32>, <256 x i32>* %addr, align 64
412// %2 = bitcast <256 x i32> %src to x86_amx
413// -->
414// %2 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
415// i8* %addr, i64 %stride64)
416void X86LowerAMXType::combineLoadBitcast(LoadInst *LD, BitCastInst *Bitcast) {
417 Value *Row = nullptr, *Col = nullptr;
418 Use &U = *(Bitcast->use_begin());
419 unsigned OpNo = U.getOperandNo();
420 auto *II = cast<IntrinsicInst>(U.getUser());
421 std::tie(Row, Col) = getShape(II, OpNo);
422 IRBuilder<> Builder(Bitcast);
423 // Use the maximun column as stride.
424 Value *Stride = Builder.getInt64(64);
425 Value *I8Ptr = LD->getOperand(0);
426 std::array<Value *, 4> Args = {Row, Col, I8Ptr, Stride};
427
428 Value *NewInst =
429 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
430 Bitcast->replaceAllUsesWith(NewInst);
431}
432
433// %src = call x86_amx @llvm.x86.tileloadd64.internal(%row, %col, %addr,
434// %stride);
435// %13 = bitcast x86_amx %src to <256 x i32>
436// store <256 x i32> %13, <256 x i32>* %addr, align 64
437// -->
438// call void @llvm.x86.tilestored64.internal(%row, %col, %addr,
439// %stride64, %13)
440void X86LowerAMXType::combineBitcastStore(BitCastInst *Bitcast, StoreInst *ST) {
441
442 Value *Tile = Bitcast->getOperand(0);
443 auto *II = cast<IntrinsicInst>(Tile);
444 // Tile is output from AMX intrinsic. The first operand of the
445 // intrinsic is row, the second operand of the intrinsic is column.
446 Value *Row = II->getOperand(0);
447 Value *Col = II->getOperand(1);
448 IRBuilder<> Builder(ST);
449 // Use the maximum column as stride. It must be the same with load
450 // stride.
451 Value *Stride = Builder.getInt64(64);
452 Value *I8Ptr = ST->getOperand(1);
453 std::array<Value *, 5> Args = {Row, Col, I8Ptr, Stride, Tile};
454 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
455 if (Bitcast->hasOneUse())
456 return;
457 // %13 = bitcast x86_amx %src to <256 x i32>
458 // store <256 x i32> %13, <256 x i32>* %addr, align 64
459 // %add = <256 x i32> %13, <256 x i32> %src2
460 // -->
461 // %13 = bitcast x86_amx %src to <256 x i32>
462 // call void @llvm.x86.tilestored64.internal(%row, %col, %addr,
463 // %stride64, %13)
464 // %14 = load <256 x i32>, %addr
465 // %add = <256 x i32> %14, <256 x i32> %src2
466 Value *Vec = Builder.CreateLoad(Bitcast->getType(), ST->getOperand(1));
467 Bitcast->replaceAllUsesWith(Vec);
468}
469
470// transform bitcast to <store, load> instructions.
471bool X86LowerAMXType::transformBitcast(BitCastInst *Bitcast) {
472 IRBuilder<> Builder(Bitcast);
473 AllocaInst *AllocaAddr;
474 Value *I8Ptr, *Stride;
475 auto *Src = Bitcast->getOperand(0);
476
477 auto Prepare = [&](Type *MemTy) {
478 AllocaAddr = createAllocaInstAtEntry(Builder, Bitcast->getParent(), MemTy);
479 I8Ptr = AllocaAddr;
480 Stride = Builder.getInt64(64);
481 };
482
483 if (Bitcast->getType()->isX86_AMXTy()) {
484 // %2 = bitcast <256 x i32> %src to x86_amx
485 // -->
486 // %addr = alloca <256 x i32>, align 64
487 // store <256 x i32> %src, <256 x i32>* %addr, align 64
488 // %addr2 = bitcast <256 x i32>* to i8*
489 // %2 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
490 // i8* %addr2,
491 // i64 64)
492 Use &U = *(Bitcast->use_begin());
493 unsigned OpNo = U.getOperandNo();
494 auto *II = dyn_cast<IntrinsicInst>(U.getUser());
495 if (!II)
496 return false; // May be bitcast from x86amx to <256 x i32>.
497 Prepare(Bitcast->getOperand(0)->getType());
498 Builder.CreateStore(Src, AllocaAddr);
499 // TODO we can pick an constant operand for the shape.
500 Value *Row = nullptr, *Col = nullptr;
501 std::tie(Row, Col) = getShape(II, OpNo);
502 std::array<Value *, 4> Args = {Row, Col, I8Ptr, Stride};
503 Value *NewInst =
504 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
505 Bitcast->replaceAllUsesWith(NewInst);
506 } else {
507 // %2 = bitcast x86_amx %src to <256 x i32>
508 // -->
509 // %addr = alloca <256 x i32>, align 64
510 // %addr2 = bitcast <256 x i32>* to i8*
511 // call void @llvm.x86.tilestored64.internal(i16 %row, i16 %col,
512 // i8* %addr2, i64 %stride)
513 // %2 = load <256 x i32>, <256 x i32>* %addr, align 64
514 auto *II = dyn_cast<IntrinsicInst>(Src);
515 if (!II)
516 return false; // May be bitcast from <256 x i32> to x86amx.
517 Prepare(Bitcast->getType());
518 Value *Row = II->getOperand(0);
519 Value *Col = II->getOperand(1);
520 std::array<Value *, 5> Args = {Row, Col, I8Ptr, Stride, Src};
521 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
522 Value *NewInst = Builder.CreateLoad(Bitcast->getType(), AllocaAddr);
523 Bitcast->replaceAllUsesWith(NewInst);
524 }
525
526 return true;
527}
528
529bool X86LowerAMXType::visit() {
530 SmallVector<Instruction *, 8> DeadInsts;
531 Col2Row.clear();
532
533 for (BasicBlock *BB : post_order(&Func)) {
534 for (Instruction &Inst : llvm::make_early_inc_range(llvm::reverse(*BB))) {
535 auto *Bitcast = dyn_cast<BitCastInst>(&Inst);
536 if (!Bitcast)
537 continue;
538
539 Value *Src = Bitcast->getOperand(0);
540 if (Bitcast->getType()->isX86_AMXTy()) {
541 if (Bitcast->user_empty()) {
542 DeadInsts.push_back(Bitcast);
543 continue;
544 }
545 LoadInst *LD = dyn_cast<LoadInst>(Src);
546 if (!LD) {
547 if (transformBitcast(Bitcast))
548 DeadInsts.push_back(Bitcast);
549 continue;
550 }
551 // If load has multi-user, duplicate a vector load.
552 // %src = load <256 x i32>, <256 x i32>* %addr, align 64
553 // %2 = bitcast <256 x i32> %src to x86_amx
554 // %add = add <256 x i32> %src, <256 x i32> %src2
555 // -->
556 // %src = load <256 x i32>, <256 x i32>* %addr, align 64
557 // %2 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
558 // i8* %addr, i64 %stride64)
559 // %add = add <256 x i32> %src, <256 x i32> %src2
560
561 // If load has one user, the load will be eliminated in DAG ISel.
562 // %src = load <256 x i32>, <256 x i32>* %addr, align 64
563 // %2 = bitcast <256 x i32> %src to x86_amx
564 // -->
565 // %2 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
566 // i8* %addr, i64 %stride64)
567 combineLoadBitcast(LD, Bitcast);
568 DeadInsts.push_back(Bitcast);
569 if (LD->hasOneUse())
570 DeadInsts.push_back(LD);
571 } else if (Src->getType()->isX86_AMXTy()) {
572 if (Bitcast->user_empty()) {
573 DeadInsts.push_back(Bitcast);
574 continue;
575 }
576 StoreInst *ST = nullptr;
577 for (Instruction *U : Bitcast->users()) {
579 if (ST)
580 break;
581 }
582 if (!ST) {
583 if (transformBitcast(Bitcast))
584 DeadInsts.push_back(Bitcast);
585 continue;
586 }
587 // If bitcast (%13) has one use, combine bitcast and store to amx store.
588 // %src = call x86_amx @llvm.x86.tileloadd64.internal(%row, %col, %addr,
589 // %stride);
590 // %13 = bitcast x86_amx %src to <256 x i32>
591 // store <256 x i32> %13, <256 x i32>* %addr, align 64
592 // -->
593 // call void @llvm.x86.tilestored64.internal(%row, %col, %addr,
594 // %stride64, %13)
595 //
596 // If bitcast (%13) has multi-use, transform as below.
597 // %13 = bitcast x86_amx %src to <256 x i32>
598 // store <256 x i32> %13, <256 x i32>* %addr, align 64
599 // %add = <256 x i32> %13, <256 x i32> %src2
600 // -->
601 // %13 = bitcast x86_amx %src to <256 x i32>
602 // call void @llvm.x86.tilestored64.internal(%row, %col, %addr,
603 // %stride64, %13)
604 // %14 = load <256 x i32>, %addr
605 // %add = <256 x i32> %14, <256 x i32> %src2
606 //
607 combineBitcastStore(Bitcast, ST);
608 // Delete user first.
609 DeadInsts.push_back(ST);
610 DeadInsts.push_back(Bitcast);
611 }
612 }
613 }
614
615 bool C = !DeadInsts.empty();
616
617 for (auto *Inst : DeadInsts)
618 Inst->eraseFromParent();
619
620 return C;
621}
622} // anonymous namespace
623
625 Function *F = BB->getParent();
626 IRBuilder<> Builder(&F->getEntryBlock().front());
627 const DataLayout &DL = F->getDataLayout();
628 unsigned AllocaAS = DL.getAllocaAddrSpace();
629 Type *V256I32Ty = VectorType::get(Builder.getInt32Ty(), 256, false);
630 AllocaInst *AllocaRes =
631 new AllocaInst(V256I32Ty, AllocaAS, "", F->getEntryBlock().begin());
632 BasicBlock::iterator Iter = AllocaRes->getIterator();
633 ++Iter;
634 Builder.SetInsertPoint(&*Iter);
635 Value *I8Ptr = Builder.CreateBitCast(AllocaRes, Builder.getPtrTy());
636 return I8Ptr;
637}
638
640 assert(TileDef->getType()->isX86_AMXTy() && "Not define tile!");
641 auto *II = cast<IntrinsicInst>(TileDef);
642
643 assert(II && "Not tile intrinsic!");
644 Value *Row = II->getOperand(0);
645 Value *Col = II->getOperand(1);
646
647 BasicBlock::iterator Iter = TileDef->getIterator();
648 IRBuilder<> Builder(++Iter);
649 Value *Stride = Builder.getInt64(64);
650 std::array<Value *, 5> Args = {Row, Col, Ptr, Stride, TileDef};
651
652 Instruction *TileStore = Builder.CreateIntrinsicWithoutFolding(
653 Intrinsic::x86_tilestored64_internal, Args);
654 return TileStore;
655}
656
657static void replaceWithTileLoad(Use &U, Value *Ptr, bool IsPHI = false) {
658 Value *V = U.get();
659 assert(V->getType()->isX86_AMXTy() && "Not define tile!");
660
661 // Get tile shape.
662 IntrinsicInst *II = nullptr;
663 if (IsPHI) {
664 Value *PhiOp = cast<PHINode>(V)->getIncomingValue(0);
665 II = cast<IntrinsicInst>(PhiOp);
666 } else {
668 }
669 Value *Row = II->getOperand(0);
670 Value *Col = II->getOperand(1);
671
672 Instruction *UserI = cast<Instruction>(U.getUser());
673 IRBuilder<> Builder(UserI);
674 Value *Stride = Builder.getInt64(64);
675 std::array<Value *, 4> Args = {Row, Col, Ptr, Stride};
676
677 Value *TileLoad =
678 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
679 UserI->replaceUsesOfWith(V, TileLoad);
680}
681
683 for (Instruction *V : I->users()) {
684 if (isa<PHINode>(V))
685 return true;
686 }
687 return false;
688}
689
690// Let all AMX tile data become volatile data, shorten the life range
691// of each tile register before fast register allocation.
692namespace {
693class X86VolatileTileData {
694 Function &F;
695
696public:
697 X86VolatileTileData(Function &Func) : F(Func) {}
698 Value *updatePhiIncomings(BasicBlock *BB,
699 SmallVector<Instruction *, 2> &Incomings);
700 void replacePhiDefWithLoad(Instruction *PHI, Value *StorePtr);
701 bool volatileTileData();
702 void volatileTilePHI(PHINode *PHI);
703 void volatileTileNonPHI(Instruction *I);
704};
705
706Value *X86VolatileTileData::updatePhiIncomings(
707 BasicBlock *BB, SmallVector<Instruction *, 2> &Incomings) {
708 Value *I8Ptr = getAllocaPos(BB);
709
710 for (auto *I : Incomings) {
711 User *Store = createTileStore(I, I8Ptr);
712
713 // All its uses (except phi) should load from stored mem.
714 for (Use &U : I->uses()) {
715 User *V = U.getUser();
716 if (isa<PHINode>(V) || V == Store)
717 continue;
718 replaceWithTileLoad(U, I8Ptr);
719 }
720 }
721 return I8Ptr;
722}
723
724void X86VolatileTileData::replacePhiDefWithLoad(Instruction *PHI,
725 Value *StorePtr) {
726 for (Use &U : PHI->uses())
727 replaceWithTileLoad(U, StorePtr, true);
728 PHI->eraseFromParent();
729}
730
731// Smilar with volatileTileNonPHI, this function only handle PHI Nodes
732// and their related AMX intrinsics.
733// 1) PHI Def should change to tileload.
734// 2) PHI Incoming Values should tilestored in just after their def.
735// 3) The mem of these tileload and tilestores should be same.
736// e.g.
737// ------------------------------------------------------
738// bb_dom:
739// ...
740// br i1 %bool.cond, label %if.else, label %if.then
741//
742// if.then:
743// def %t0 = ...
744// ...
745// use %t0
746// ...
747// br label %if.end
748//
749// if.else:
750// def %t1 = ...
751// br label %if.end
752//
753// if.end:
754// %td = phi x86_amx [ %t1, %if.else ], [ %t0, %if.then ]
755// ...
756// use %td
757// ------------------------------------------------------
758// -->
759// ------------------------------------------------------
760// bb_entry:
761// %mem = alloca <256 x i32>, align 1024 *
762// ...
763// bb_dom:
764// ...
765// br i1 %bool.cond, label %if.else, label %if.then
766//
767// if.then:
768// def %t0 = ...
769// call void @llvm.x86.tilestored64.internal(mem, %t0) *
770// ...
771// %t0` = call x86_amx @llvm.x86.tileloadd64.internal(mem)*
772// use %t0` *
773// ...
774// br label %if.end
775//
776// if.else:
777// def %t1 = ...
778// call void @llvm.x86.tilestored64.internal(mem, %t1) *
779// br label %if.end
780//
781// if.end:
782// ...
783// %td = call x86_amx @llvm.x86.tileloadd64.internal(mem) *
784// use %td
785// ------------------------------------------------------
786void X86VolatileTileData::volatileTilePHI(PHINode *PHI) {
787 BasicBlock *BB = PHI->getParent();
788 SmallVector<Instruction *, 2> Incomings;
789
790 for (unsigned I = 0, E = PHI->getNumIncomingValues(); I != E; ++I) {
791 Value *Op = PHI->getIncomingValue(I);
793 assert(Inst && "We shouldn't fold AMX instruction!");
794 Incomings.push_back(Inst);
795 }
796
797 Value *StorePtr = updatePhiIncomings(BB, Incomings);
798 replacePhiDefWithLoad(PHI, StorePtr);
799}
800
801// Store the defined tile and load it before use.
802// All its users are not PHI.
803// e.g.
804// ------------------------------------------------------
805// def %td = ...
806// ...
807// "use %td"
808// ------------------------------------------------------
809// -->
810// ------------------------------------------------------
811// def %td = ...
812// call void @llvm.x86.tilestored64.internal(mem, %td)
813// ...
814// %td2 = call x86_amx @llvm.x86.tileloadd64.internal(mem)
815// "use %td2"
816// ------------------------------------------------------
817void X86VolatileTileData::volatileTileNonPHI(Instruction *I) {
818 BasicBlock *BB = I->getParent();
819 Value *I8Ptr = getAllocaPos(BB);
820 User *Store = createTileStore(I, I8Ptr);
821
822 // All its uses should load from stored mem.
823 for (Use &U : I->uses()) {
824 User *V = U.getUser();
825 assert(!isa<PHINode>(V) && "PHI Nodes should be excluded!");
826 if (V != Store)
827 replaceWithTileLoad(U, I8Ptr);
828 }
829}
830
831// Volatile Tile Model:
832// 1) All the uses of tile data comes from tileload in time.
833// 2) All the defs of tile data tilestore into mem immediately.
834// For example:
835// --------------------------------------------------------------------------
836// %t1 = call x86_amx @llvm.x86.tileloadd64.internal(m, k, ...) key
837// %t2 = call x86_amx @llvm.x86.tileloadd64.internal(k, n, ...)
838// %t3 = call x86_amx @llvm.x86.tileloadd64.internal(m, n, ...) amx
839// %td = tail call x86_amx @llvm.x86.tdpbssd.internal(m, n, k, t1, t2, t3)
840// call void @llvm.x86.tilestored64.internal(... td) area
841// --------------------------------------------------------------------------
842// 3) No terminator, call or other amx instructions in the key amx area.
843bool X86VolatileTileData::volatileTileData() {
844 bool Changed = false;
845 for (BasicBlock &BB : F) {
846 SmallVector<Instruction *, 2> PHIInsts;
847 SmallVector<Instruction *, 8> AMXDefInsts;
848
849 for (Instruction &I : BB) {
850 if (!I.getType()->isX86_AMXTy())
851 continue;
852 if (isa<PHINode>(&I))
853 PHIInsts.push_back(&I);
854 else
855 AMXDefInsts.push_back(&I);
856 }
857
858 // First we "volatile" the non-phi related amx intrinsics.
859 for (Instruction *I : AMXDefInsts) {
860 if (isIncomingOfPHI(I))
861 continue;
862 // Skip ACE-only intrinsics - ACE (Palette 2) doesn't have
863 // TILELOADD/TILESTORED instructions needed for volatile model.
865 continue;
866 volatileTileNonPHI(I);
867 Changed = true;
868 }
869
870 for (Instruction *I : PHIInsts) {
871 // Skip PHI nodes with ACE intrinsic incoming values.
873 continue;
874 volatileTilePHI(dyn_cast<PHINode>(I));
875 Changed = true;
876 }
877 }
878 return Changed;
879}
880
881} // anonymous namespace
882
883namespace {
884
885class X86LowerAMXCast {
886 Function &Func;
887 std::unique_ptr<DominatorTree> DT;
888
889public:
890 X86LowerAMXCast(Function &F) : Func(F), DT(nullptr) {}
891 bool combineCastStore(IntrinsicInst *Cast, StoreInst *ST);
892 bool combineLoadCast(IntrinsicInst *Cast, LoadInst *LD);
893 bool combineTilezero(IntrinsicInst *Cast);
894 bool combineLdSt(SmallVectorImpl<Instruction *> &Casts);
895 bool combineAMXcast(TargetLibraryInfo *TLI);
896 bool transformAMXCast(IntrinsicInst *AMXCast);
897 bool transformAllAMXCast();
898 bool optimizeAMXCastFromPhi(IntrinsicInst *CI, PHINode *PN,
899 SmallSetVector<Instruction *, 16> &DeadInst);
900};
901
902static bool DCEInstruction(Instruction *I,
903 SmallSetVector<Instruction *, 16> &WorkList,
904 const TargetLibraryInfo *TLI) {
908
909 // Null out all of the instruction's operands to see if any operand becomes
910 // dead as we go.
911 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
912 Value *OpV = I->getOperand(i);
913 I->setOperand(i, nullptr);
914
915 if (!OpV->use_empty() || I == OpV)
916 continue;
917
918 // If the operand is an instruction that became dead as we nulled out the
919 // operand, and if it is 'trivially' dead, delete it in a future loop
920 // iteration.
921 if (Instruction *OpI = dyn_cast<Instruction>(OpV)) {
923 WorkList.insert(OpI);
924 }
925 }
926 }
927 I->eraseFromParent();
928 return true;
929 }
930 return false;
931}
932
933/// This function handles following case
934///
935/// A -> B amxcast
936/// PHI
937/// B -> A amxcast
938///
939/// All the related PHI nodes can be replaced by new PHI nodes with type A.
940/// The uses of \p CI can be changed to the new PHI node corresponding to \p PN.
941bool X86LowerAMXCast::optimizeAMXCastFromPhi(
942 IntrinsicInst *CI, PHINode *PN,
943 SmallSetVector<Instruction *, 16> &DeadInst) {
944 IRBuilder<> Builder(CI);
945 Value *Src = CI->getOperand(0);
946 Type *SrcTy = Src->getType(); // Type B
947 Type *DestTy = CI->getType(); // Type A
948
949 SmallVector<PHINode *, 4> PhiWorklist;
950 SmallSetVector<PHINode *, 4> OldPhiNodes;
951
952 // Find all of the A->B casts and PHI nodes.
953 // We need to inspect all related PHI nodes, but PHIs can be cyclic, so
954 // OldPhiNodes is used to track all known PHI nodes, before adding a new
955 // PHI to PhiWorklist, it is checked against and added to OldPhiNodes first.
956 PhiWorklist.push_back(PN);
957 OldPhiNodes.insert(PN);
958 while (!PhiWorklist.empty()) {
959 auto *OldPN = PhiWorklist.pop_back_val();
960 for (unsigned I = 0; I < OldPN->getNumOperands(); ++I) {
961 Value *IncValue = OldPN->getIncomingValue(I);
962 // TODO: currently, We ignore cases where it is a const. In the future, we
963 // might support const.
964 if (isa<Constant>(IncValue)) {
965 auto *IncConst = dyn_cast<Constant>(IncValue);
966 if (!isa<UndefValue>(IncValue) && !IncConst->isNullValue())
967 return false;
968 Value *Row = nullptr, *Col = nullptr;
969 unsigned ConsumerOpNo = 0;
970 IntrinsicInst *Consumer = getTileConsumer(OldPN, ConsumerOpNo);
971 if (Consumer)
972 std::tie(Row, Col) = getShape(Consumer, ConsumerOpNo);
973 // TODO: If it is not constant the Row and Col must domoniate tilezero
974 // that we are going to create.
975 if (!Row || !Col || !isa<Constant>(Row) || !isa<Constant>(Col))
976 return false;
977 // Create tilezero at the end of incoming block.
978 auto *Block = OldPN->getIncomingBlock(I);
979 BasicBlock::iterator Iter = Block->getTerminator()->getIterator();
980 Instruction *NewInst = Builder.CreateIntrinsicWithoutFolding(
981 getTilezeroIntrinsic(Consumer), {}, {Row, Col});
982 NewInst->moveBefore(Iter);
983 NewInst = Builder.CreateIntrinsicWithoutFolding(
984 Intrinsic::x86_cast_tile_to_vector, {IncValue->getType()},
985 {NewInst});
986 NewInst->moveBefore(Iter);
987 // Replace InValue with new Value.
988 OldPN->setIncomingValue(I, NewInst);
989 IncValue = NewInst;
990 }
991
992 if (auto *PNode = dyn_cast<PHINode>(IncValue)) {
993 if (OldPhiNodes.insert(PNode))
994 PhiWorklist.push_back(PNode);
995 continue;
996 }
997 Instruction *ACI = dyn_cast<Instruction>(IncValue);
998 if (ACI && isAMXCast(ACI)) {
999 // Verify it's a A->B cast.
1000 Type *TyA = ACI->getOperand(0)->getType();
1001 Type *TyB = ACI->getType();
1002 if (TyA != DestTy || TyB != SrcTy)
1003 return false;
1004 continue;
1005 }
1006 return false;
1007 }
1008 }
1009
1010 // Check that each user of each old PHI node is something that we can
1011 // rewrite, so that all of the old PHI nodes can be cleaned up afterwards.
1012 for (auto *OldPN : OldPhiNodes) {
1013 for (Instruction *V : OldPN->users()) {
1014 if (isAMXCast(V)) {
1015 // Verify it's a B->A cast.
1016 Type *TyB = V->getOperand(0)->getType();
1017 Type *TyA = V->getType();
1018 if (TyA != DestTy || TyB != SrcTy)
1019 return false;
1020 } else if (auto *PHI = dyn_cast<PHINode>(V)) {
1021 // As long as the user is another old PHI node, then even if we don't
1022 // rewrite it, the PHI web we're considering won't have any users
1023 // outside itself, so it'll be dead.
1024 // example:
1025 // bb.0:
1026 // %0 = amxcast ...
1027 // bb.1:
1028 // %1 = amxcast ...
1029 // bb.2:
1030 // %goodphi = phi %0, %1
1031 // %3 = amxcast %goodphi
1032 // bb.3:
1033 // %goodphi2 = phi %0, %goodphi
1034 // %4 = amxcast %goodphi2
1035 // When optimizeAMXCastFromPhi process %3 and %goodphi, %goodphi2 is
1036 // outside the phi-web, so the combination stop When
1037 // optimizeAMXCastFromPhi process %4 and %goodphi2, the optimization
1038 // will be done.
1039 if (OldPhiNodes.count(PHI) == 0)
1040 return false;
1041 } else
1042 return false;
1043 }
1044 }
1045
1046 // For each old PHI node, create a corresponding new PHI node with a type A.
1047 SmallDenseMap<PHINode *, PHINode *> NewPNodes;
1048 for (auto *OldPN : OldPhiNodes) {
1049 Builder.SetInsertPoint(OldPN);
1050 PHINode *NewPN = Builder.CreatePHI(DestTy, OldPN->getNumOperands());
1051 NewPNodes[OldPN] = NewPN;
1052 }
1053
1054 // Fill in the operands of new PHI nodes.
1055 for (auto *OldPN : OldPhiNodes) {
1056 PHINode *NewPN = NewPNodes[OldPN];
1057 for (unsigned j = 0, e = OldPN->getNumOperands(); j != e; ++j) {
1058 Value *V = OldPN->getOperand(j);
1059 Value *NewV = nullptr;
1061 // There should not be a AMXcast from a const.
1062 if (ACI && isAMXCast(ACI))
1063 NewV = ACI->getOperand(0);
1064 else if (auto *PrevPN = dyn_cast<PHINode>(V))
1065 NewV = NewPNodes[PrevPN];
1066 assert(NewV);
1067 NewPN->addIncoming(NewV, OldPN->getIncomingBlock(j));
1068 }
1069 }
1070
1071 // Traverse all accumulated PHI nodes and process its users,
1072 // which are Stores and BitcCasts. Without this processing
1073 // NewPHI nodes could be replicated and could lead to extra
1074 // moves generated after DeSSA.
1075 // If there is a store with type B, change it to type A.
1076
1077 // Replace users of BitCast B->A with NewPHI. These will help
1078 // later to get rid of a closure formed by OldPHI nodes.
1079 for (auto *OldPN : OldPhiNodes) {
1080 PHINode *NewPN = NewPNodes[OldPN];
1081 for (Instruction *V : make_early_inc_range(OldPN->users())) {
1082 if (isAMXCast(V)) {
1083 Type *TyB = V->getOperand(0)->getType();
1084 Type *TyA = V->getType();
1085 assert(TyA == DestTy && TyB == SrcTy);
1086 (void)TyA;
1087 (void)TyB;
1088 V->replaceAllUsesWith(NewPN);
1089 DeadInst.insert(V);
1090 } else if (auto *PHI = dyn_cast<PHINode>(V)) {
1091 // We don't need to push PHINode into DeadInst since they are operands
1092 // of rootPN DCE can safely delete rootPN's operands if rootPN is dead.
1093 assert(OldPhiNodes.contains(PHI));
1094 (void)PHI;
1095 } else
1096 llvm_unreachable("all uses should be handled");
1097 }
1098 }
1099 return true;
1100}
1101
1102// %43 = call <256 x i32> @llvm.x86.cast.tile.to.vector.v256i32(x86_amx %42)
1103// store <256 x i32> %43, <256 x i32>* %p, align 64
1104// -->
1105// call void @llvm.x86.tilestored64.internal(i16 %row, i16 %col, i8* %p,
1106// i64 64, x86_amx %42)
1107bool X86LowerAMXCast::combineCastStore(IntrinsicInst *Cast, StoreInst *ST) {
1108 Value *Tile = Cast->getOperand(0);
1109
1110 assert(Tile->getType()->isX86_AMXTy() && "Not Tile Operand!");
1111
1112 // TODO: Specially handle the multi-use case.
1113 if (!Tile->hasOneUse())
1114 return false;
1115
1116 auto *II = cast<IntrinsicInst>(Tile);
1117 // ACE v1 doesn't have TILESTORED, so an ACE tile cannot be stored this way.
1118 // ACE uses struct-based API with vector load/store.
1120 return false;
1121 // Tile is output from AMX intrinsic. The first operand of the
1122 // intrinsic is row, the second operand of the intrinsic is column.
1123 Value *Row = II->getOperand(0);
1124 Value *Col = II->getOperand(1);
1125
1126 IRBuilder<> Builder(ST);
1127
1128 // Stride should be equal to col(measured by bytes)
1129 Value *Stride = Builder.CreateSExt(Col, Builder.getInt64Ty());
1130 Value *I8Ptr = Builder.CreateBitCast(ST->getOperand(1), Builder.getPtrTy());
1131 std::array<Value *, 5> Args = {Row, Col, I8Ptr, Stride, Tile};
1132 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
1133 return true;
1134}
1135
1136// %65 = load <256 x i32>, <256 x i32>* %p, align 64
1137// %66 = call x86_amx @llvm.x86.cast.vector.to.tile(<256 x i32> %65)
1138// -->
1139// %66 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
1140// i8* %p, i64 64)
1141bool X86LowerAMXCast::combineLoadCast(IntrinsicInst *Cast, LoadInst *LD) {
1142 bool EraseLoad = true;
1143 Value *Row = nullptr, *Col = nullptr;
1144 Use &U = *(Cast->use_begin());
1145 unsigned OpNo = U.getOperandNo();
1146 auto *II = cast<IntrinsicInst>(U.getUser());
1147 // TODO: If it is cast intrinsic or phi node, we can propagate the
1148 // shape information through def-use chain.
1149 if (!isAMXIntrinsic(II))
1150 return false;
1151 // ACE v1 doesn't have TILELOADD, so an ACE tile cannot be loaded this way.
1152 // ACE uses struct-based API with vector load/store.
1154 return false;
1155 std::tie(Row, Col) = getShape(II, OpNo);
1156 IRBuilder<> Builder(LD);
1157 Value *I8Ptr;
1158
1159 // To save compiling time, we create dominator tree when it is really needed.
1160 if (!DT)
1161 DT.reset(new DominatorTree(Func));
1162 if (!DT->dominates(Row, LD) || !DT->dominates(Col, LD)) {
1163 // store the value to stack and reload it from stack before cast.
1164 auto *AllocaAddr =
1165 createAllocaInstAtEntry(Builder, Cast->getParent(), LD->getType());
1166 Builder.SetInsertPoint(&*std::next(LD->getIterator()));
1167 Builder.CreateStore(LD, AllocaAddr);
1168
1169 Builder.SetInsertPoint(Cast);
1170 I8Ptr = Builder.CreateBitCast(AllocaAddr, Builder.getPtrTy());
1171 EraseLoad = false;
1172 } else {
1173 I8Ptr = Builder.CreateBitCast(LD->getOperand(0), Builder.getPtrTy());
1174 }
1175 // Stride should be equal to col(measured by bytes)
1176 Value *Stride = Builder.CreateSExt(Col, Builder.getInt64Ty());
1177 std::array<Value *, 4> Args = {Row, Col, I8Ptr, Stride};
1178
1179 Value *NewInst =
1180 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
1181 Cast->replaceAllUsesWith(NewInst);
1182
1183 return EraseLoad;
1184}
1185
1186// %19 = tail call x86_amx @llvm.x86.cast.vector.to.tile.v256i32(<256 x i32> zeroinitializer)
1187// -->
1188// %19 = tail call x86_amx @llvm.x86.tilezero.internal(i16 %row, i16 %col)
1189bool X86LowerAMXCast::combineTilezero(IntrinsicInst *Cast) {
1190 Value *Row = nullptr, *Col = nullptr;
1191 Use &U = *(Cast->use_begin());
1192 unsigned OpNo = U.getOperandNo();
1193 auto *II = cast<IntrinsicInst>(U.getUser());
1194 if (!isAMXIntrinsic(II))
1195 return false;
1196
1197 std::tie(Row, Col) = getShape(II, OpNo);
1198
1199 IRBuilder<> Builder(Cast);
1200 Value *NewInst =
1201 Builder.CreateIntrinsic(getTilezeroIntrinsic(II), {}, {Row, Col});
1202 Cast->replaceAllUsesWith(NewInst);
1203 return true;
1204}
1205
1206bool X86LowerAMXCast::combineLdSt(SmallVectorImpl<Instruction *> &Casts) {
1207 bool Change = false;
1208 for (auto *Cast : Casts) {
1209 auto *II = cast<IntrinsicInst>(Cast);
1210 // %43 = call <256 x i32> @llvm.x86.cast.tile.to.vector(x86_amx %42)
1211 // store <256 x i32> %43, <256 x i32>* %p, align 64
1212 // -->
1213 // call void @llvm.x86.tilestored64.internal(i16 %row, i16 %col, i8* %p,
1214 // i64 64, x86_amx %42)
1215 if (II->getIntrinsicID() == Intrinsic::x86_cast_tile_to_vector) {
1216 SmallVector<Instruction *, 2> DeadStores;
1217 for (User *U : Cast->users()) {
1218 StoreInst *Store = dyn_cast<StoreInst>(U);
1219 if (!Store)
1220 continue;
1221 if (combineCastStore(cast<IntrinsicInst>(Cast), Store)) {
1222 DeadStores.push_back(Store);
1223 Change = true;
1224 }
1225 }
1226 for (auto *Store : DeadStores)
1227 Store->eraseFromParent();
1228 } else { // x86_cast_vector_to_tile
1229 // %19 = tail call x86_amx @llvm.x86.cast.vector.to.tile.v256i32(<256 x i32> zeroinitializer)
1230 // -->
1231 // %19 = tail call x86_amx @llvm.x86.tilezero.internal(i16 %row, i16 %col)
1232 if (isa<ConstantAggregateZero>(Cast->getOperand(0))) {
1233 Change |= combineTilezero(cast<IntrinsicInst>(Cast));
1234 continue;
1235 }
1236
1237 auto *Load = dyn_cast<LoadInst>(Cast->getOperand(0));
1238 if (!Load || !Load->hasOneUse())
1239 continue;
1240 // %65 = load <256 x i32>, <256 x i32>* %p, align 64
1241 // %66 = call x86_amx @llvm.x86.cast.vector.to.tile(<256 x i32> %65)
1242 // -->
1243 // %66 = call x86_amx @llvm.x86.tileloadd64.internal(i16 %row, i16 %col,
1244 // i8* %p, i64 64)
1245 if (combineLoadCast(cast<IntrinsicInst>(Cast), Load)) {
1246 // Set the operand is null so that load instruction can be erased.
1247 Cast->setOperand(0, nullptr);
1248 Load->eraseFromParent();
1249 Change = true;
1250 }
1251 }
1252 }
1253 return Change;
1254}
1255
1256bool X86LowerAMXCast::combineAMXcast(TargetLibraryInfo *TLI) {
1257 bool Change = false;
1258 // Collect tile cast instruction.
1259 SmallVector<Instruction *, 8> Vec2TileInsts;
1260 SmallVector<Instruction *, 8> Tile2VecInsts;
1261 SmallVector<Instruction *, 8> PhiCastWorkList;
1262 SmallSetVector<Instruction *, 16> DeadInst;
1263 for (BasicBlock &BB : Func) {
1264 for (Instruction &I : BB) {
1265 Value *Vec;
1266 if (match(&I,
1268 Vec2TileInsts.push_back(&I);
1270 m_Value(Vec))))
1271 Tile2VecInsts.push_back(&I);
1272 }
1273 }
1274
1275 auto Convert = [&](SmallVectorImpl<Instruction *> &Insts, Intrinsic::ID IID) {
1276 for (auto *Inst : Insts) {
1277 for (User *U : Inst->users()) {
1278 IntrinsicInst *II = dyn_cast<IntrinsicInst>(U);
1279 if (!II || II->getIntrinsicID() != IID)
1280 continue;
1281 // T1 = vec2tile V0
1282 // V2 = tile2vec T1
1283 // V3 = OP V2
1284 // -->
1285 // T1 = vec2tile V0
1286 // V2 = tile2vec T1
1287 // V3 = OP V0
1288 II->replaceAllUsesWith(Inst->getOperand(0));
1289 Change = true;
1290 }
1291 }
1292 };
1293
1294 Convert(Vec2TileInsts, Intrinsic::x86_cast_tile_to_vector);
1295 Convert(Tile2VecInsts, Intrinsic::x86_cast_vector_to_tile);
1296
1297 SmallVector<Instruction *, 8> LiveCasts;
1298 auto EraseInst = [&](SmallVectorImpl<Instruction *> &Insts) {
1299 for (auto *Inst : Insts) {
1300 if (Inst->use_empty()) {
1301 Inst->eraseFromParent();
1302 Change = true;
1303 } else {
1304 LiveCasts.push_back(Inst);
1305 }
1306 }
1307 };
1308
1309 EraseInst(Vec2TileInsts);
1310 EraseInst(Tile2VecInsts);
1311 LLVM_DEBUG(dbgs() << "[LowerAMXTYpe][combineAMXcast] IR dump after combine "
1312 "Vec2Tile and Tile2Vec:\n";
1313 Func.dump());
1314 Change |= combineLdSt(LiveCasts);
1315 EraseInst(LiveCasts);
1316 LLVM_DEBUG(dbgs() << "[LowerAMXTYpe][combineAMXcast] IR dump after combine "
1317 "AMXCast and load/store:\n";
1318 Func.dump());
1319
1320 // Handle the A->B->A cast, and there is an intervening PHI node.
1321 for (BasicBlock &BB : Func) {
1322 for (Instruction &I : BB) {
1323 if (isAMXCast(&I)) {
1324 if (isa<PHINode>(I.getOperand(0)))
1325 PhiCastWorkList.push_back(&I);
1326 }
1327 }
1328 }
1329 for (auto *I : PhiCastWorkList) {
1330 // We skip the dead Amxcast.
1331 if (DeadInst.contains(I))
1332 continue;
1333 PHINode *PN = cast<PHINode>(I->getOperand(0));
1334 if (optimizeAMXCastFromPhi(cast<IntrinsicInst>(I), PN, DeadInst)) {
1335 DeadInst.insert(PN);
1336 Change = true;
1337 }
1338 }
1339
1340 // Since we create new phi and merge AMXCast, some old phis and AMXCast might
1341 // have no uses. We do some DeadCodeElimination for them.
1342 while (!DeadInst.empty()) {
1343 Instruction *I = DeadInst.pop_back_val();
1344 Change |= DCEInstruction(I, DeadInst, TLI);
1345 }
1346 LLVM_DEBUG(dbgs() << "[LowerAMXTYpe][combineAMXcast] IR dump after "
1347 "optimizeAMXCastFromPhi:\n";
1348 Func.dump());
1349 return Change;
1350}
1351
1352// There might be remaining AMXcast after combineAMXcast and they should be
1353// handled elegantly.
1354bool X86LowerAMXCast::transformAMXCast(IntrinsicInst *AMXCast) {
1355 IRBuilder<> Builder(AMXCast);
1356 AllocaInst *AllocaAddr;
1357 Value *I8Ptr, *Stride;
1358 auto *Src = AMXCast->getOperand(0);
1359
1360 auto Prepare = [&](Type *MemTy) {
1361 AllocaAddr = createAllocaInstAtEntry(Builder, AMXCast->getParent(), MemTy);
1362 I8Ptr = Builder.CreateBitCast(AllocaAddr, Builder.getPtrTy());
1363 Stride = Builder.getInt64(64);
1364 };
1365
1366 if (AMXCast->getType()->isX86_AMXTy()) {
1367 // %2 = amxcast <225 x i32> %src to x86_amx
1368 // call void @llvm.x86.tilestored64.internal(i16 15, i16 60,
1369 // i8* %addr3, i64 60, x86_amx %2)
1370 // -->
1371 // %addr = alloca <225 x i32>, align 64
1372 // store <225 x i32> %src, <225 x i32>* %addr, align 64
1373 // %addr2 = bitcast <225 x i32>* %addr to i8*
1374 // %2 = call x86_amx @llvm.x86.tileloadd64.internal(i16 15, i16 60,
1375 // i8* %addr2,
1376 // i64 60)
1377 // call void @llvm.x86.tilestored64.internal(i16 15, i16 60,
1378 // i8* %addr3, i64 60, x86_amx %2)
1379 if (AMXCast->use_empty()) {
1380 AMXCast->eraseFromParent();
1381 return true;
1382 }
1383 Use &U = *(AMXCast->use_begin());
1384 unsigned OpNo = U.getOperandNo();
1385 auto *II = dyn_cast<IntrinsicInst>(U.getUser());
1386 if (!II)
1387 return false; // May be bitcast from x86amx to <256 x i32>.
1388 if (isACEOnlyIntrinsic(II)) {
1389 Value *Row = nullptr, *Col = nullptr;
1390 std::tie(Row, Col) = getShape(II, OpNo);
1391 Value *NewInst = createACETileFromVector(Builder, Src, Row, Col);
1392 AMXCast->replaceAllUsesWith(NewInst);
1393 AMXCast->eraseFromParent();
1394 return true;
1395 }
1396 Prepare(AMXCast->getOperand(0)->getType());
1397 Builder.CreateStore(Src, AllocaAddr);
1398 // TODO we can pick an constant operand for the shape.
1399 Value *Row = nullptr, *Col = nullptr;
1400 std::tie(Row, Col) = getShape(II, OpNo);
1401 std::array<Value *, 4> Args = {
1402 Row, Col, I8Ptr, Builder.CreateSExt(Col, Builder.getInt64Ty())};
1403 Value *NewInst =
1404 Builder.CreateIntrinsic(Intrinsic::x86_tileloadd64_internal, Args);
1405 AMXCast->replaceAllUsesWith(NewInst);
1406 AMXCast->eraseFromParent();
1407 } else {
1408 // %2 = amxcast x86_amx %src to <225 x i32>
1409 // -->
1410 // %addr = alloca <225 x i32>, align 64
1411 // %addr2 = bitcast <225 x i32>* to i8*
1412 // call void @llvm.x86.tilestored64.internal(i16 %row, i16 %col,
1413 // i8* %addr2, i64 %stride)
1414 // %2 = load <225 x i32>, <225 x i32>* %addr, align 64
1415 auto *II = dyn_cast<IntrinsicInst>(Src);
1416 if (!II)
1417 return false; // May be bitcast from <256 x i32> to x86amx.
1418 if (isACEOnlyIntrinsic(II)) {
1419 Value *NewInst =
1420 createVectorFromACETile(Builder, Src, II->getOperand(0),
1421 II->getOperand(1), AMXCast->getType());
1422 AMXCast->replaceAllUsesWith(NewInst);
1423 AMXCast->eraseFromParent();
1424 return true;
1425 }
1426 Prepare(AMXCast->getType());
1427 Value *Row = II->getOperand(0);
1428 Value *Col = II->getOperand(1);
1429 std::array<Value *, 5> Args = {
1430 Row, Col, I8Ptr, Builder.CreateSExt(Col, Builder.getInt64Ty()), Src};
1431 Builder.CreateIntrinsic(Intrinsic::x86_tilestored64_internal, Args);
1432 Value *NewInst = Builder.CreateLoad(AMXCast->getType(), AllocaAddr);
1433 AMXCast->replaceAllUsesWith(NewInst);
1434 AMXCast->eraseFromParent();
1435 }
1436
1437 return true;
1438}
1439
1440bool X86LowerAMXCast::transformAllAMXCast() {
1441 bool Change = false;
1442 // Collect tile cast instruction.
1443 SmallVector<Instruction *, 8> WorkLists;
1444 for (BasicBlock &BB : Func) {
1445 for (Instruction &I : BB) {
1446 if (isAMXCast(&I))
1447 WorkLists.push_back(&I);
1448 }
1449 }
1450
1451 for (auto *Inst : WorkLists) {
1452 Change |= transformAMXCast(cast<IntrinsicInst>(Inst));
1453 }
1454
1455 return Change;
1456}
1457
1458bool lowerAmxType(Function &F, const TargetMachine *TM,
1459 TargetLibraryInfo *TLI) {
1460 // Performance optimization: most code doesn't use AMX, so return early if
1461 // there are no instructions that produce AMX values. This is sufficient, as
1462 // AMX arguments and constants are not allowed -- so any producer of an AMX
1463 // value must be an instruction.
1464 // TODO: find a cheaper way for this, without looking at all instructions.
1465 if (!containsAMXCode(F))
1466 return false;
1467
1468 bool C = false;
1469 X86LowerAMXCast LAC(F);
1470 C |= LAC.combineAMXcast(TLI);
1471 // There might be remaining AMXcast after combineAMXcast and they should be
1472 // handled elegantly.
1473 C |= LAC.transformAllAMXCast();
1474
1475 X86LowerAMXType LAT(F);
1476 C |= LAT.visit();
1477
1478 // Prepare for fast register allocation at O0.
1479 // Todo: May better check the volatile model of AMX code, not just
1480 // by checking Attribute::OptimizeNone and CodeGenOptLevel::None.
1481 if (TM->getOptLevel() == CodeGenOptLevel::None) {
1482 // If Front End not use O0 but the Mid/Back end use O0, (e.g.
1483 // "Clang -O2 -S -emit-llvm t.c" + "llc t.ll") we should make
1484 // sure the amx data is volatile, that is necessary for AMX fast
1485 // register allocation.
1486 // This spills tiles with TILESTORED and reloads them with TILELOADD, which
1487 // ACE cannot do under palette 2. volatileTileData leaves ACE tiles alone
1488 // per value, so the tile registers stay live and X86FastPreTileConfig
1489 // spills them instead.
1490 if (!F.hasFnAttribute(Attribute::OptimizeNone)) {
1491 X86VolatileTileData VTD(F);
1492 C = VTD.volatileTileData() || C;
1493 }
1494 }
1495
1496 return C;
1497}
1498
1499} // anonymous namespace
1500
1504 bool Changed = lowerAmxType(F, TM, &TLI);
1505 if (!Changed)
1506 return PreservedAnalyses::all();
1507
1510 return PA;
1511}
1512
1513namespace {
1514
1515class X86LowerAMXTypeLegacyPass : public FunctionPass {
1516public:
1517 static char ID;
1518
1519 X86LowerAMXTypeLegacyPass() : FunctionPass(ID) {}
1520
1521 bool runOnFunction(Function &F) override {
1522 TargetMachine *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
1524 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1525 return lowerAmxType(F, TM, TLI);
1526 }
1527
1528 void getAnalysisUsage(AnalysisUsage &AU) const override {
1529 AU.setPreservesCFG();
1530 AU.addRequired<TargetPassConfig>();
1531 AU.addRequired<TargetLibraryInfoWrapperPass>();
1532 }
1533};
1534
1535} // anonymous namespace
1536
1537static const char PassName[] = "Lower AMX type for load/store";
1538char X86LowerAMXTypeLegacyPass::ID = 0;
1539INITIALIZE_PASS_BEGIN(X86LowerAMXTypeLegacyPass, DEBUG_TYPE, PassName, false,
1540 false)
1543INITIALIZE_PASS_END(X86LowerAMXTypeLegacyPass, DEBUG_TYPE, PassName, false,
1544 false)
1545
1547 return new X86LowerAMXTypeLegacyPass();
1548}
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool DCEInstruction(Instruction *I, SmallSetVector< Instruction *, 16 > &WorkList, const TargetLibraryInfo *TLI)
Definition DCE.cpp:55
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
This file implements a set that has insertion order iteration characteristics.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
static ShapeT getShape(MachineRegisterInfo *MRI, Register TileReg)
static const char PassName[]
static bool isAMXCast(Instruction *II)
static Value * createACETileFromVector(IRBuilder<> &Builder, Value *Vec, Value *Row, Value *Col)
static Value * getRowFromCol(Instruction *II, Value *V, unsigned Granularity)
static constexpr unsigned ACENumTileRows
static void replaceWithTileLoad(Use &U, Value *Ptr, bool IsPHI=false)
static Instruction * createTileStore(Instruction *TileDef, Value *Ptr)
static Value * getAllocaPos(BasicBlock *BB)
static Intrinsic::ID getTilezeroIntrinsic(IntrinsicInst *Consumer)
static bool containsAMXCode(Function &F)
static constexpr unsigned ACERowNumElts
std::pair< Value *, Value * > getShape(IntrinsicInst *II, unsigned OpNo)
static IntrinsicInst * getTileConsumer(PHINode *Phi, unsigned &OpNo)
static bool hasACEIncomingValue(PHINode *PHI)
static bool isIncomingOfPHI(Instruction *I)
static bool isAMXIntrinsic(Value *I)
static Instruction * getFirstNonAllocaInTheEntryBlock(Function &F)
static bool isACEOnlyIntrinsic(Instruction *I)
static AllocaInst * createAllocaInstAtEntry(IRBuilder<> &Builder, BasicBlock *BB, Type *Ty)
static Value * createVectorFromACETile(IRBuilder<> &Builder, Value *Tile, Value *Row, Value *Col, Type *VecTy)
an instruction to allocate memory on the stack
void setAlignment(Align Align)
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
LLVM Basic Block Representation.
Definition BasicBlock.h:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:212
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:169
This class represents a no-op cast from one type to another.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:838
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
Value * CreateUDiv(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition IRBuilder.h:1475
ConstantInt * getInt16(uint16_t C)
Get a constant 16-bit value.
Definition IRBuilder.h:466
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2990
LLVM_ABI void moveBefore(InstListType::iterator InsertPos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
iterator_range< user_iterator > users()
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
An instruction for reading from memory.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
Definition SetVector.h:258
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
value_type pop_back_val()
Definition SetVector.h:285
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:278
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition Type.h:202
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
void setOperand(unsigned i, Value *Val)
Definition User.h:212
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition User.cpp:21
Value * getOperand(unsigned i) const
Definition User.h:207
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:548
use_iterator use_begin()
Definition Value.h:366
bool use_empty() const
Definition Value.h:348
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:83
@ Bitcast
Perform the operation on a different, but equivalently sized type.
bool match(Val *V, const Pattern &P)
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI 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:1833
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:649
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Definition Local.cpp:409
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
auto post_order(const T &G)
Post-order traversal of a graph.
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
LLVM_ABI bool salvageKnowledge(Instruction *I, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert if before I.
DWARFExpression::Operation Op
FunctionPass * createX86LowerAMXTypeLegacyPass()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.