@@ -562,6 +562,48 @@ legalizeGetHighLowi64Bytes(Instruction &I,
562
562
}
563
563
}
564
564
565
+ static void legalizeLoadStoreOnArrayAllocas (
566
+ Instruction &I, SmallVectorImpl<Instruction *> &ToRemove,
567
+ DenseMap<Value *, Value *> &) {
568
+
569
+ Value *PtrOp;
570
+ [[maybe_unused]] Type *LoadStoreTy;
571
+ if (auto *LI = dyn_cast<LoadInst>(&I)) {
572
+ PtrOp = LI->getPointerOperand ();
573
+ LoadStoreTy = LI->getType ();
574
+ } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
575
+ PtrOp = SI->getPointerOperand ();
576
+ LoadStoreTy = SI->getValueOperand ()->getType ();
577
+ } else
578
+ return ;
579
+
580
+ assert (LoadStoreTy->isSingleValueType () &&
581
+ " Expected load/store type to be a single-valued type" );
582
+
583
+ auto *AllocaPtrOp = dyn_cast<AllocaInst>(PtrOp);
584
+ if (!AllocaPtrOp)
585
+ return ;
586
+
587
+ Type *Ty = AllocaPtrOp->getAllocatedType ();
588
+ if (!isa<ArrayType>(Ty)) return ;
589
+ assert (!isa<ArrayType>(Ty->getArrayElementType ()) &&
590
+ " Expected allocated type of AllocaInst to be a flat ArrayType" );
591
+
592
+ IRBuilder<> Builder (&I);
593
+ Value *Zero = Builder.getInt32 (0 );
594
+ Value *GEP = Builder.CreateInBoundsGEP (Ty, AllocaPtrOp, {Zero, Zero});
595
+
596
+ Value *NewLoadStore = nullptr ;
597
+ if (auto *LI = dyn_cast<LoadInst>(&I))
598
+ NewLoadStore = Builder.CreateLoad (LI->getType (), GEP, LI->getName ());
599
+ else if (auto *SI = dyn_cast<StoreInst>(&I))
600
+ NewLoadStore =
601
+ Builder.CreateStore (SI->getValueOperand (), GEP, SI->isVolatile ());
602
+
603
+ ToRemove.push_back (&I);
604
+ I.replaceAllUsesWith (NewLoadStore);
605
+ }
606
+
565
607
namespace {
566
608
class DXILLegalizationPipeline {
567
609
@@ -605,6 +647,7 @@ class DXILLegalizationPipeline {
605
647
LegalizationPipeline[Stage1].push_back (legalizeMemCpy);
606
648
LegalizationPipeline[Stage1].push_back (removeMemSet);
607
649
LegalizationPipeline[Stage1].push_back (updateFnegToFsub);
650
+ LegalizationPipeline[Stage1].push_back (legalizeLoadStoreOnArrayAllocas);
608
651
// Note: legalizeGetHighLowi64Bytes and
609
652
// downcastI64toI32InsertExtractElements both modify extractelement, so they
610
653
// must run staggered stages. legalizeGetHighLowi64Bytes runs first b\c it
0 commit comments