@@ -473,6 +473,12 @@ void CustomSafeOptPass::visitCallInst(CallInst& C)
473
473
break ;
474
474
}
475
475
476
+ case GenISAIntrinsic::GenISA_ldrawvector_indexed:
477
+ {
478
+ visitLdRawVec (inst);
479
+ break ;
480
+ }
481
+
476
482
default :
477
483
break ;
478
484
}
@@ -1339,6 +1345,56 @@ void IGC::CustomSafeOptPass::visitLdptr(llvm::CallInst* inst)
1339
1345
}
1340
1346
}
1341
1347
1348
+
1349
+ void IGC::CustomSafeOptPass::visitLdRawVec (llvm::CallInst* inst)
1350
+ {
1351
+ // Try to optimize and remove vector ld raw and change to scalar ld raw
1352
+
1353
+ // %a = call <4 x float> @llvm.genx.GenISA.ldrawvector.indexed.v4f32.p1441792f32(
1354
+ // .....float addrspace(1441792) * %243, i32 %offset, i32 4, i1 false), !dbg !216
1355
+ // %b = extractelement <4 x float> % 245, i32 0, !dbg !216
1356
+
1357
+ // into
1358
+
1359
+ // %new_offset = add i32 %offset, 0, !dbg !216
1360
+ // %b = call float @llvm.genx.GenISA.ldraw.indexed.f32.p1441792f32.i32.i32.i1(
1361
+ // .....float addrspace(1441792) * %251, i32 %new_offset, i32 4, i1 false)
1362
+
1363
+ if (inst->hasOneUse () &&
1364
+ isa<ExtractElementInst>(inst->user_back ()))
1365
+ {
1366
+ auto EE = cast<ExtractElementInst>(inst->user_back ());
1367
+ if (auto constIndex = dyn_cast<ConstantInt>(EE->getIndexOperand ()))
1368
+ {
1369
+ llvm::IRBuilder<> builder (inst);
1370
+
1371
+ llvm::SmallVector<llvm::Type*, 2 > ovldtypes{
1372
+ EE->getType (), // float type
1373
+ inst->getOperand (0 )->getType (),
1374
+ };
1375
+
1376
+ // For new_offset we need to take into acount the index of the Extract
1377
+ // and convert it to bytes and add it to the existing offset
1378
+ auto new_offset = constIndex->getZExtValue () * 4 ;
1379
+
1380
+ llvm::SmallVector<llvm::Value*, 4 > new_args{
1381
+ inst->getOperand (0 ),
1382
+ builder.CreateAdd (inst->getOperand (1 ),builder.getInt32 ((unsigned )new_offset)),
1383
+ inst->getOperand (2 ),
1384
+ inst->getOperand (3 )
1385
+ };
1386
+
1387
+ Function* pLdraw_indexed_intrinsic = llvm::GenISAIntrinsic::getDeclaration (
1388
+ inst->getModule (),
1389
+ GenISAIntrinsic::GenISA_ldraw_indexed,
1390
+ ovldtypes);
1391
+
1392
+ llvm::Value* ldraw_indexed = builder.CreateCall (pLdraw_indexed_intrinsic, new_args, " " );
1393
+ EE->replaceAllUsesWith (ldraw_indexed);
1394
+ }
1395
+ }
1396
+ }
1397
+
1342
1398
void IGC::CustomSafeOptPass::visitSampleBptr (llvm::SampleIntrinsic* sampleInst)
1343
1399
{
1344
1400
// sampleB with bias_value==0 -> sample
0 commit comments