@@ -448,21 +448,6 @@ void GenXDeadVectorRemoval::processRdRegion(Instruction *Inst, LiveBits LB)
448
448
addToWorkList (InInst);
449
449
}
450
450
451
- static Constant *undefDeadConstElements (Constant *C, LiveBits LB) {
452
- if (isa<UndefValue>(C) || isa<ConstantAggregateZero>(C))
453
- return C;
454
- if (!C->getType ()->isVectorTy ()) {
455
- IGC_ASSERT (LB.getNumElements () == 1 );
456
- return LB.get (0 ) ? C : UndefValue::get (C->getType ());
457
- }
458
- SmallVector<Constant *, 8 > NewElems;
459
- for (unsigned i = 0 ; i < LB.getNumElements (); ++i)
460
- NewElems.push_back (LB.get (i)
461
- ? C->getAggregateElement (i)
462
- : UndefValue::get (C->getType ()->getScalarType ()));
463
- return ConstantVector::get (NewElems);
464
- }
465
-
466
451
/* **********************************************************************
467
452
* processWrRegion : process a wrregion instruction for element liveness
468
453
*/
@@ -548,9 +533,23 @@ void GenXDeadVectorRemoval::processWrRegion(Instruction *Inst, LiveBits LB)
548
533
addToWorkList (OldInInst);
549
534
// If some constant values are not in use, set it to undef so ConstantLoader
550
535
// can benefit from it.
551
- else if (auto OldInConst = dyn_cast<Constant>(OldInVal))
552
- Inst->setOperand (GenXIntrinsic::GenXRegion::OldValueOperandNum,
553
- undefDeadConstElements (OldInConst, OldInLB));
536
+ else if (auto OldInConst = dyn_cast<Constant>(OldInVal)) {
537
+ Constant *NewInConst = nullptr ;
538
+ if (isa<UndefValue>(OldInConst))
539
+ NewInConst = UndefValue::get (OldInConst->getType ());
540
+ else if (isa<ConstantAggregateZero>(OldInConst))
541
+ NewInConst = ConstantAggregateZero::get (OldInConst->getType ());
542
+ else {
543
+ SmallVector<Constant *, 8 > NewElems;
544
+ for (unsigned i = 0 ; i < OldInLB.getNumElements (); ++i)
545
+ NewElems.push_back (OldInLB.get (i) ?
546
+ OldInConst->getAggregateElement (i) :
547
+ UndefValue::get (OldInConst->getType ()->getScalarType ()));
548
+ NewInConst = ConstantVector::get (NewElems);
549
+ }
550
+ IGC_ASSERT (NewInConst);
551
+ Inst->setOperand (GenXIntrinsic::GenXRegion::OldValueOperandNum, NewInConst);
552
+ }
554
553
}
555
554
if (UsedOldInput) {
556
555
// We know that at least one element of the "old value" input is used,
@@ -564,20 +563,10 @@ void GenXDeadVectorRemoval::processWrRegion(Instruction *Inst, LiveBits LB)
564
563
*/
565
564
void GenXDeadVectorRemoval::processBitCast (Instruction *Inst, LiveBits LB)
566
565
{
567
- LiveBits InLB;
568
- LiveBitsStorage ConstVecLBS;
569
- auto InVal = Inst->getOperand (0 );
570
- if (auto InInst = dyn_cast<Instruction>(InVal))
571
- InLB = createLiveBits (InInst);
572
- else if (isa<Constant>(InVal)) {
573
- unsigned NumElems =
574
- isa<VectorType>(InVal->getType ())
575
- ? cast<VectorType>(InVal->getType ())->getNumElements ()
576
- : 1 ;
577
- ConstVecLBS.setNumElements (NumElems);
578
- InLB = LiveBits (&ConstVecLBS, NumElems);
579
- } else
566
+ auto InInst = dyn_cast<Instruction>(Inst->getOperand (0 ));
567
+ if (!InInst)
580
568
return ;
569
+ LiveBits InLB = createLiveBits (InInst);
581
570
bool Modified = false ;
582
571
if (InLB.getNumElements () == LB.getNumElements ())
583
572
Modified = InLB.orBits (LB);
@@ -600,12 +589,8 @@ void GenXDeadVectorRemoval::processBitCast(Instruction *Inst, LiveBits LB)
600
589
Modified |= InLB.set (Idx);
601
590
}
602
591
}
603
- if (Modified) {
604
- if (auto InInst = dyn_cast<Instruction>(InVal))
605
- addToWorkList (InInst);
606
- else if (auto InConst = dyn_cast<Constant>(InVal))
607
- Inst->setOperand (0 , undefDeadConstElements (InConst, InLB));
608
- }
592
+ if (Modified)
593
+ addToWorkList (InInst);
609
594
}
610
595
611
596
/* **********************************************************************
0 commit comments