@@ -4515,6 +4515,9 @@ void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo) {
4515
4515
break ;
4516
4516
case ISD::EXTRACT_SUBVECTOR: Res = WidenVecRes_EXTRACT_SUBVECTOR (N); break ;
4517
4517
case ISD::INSERT_VECTOR_ELT: Res = WidenVecRes_INSERT_VECTOR_ELT (N); break ;
4518
+ case ISD::ATOMIC_LOAD:
4519
+ Res = WidenVecRes_ATOMIC_LOAD (cast<AtomicSDNode>(N));
4520
+ break ;
4518
4521
case ISD::LOAD: Res = WidenVecRes_LOAD (N); break ;
4519
4522
case ISD::STEP_VECTOR:
4520
4523
case ISD::SPLAT_VECTOR:
@@ -5901,6 +5904,30 @@ SDValue DAGTypeLegalizer::WidenVecRes_INSERT_VECTOR_ELT(SDNode *N) {
5901
5904
N->getOperand (1 ), N->getOperand (2 ));
5902
5905
}
5903
5906
5907
+ SDValue DAGTypeLegalizer::WidenVecRes_ATOMIC_LOAD (AtomicSDNode *N) {
5908
+ SmallVector<SDValue, 16 > LdChain; // Chain for the series of load
5909
+ SDValue Result = GenWidenVectorLoads (LdChain, N, true /* IsAtomic*/ );
5910
+
5911
+ if (Result) {
5912
+ // If we generate a single load, we can use that for the chain. Otherwise,
5913
+ // build a factor node to remember the multiple loads are independent and
5914
+ // chain to that.
5915
+ SDValue NewChain;
5916
+ if (LdChain.size () == 1 )
5917
+ NewChain = LdChain[0 ];
5918
+ else
5919
+ NewChain = DAG.getNode (ISD::TokenFactor, SDLoc (N), MVT::Other, LdChain);
5920
+
5921
+ // Modified the chain - switch anything that used the old chain to use
5922
+ // the new one.
5923
+ ReplaceValueWith (SDValue (N, 1 ), NewChain);
5924
+
5925
+ return Result;
5926
+ }
5927
+
5928
+ report_fatal_error (" Unable to widen atomic vector load" );
5929
+ }
5930
+
5904
5931
SDValue DAGTypeLegalizer::WidenVecRes_LOAD (SDNode *N) {
5905
5932
LoadSDNode *LD = cast<LoadSDNode>(N);
5906
5933
ISD::LoadExtType ExtType = LD->getExtensionType ();
@@ -7699,8 +7726,9 @@ static SDValue BuildVectorFromScalar(SelectionDAG& DAG, EVT VecTy,
7699
7726
return DAG.getNode (ISD::BITCAST, dl, VecTy, VecOp);
7700
7727
}
7701
7728
7729
+ template <typename T>
7702
7730
SDValue DAGTypeLegalizer::GenWidenVectorLoads (SmallVectorImpl<SDValue> &LdChain,
7703
- LoadSDNode *LD) {
7731
+ T *LD, bool IsAtomic ) {
7704
7732
// The strategy assumes that we can efficiently load power-of-two widths.
7705
7733
// The routine chops the vector into the largest vector loads with the same
7706
7734
// element type or scalar loads and then recombines it to the widen vector
@@ -7757,8 +7785,13 @@ SDValue DAGTypeLegalizer::GenWidenVectorLoads(SmallVectorImpl<SDValue> &LdChain,
7757
7785
} while (TypeSize::isKnownGT (RemainingWidth, NewVTWidth));
7758
7786
}
7759
7787
7760
- SDValue LdOp = DAG.getLoad (*FirstVT, dl, Chain, BasePtr, LD->getPointerInfo (),
7761
- LD->getOriginalAlign (), MMOFlags, AAInfo);
7788
+ SDValue LdOp;
7789
+ if (IsAtomic)
7790
+ LdOp = DAG.getAtomic (ISD::ATOMIC_LOAD, dl, *FirstVT, *FirstVT, Chain,
7791
+ BasePtr, LD->getMemOperand ());
7792
+ else
7793
+ LdOp = DAG.getLoad (*FirstVT, dl, Chain, BasePtr, LD->getPointerInfo (),
7794
+ LD->getOriginalAlign (), MMOFlags, AAInfo);
7762
7795
LdChain.push_back (LdOp.getValue (1 ));
7763
7796
7764
7797
// Check if we can load the element with one instruction.
0 commit comments