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