@@ -887,16 +887,16 @@ bool VariableReuseAnalysis::getAllInsEltsIfAvailable(InsertElementInst *FirstIEI
887
887
IGC_ASSERT_MESSAGE (IEI_ix < nelts, " ICE: IEI's index out of bound!" );
888
888
SVecInsEltInfo &InsEltInfo = AllIEIs[IEI_ix];
889
889
if (InsEltInfo.IEI ) {
890
- // This element is inserted more than once, skip.
890
+ // One element is inserted more than once, skip.
891
891
return false ;
892
892
}
893
893
InsEltInfo.IEI = I;
894
894
InsEltInfo.Elt = E;
895
895
InsEltInfo.FromVec = V;
896
896
InsEltInfo.FromVec_eltIx = V_ix;
897
-
898
- // So far, E is never nullptr (could be in the future)
899
- InsEltInfo. EEI = dyn_cast_or_null<ExtractElementInst>(E);
897
+ if (E) {
898
+ InsEltInfo. EEI = dyn_cast<ExtractElementInst>(E);
899
+ }
900
900
901
901
if (!I->hasOneUse ()) {
902
902
break ;
@@ -923,24 +923,19 @@ bool VariableReuseAnalysis::getAllInsEltsIfAvailable(InsertElementInst *FirstIEI
923
923
if (tV == nullptr )
924
924
return false ;
925
925
926
- // Expect all IEIs are in the same DeSSA CC (DeSSA special-handles IEIs)
926
+ // Expect node values for all IEIs are identical. In general, if they
927
+ // are in the same DeSSA CC, that would be fine.
927
928
Value *tV_nv = m_DeSSA->getNodeValue (tV);
928
929
if (V_root != getRootValue (tV_nv))
929
930
return false ;
930
931
931
932
Value *E = AllIEIs[i].Elt ;
932
- if (!E || isa<Constant>(E)) {
933
- // constant is okay for either non-uniform or uniform.
934
- continue ;
935
- }
936
933
Value *FromVec = AllIEIs[i].FromVec ;
937
- if (FromVec) {
938
- Value *FromVec_nv = m_DeSSA->getNodeValue (FromVec);
939
- // check if FromVec has been coalesced with IEI already by DeSSA.
940
- // (Wouldn't happen under current DeSSA, but might happen in future)
941
- if (V_root == getRootValue (FromVec_nv))
942
- return false ;
943
- }
934
+ Value *FromVec_nv = m_DeSSA->getNodeValue (FromVec);
935
+ // check if FromVec has been coalesced with IEI already by DeSSA.
936
+ // (Wouldn't happen under current DeSSA, but might happen in future)
937
+ if (V_root == getRootValue (FromVec_nv))
938
+ return false ;
944
939
945
940
// Make sure FromVec or E have the same uniformness as V.
946
941
if ((E && V_dep != m_WIA->whichDepend (E)) || (FromVec && V_dep != m_WIA->whichDepend (FromVec)))
@@ -974,13 +969,17 @@ Value *VariableReuseAnalysis::traceAliasValue(Value *V) {
974
969
}
975
970
976
971
//
977
- // Returns true if there is the following pattern; otherwise return false.
972
+ // Returns true if the following is true
978
973
// IEI = insertElement <vectorType> Vec, S, <constant IEI_ix>
979
- // 1. S is from another vector V.
980
- // S = extractElement <vectorType> V, <constant V_ix>
981
- // In this case, S is the element denoted by (V, V_ix)
982
- // 2. otherwise, V=nullptr, V_ix=0.
983
- // S is a candidate and could be alias to the vector.
974
+ // Return false, otherwise.
975
+ //
976
+ // When the above condition is true, V and V_ix are used for the
977
+ // following cases:
978
+ // 1. S is from another vector V.
979
+ // S = extractElement <vectorType> V, <constant V_ix>
980
+ // S is the element denoted by (V, V_ix)
981
+ // 2. otherwise, V=nullptr, V_ix=0.
982
+ // S is a candidate inserted and could be alias to the vector.
984
983
//
985
984
// Input: IEI
986
985
// Output: IEI_ix, S, V, V_ix
@@ -1000,9 +999,9 @@ bool VariableReuseAnalysis::getElementValue(InsertElementInst *IEI, int &IEI_ix,
1000
999
IEI_ix = (int )CI->getZExtValue ();
1001
1000
1002
1001
Value *elem0 = IEI->getOperand (1 );
1003
- if (hasBeenPayloadCoalesced (elem0) || isOrCoalescedWithArg (elem0)) {
1004
- // If elem0 has been payload-coalesced or it has been aliased to
1005
- // an argument, skip it.
1002
+ if (hasBeenPayloadCoalesced (elem0) || isa<Constant>(elem0) || isOrCoalescedWithArg (elem0)) {
1003
+ // If elem0 has been payload-coalesced, is constant,
1004
+ // or it has been aliased to an argument, skip it.
1006
1005
return false ;
1007
1006
}
1008
1007
@@ -1047,10 +1046,11 @@ void VariableReuseAnalysis::InsertElementAliasing(Function *F) {
1047
1046
1048
1047
// IGC Key VectorAlias controls vectorAlias optimiation.
1049
1048
//
1050
- // VectorAlias (also from m_pCtx->getVectorCoalescingControl())
1051
- // 0x0: disable vector aliasing
1052
- // 0x1: subvec aliasing for isolated values (getRootValue()=null)
1053
- // 0x2: subvec aliasing for both isolated and non-isolated value)
1049
+ // Do it if VectorAlias != 0.
1050
+ // VectorAlias=0x1: subvec aliasing for isolated values
1051
+ // (getRootValue()=null)
1052
+ // =0x2: subvec aliasing for both isolated and non-isolated
1053
+ // value)
1054
1054
const auto control = (m_pCtx->getVectorCoalescingControl () & 0x3 );
1055
1055
// To avoid increasing GRF pressure, skip if F is too large or not an entry
1056
1056
const int32_t NumBBThreshold = IGC_GET_FLAG_VALUE (VectorAliasBBThreshold);
@@ -1253,7 +1253,6 @@ bool VariableReuseAnalysis::processInsertTo(BasicBlock *BB, VecInsEltInfoTy &All
1253
1253
isSubCandidate = false ;
1254
1254
}
1255
1255
1256
- // So far, Elt is never nullptr (could be in the future)
1257
1256
if (Elt && Sub == nullptr && skipScalarAliaser (BB, Elt)) {
1258
1257
// Skip scalar coalescing
1259
1258
isSubCandidate = false ;
@@ -1434,11 +1433,8 @@ VariableReuseAnalysis::AState VariableReuseAnalysis::getCandidateStateUse(Value
1434
1433
}
1435
1434
} else if (StoreInst *SI = dyn_cast<StoreInst>(Val)) {
1436
1435
retSt = AState::TARGET;
1437
- } else if (CallInst *CallI = dyn_cast<CallInst>(Val)) {
1438
- if (CallI->isInlineAsm ())
1439
- retSt = AState::TARGET;
1440
- else
1441
- return AState::SKIP;
1436
+ } else if (isa<CallInst>(Val)) {
1437
+ return AState::SKIP;
1442
1438
}
1443
1439
}
1444
1440
return retSt;
@@ -1464,17 +1460,15 @@ VariableReuseAnalysis::AState VariableReuseAnalysis::getCandidateStateDef(Value
1464
1460
}
1465
1461
} else if (LoadInst *SI = dyn_cast<LoadInst>(Val)) {
1466
1462
return AState::TARGET;
1467
- } else if (CallInst *CallI = dyn_cast<CallInst>(Val)) {
1468
- if (CallI->isInlineAsm ())
1469
- return AState::TARGET;
1463
+ } else if (isa<CallInst>(Val)) {
1470
1464
return AState::SKIP;
1471
1465
}
1472
1466
return AState::OK;
1473
1467
}
1474
1468
1475
1469
// Vector alias disables extractMask optimization. This function
1476
1470
// checks if extractMask optim can be applied. And the caller
1477
- // will decide whether to favor extractMask optimization or not .
1471
+ // will decide whether to favor extractMask optimization.
1478
1472
bool VariableReuseAnalysis::isExtractMaskCandidate (Value *V) const {
1479
1473
auto BIT = [](int n) { return (uint32_t )(1 << n); };
1480
1474
0 commit comments