@@ -448,6 +448,21 @@ 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
+
451
466
/* **********************************************************************
452
467
* processWrRegion : process a wrregion instruction for element liveness
453
468
*/
@@ -533,23 +548,9 @@ void GenXDeadVectorRemoval::processWrRegion(Instruction *Inst, LiveBits LB)
533
548
addToWorkList (OldInInst);
534
549
// If some constant values are not in use, set it to undef so ConstantLoader
535
550
// can benefit from it.
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
- }
551
+ else if (auto OldInConst = dyn_cast<Constant>(OldInVal))
552
+ Inst->setOperand (GenXIntrinsic::GenXRegion::OldValueOperandNum,
553
+ undefDeadConstElements (OldInConst, OldInLB));
553
554
}
554
555
if (UsedOldInput) {
555
556
// We know that at least one element of the "old value" input is used,
@@ -563,10 +564,20 @@ void GenXDeadVectorRemoval::processWrRegion(Instruction *Inst, LiveBits LB)
563
564
*/
564
565
void GenXDeadVectorRemoval::processBitCast (Instruction *Inst, LiveBits LB)
565
566
{
566
- auto InInst = dyn_cast<Instruction>(Inst->getOperand (0 ));
567
- if (!InInst)
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
568
580
return ;
569
- LiveBits InLB = createLiveBits (InInst);
570
581
bool Modified = false ;
571
582
if (InLB.getNumElements () == LB.getNumElements ())
572
583
Modified = InLB.orBits (LB);
@@ -589,8 +600,12 @@ void GenXDeadVectorRemoval::processBitCast(Instruction *Inst, LiveBits LB)
589
600
Modified |= InLB.set (Idx);
590
601
}
591
602
}
592
- if (Modified)
593
- addToWorkList (InInst);
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
+ }
594
609
}
595
610
596
611
/* **********************************************************************
0 commit comments