@@ -1786,20 +1786,30 @@ static e_alignment GetPreferredAlignmentOnUse(llvm::Value* V, WIAnalysis* WIA,
1786
1786
{
1787
1787
auto getAlign = [](Value* aV, WIAnalysis* aWIA, CodeGenContext* pCtx) -> e_alignment
1788
1788
{
1789
- // If uniform variables are once used by uniform loads, stores, or atomic
1790
- // ops, they need being GRF aligned.
1789
+ // Once uniform variables are used by uniform loads, stores, or atomic
1790
+ // ops, they need being GRF aligned, except that for block read/write
1791
+ // or vector load/store with > 1 elements. The block read/write's address
1792
+ // is just a field in its header payload so no need to grf-aligned; Vector
1793
+ // load/store with > 1 elements needs to create a new cvar anyway to hold
1794
+ // scatter load/store address [see detail in vector load/store].
1791
1795
for (auto UI = aV->user_begin (), UE = aV->user_end (); UI != UE; ++UI) {
1792
- if (LoadInst* ST = dyn_cast<LoadInst>(*UI)) {
1793
- Value* Ptr = ST->getPointerOperand ();
1794
- if (aWIA->whichDepend (Ptr) == WIAnalysis::UNIFORM) {
1796
+ if (LoadInst* LI = dyn_cast<LoadInst>(*UI)) {
1797
+ Value* Ptr = LI->getPointerOperand ();
1798
+ // If Ptr is uniform and loads a scalar, need [2]grf-alignment.
1799
+ VectorType* vTy = dyn_cast<VectorType>(LI->getType ());
1800
+ if (aWIA->whichDepend (Ptr) == WIAnalysis::UNIFORM &&
1801
+ !(vTy && vTy->getNumElements () > 1 )) {
1795
1802
if (IGC::isA64Ptr (cast<PointerType>(Ptr->getType ()), pCtx))
1796
1803
return EALIGN_2GRF;
1797
1804
return EALIGN_GRF;
1798
1805
}
1799
1806
}
1800
1807
if (StoreInst* ST = dyn_cast<StoreInst>(*UI)) {
1801
1808
Value* Ptr = ST->getPointerOperand ();
1802
- if (aWIA->whichDepend (Ptr) == WIAnalysis::UNIFORM) {
1809
+ VectorType* vTy = dyn_cast<VectorType>(ST->getValueOperand ()->getType ());
1810
+ // If Ptr is uniform and stores a scalar, need [2]grf-alignment.
1811
+ if (aWIA->whichDepend (Ptr) == WIAnalysis::UNIFORM &&
1812
+ !(vTy && vTy->getNumElements () > 1 )) {
1803
1813
if (IGC::isA64Ptr (cast<PointerType>(Ptr->getType ()), pCtx))
1804
1814
return EALIGN_2GRF;
1805
1815
return EALIGN_GRF;
0 commit comments