70
70
#include " llvm/Target/TargetMachine.h"
71
71
#include " llvm/Transforms/Utils/Local.h"
72
72
#include < cassert>
73
- #include < queue>
74
73
#include < utility>
75
74
76
75
using namespace llvm ;
@@ -489,57 +488,12 @@ bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
489
488
490
489
LLVM_DEBUG (dbgs () << " IA: Found a deinterleave intrinsic: " << *DI << " \n " );
491
490
492
- std::stack<IntrinsicInst *> DeinterleaveTreeQueue;
493
- SmallVector<Value *> TempLeafNodes, LeafNodes;
494
- std::map<IntrinsicInst *, bool > mp;
495
- SmallVector<Instruction *> TempDeadInsts;
496
-
497
- DeinterleaveTreeQueue.push (DI);
498
- while (!DeinterleaveTreeQueue.empty ()) {
499
- auto CurrentDI = DeinterleaveTreeQueue.top ();
500
- DeinterleaveTreeQueue.pop ();
501
- TempDeadInsts.push_back (CurrentDI);
502
- // iterate over extract users of deinterleave
503
- for (auto UserExtract : CurrentDI->users ()) {
504
- Instruction *Extract = dyn_cast<Instruction>(UserExtract);
505
- if (!Extract || Extract->getOpcode () != Instruction::ExtractValue)
506
- continue ;
507
- bool IsLeaf = true ;
508
- // iterate over deinterleave users of extract
509
- for (auto UserDI : UserExtract->users ()) {
510
- IntrinsicInst *Child_DI = dyn_cast<IntrinsicInst>(UserDI);
511
- if (!Child_DI || Child_DI->getIntrinsicID () !=
512
- Intrinsic::experimental_vector_deinterleave2)
513
- continue ;
514
- IsLeaf = false ;
515
- if (mp.count (Child_DI) == 0 ) {
516
- DeinterleaveTreeQueue.push (Child_DI);
517
- }
518
- continue ;
519
- }
520
- if (IsLeaf) {
521
- TempLeafNodes.push_back (UserExtract);
522
- TempDeadInsts.push_back (Extract);
523
- } else {
524
- TempDeadInsts.push_back (Extract);
525
- }
526
- }
527
- }
528
- // sort the deinterleaved nodes in the order that
529
- // they will be extracted from the target-specific intrinsic.
530
- for (unsigned I = 1 ; I < TempLeafNodes.size (); I += 2 )
531
- LeafNodes.push_back (TempLeafNodes[I]);
532
-
533
- for (unsigned I = 0 ; I < TempLeafNodes.size (); I += 2 )
534
- LeafNodes.push_back (TempLeafNodes[I]);
535
-
536
491
// Try and match this with target specific intrinsics.
537
- if (!TLI->lowerDeinterleaveIntrinsicToLoad (DI, LeafNodes, LI))
492
+ if (!TLI->lowerDeinterleaveIntrinsicToLoad (DI, LI))
538
493
return false ;
539
494
540
495
// We now have a target-specific load, so delete the old one.
541
- DeadInsts.insert (DeadInsts.end (), TempDeadInsts.rbegin (),
542
- TempDeadInsts.rend ());
496
+ DeadInsts.push_back (DI);
543
497
DeadInsts.push_back (LI);
544
498
return true ;
545
499
}
@@ -555,38 +509,14 @@ bool InterleavedAccessImpl::lowerInterleaveIntrinsic(
555
509
return false ;
556
510
557
511
LLVM_DEBUG (dbgs () << " IA: Found an interleave intrinsic: " << *II << " \n " );
558
- std::queue<IntrinsicInst *> IeinterleaveTreeQueue;
559
- SmallVector<Value *> TempLeafNodes, LeafNodes;
560
- SmallVector<Instruction *> TempDeadInsts;
561
-
562
- IeinterleaveTreeQueue.push (II);
563
- while (!IeinterleaveTreeQueue.empty ()) {
564
- auto node = IeinterleaveTreeQueue.front ();
565
- TempDeadInsts.push_back (node);
566
- IeinterleaveTreeQueue.pop ();
567
- for (unsigned i = 0 ; i < 2 ; i++) {
568
- auto op = node->getOperand (i);
569
- if (auto CurrentII = dyn_cast<IntrinsicInst>(op)) {
570
- if (CurrentII->getIntrinsicID () !=
571
- Intrinsic::experimental_vector_interleave2)
572
- continue ;
573
- IeinterleaveTreeQueue.push (CurrentII);
574
- continue ;
575
- }
576
- TempLeafNodes.push_back (op);
577
- }
578
- }
579
- for (unsigned I = 0 ; I < TempLeafNodes.size (); I += 2 )
580
- LeafNodes.push_back (TempLeafNodes[I]);
581
- for (unsigned I = 1 ; I < TempLeafNodes.size (); I += 2 )
582
- LeafNodes.push_back (TempLeafNodes[I]);
512
+
583
513
// Try and match this with target specific intrinsics.
584
- if (!TLI->lowerInterleaveIntrinsicToStore (II, LeafNodes, SI))
514
+ if (!TLI->lowerInterleaveIntrinsicToStore (II, SI))
585
515
return false ;
586
516
587
517
// We now have a target-specific store, so delete the old one.
588
518
DeadInsts.push_back (SI);
589
- DeadInsts.insert (DeadInsts. end (), TempDeadInsts. begin (), TempDeadInsts. end () );
519
+ DeadInsts.push_back (II );
590
520
return true ;
591
521
}
592
522
@@ -607,8 +537,7 @@ bool InterleavedAccessImpl::runOnFunction(Function &F) {
607
537
// with a factor of 2.
608
538
if (II->getIntrinsicID () == Intrinsic::vector_deinterleave2)
609
539
Changed |= lowerDeinterleaveIntrinsic (II, DeadInsts);
610
-
611
- else if (II->getIntrinsicID () == Intrinsic::vector_interleave2)
540
+ if (II->getIntrinsicID () == Intrinsic::vector_interleave2)
612
541
Changed |= lowerInterleaveIntrinsic (II, DeadInsts);
613
542
}
614
543
}
0 commit comments