@@ -128,6 +128,8 @@ class GASPropagator : public InstVisitor<GASPropagator, bool> {
128
128
bool visitICmp (ICmpInst &);
129
129
bool visitSelect (SelectInst &);
130
130
bool visitMemCpyInst (MemCpyInst &);
131
+ bool visitMemMoveInst (MemMoveInst &);
132
+ bool visitMemSetInst (MemSetInst &);
131
133
bool visitCallInst (CallInst &);
132
134
};
133
135
@@ -477,33 +479,70 @@ bool GASPropagator::visitSelect(SelectInst &I) {
477
479
return true ;
478
480
}
479
481
482
+ static bool handelMemTransferInst (MemTransferInst &I) {
483
+ Value *NewDst = nullptr ;
484
+ Type *NewDstTy = nullptr ;
485
+ Use *DstUse = &I.getArgOperandUse (0 );
486
+ if (auto ASCI = dyn_cast<AddrSpaceCastInst>(DstUse->get ())) {
487
+ NewDst = ASCI->getOperand (0 );
488
+ NewDstTy = NewDst->getType ();
489
+ }
490
+
491
+ Value *NewSrc = nullptr ;
492
+ Type *NewSrcTy = nullptr ;
493
+ Use *SrcUse = &I.getArgOperandUse (1 );
494
+ if (auto ASCI = dyn_cast<AddrSpaceCastInst>(SrcUse->get ())) {
495
+ NewSrc = ASCI->getOperand (0 );
496
+ NewSrcTy = NewSrc->getType ();
497
+ }
498
+
499
+ // No address space cast on src or dst.
500
+ if (NewDst == nullptr && NewSrc == nullptr )
501
+ return false ;
502
+
503
+ Type *Tys[] = {NewDstTy ? NewDstTy : I.getArgOperand (0 )->getType (),
504
+ NewSrcTy ? NewSrcTy : I.getArgOperand (1 )->getType (),
505
+ I.getArgOperand (2 )->getType ()};
506
+ Function *Fn = nullptr ;
507
+ Module *M = I.getParent ()->getParent ()->getParent ();
508
+ if (isa<MemCpyInst>(I))
509
+ Fn = Intrinsic::getDeclaration (M, Intrinsic::memcpy, Tys);
510
+ else if (isa<MemMoveInst>(I))
511
+ Fn = Intrinsic::getDeclaration (M, Intrinsic::memmove, Tys);
512
+ else
513
+ llvm_unreachable (" unsupported memory intrinsic kind" );
514
+
515
+ I.setCalledFunction (Fn);
516
+ if (NewDst)
517
+ DstUse->set (NewDst);
518
+ if (NewSrc)
519
+ SrcUse->set (NewSrc);
520
+ return true ;
521
+ }
522
+
480
523
bool GASPropagator::visitMemCpyInst (MemCpyInst &I) {
481
- AddrSpaceCastInst *ASCI = nullptr ;
524
+ return handelMemTransferInst (I);
525
+ }
482
526
527
+ bool GASPropagator::visitMemMoveInst (MemMoveInst &I) {
528
+ return handelMemTransferInst (I);
529
+ }
530
+
531
+ bool GASPropagator::visitMemSetInst (MemSetInst &I) {
483
532
Use *DstUse = &I.getArgOperandUse (0 );
484
- ASCI = dyn_cast<AddrSpaceCastInst>(DstUse->get ());
533
+ auto ASCI = dyn_cast<AddrSpaceCastInst>(DstUse->get ());
485
534
if (!ASCI)
486
535
return false ;
487
536
488
537
Value *OrigDst = ASCI->getOperand (0 );
489
538
Type *OrigDstTy = OrigDst->getType ();
490
539
491
- Use *SrcUse = &I.getArgOperandUse (1 );
492
- ASCI = dyn_cast<AddrSpaceCastInst>(SrcUse->get ());
493
- if (!ASCI)
494
- return false ;
495
-
496
- Value *OrigSrc = ASCI->getOperand (0 );
497
- Type *OrigSrcTy = OrigSrc->getType ();
498
-
499
- Type *Tys[] = {OrigDstTy, OrigSrcTy, I.getArgOperand (2 )->getType ()};
540
+ Type *Tys[] = {OrigDstTy, I.getArgOperand (2 )->getType ()};
500
541
Function *Fn = Intrinsic::getDeclaration (
501
- I.getParent ()->getParent ()->getParent (), Intrinsic::memcpy , Tys);
542
+ I.getParent ()->getParent ()->getParent (), Intrinsic::memset , Tys);
502
543
503
544
I.setCalledFunction (Fn);
504
545
DstUse->set (OrigDst);
505
- SrcUse->set (OrigSrc);
506
-
507
546
return true ;
508
547
}
509
548
0 commit comments