@@ -530,6 +530,9 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
530
530
setOperationAction(ISD::XOR, MVT::i32, Custom);
531
531
setOperationAction(ISD::XOR, MVT::i64, Custom);
532
532
533
+ setOperationAction(ISD::ADDRSPACECAST, MVT::i32, Custom);
534
+ setOperationAction(ISD::ADDRSPACECAST, MVT::i64, Custom);
535
+
533
536
// Virtually no operation on f128 is legal, but LLVM can't expand them when
534
537
// there's a valid register class, so we need custom operations in most cases.
535
538
setOperationAction(ISD::FABS, MVT::f128, Expand);
@@ -6879,6 +6882,37 @@ static SDValue LowerTruncateVectorStore(SDLoc DL, StoreSDNode *ST,
6879
6882
ST->getBasePtr(), ST->getMemOperand());
6880
6883
}
6881
6884
6885
+ static SDValue LowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) {
6886
+ SDLoc dl(Op);
6887
+ SDValue Src = Op.getOperand(0);
6888
+ MVT DestVT = Op.getSimpleValueType();
6889
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6890
+ AddrSpaceCastSDNode *N = cast<AddrSpaceCastSDNode>(Op.getNode());
6891
+
6892
+ unsigned SrcAS = N->getSrcAddressSpace();
6893
+ unsigned DestAS = N->getDestAddressSpace();
6894
+ assert(SrcAS != DestAS &&
6895
+ "addrspacecast must be between different address spaces");
6896
+ assert(TLI.getTargetMachine().getPointerSize(SrcAS) !=
6897
+ TLI.getTargetMachine().getPointerSize(DestAS) &&
6898
+ "addrspacecast must be between different ptr sizes");
6899
+
6900
+ if (SrcAS == ARM64AS::PTR32_SPTR) {
6901
+ return DAG.getNode(ISD::SIGN_EXTEND, dl, DestVT, Src,
6902
+ DAG.getTargetConstant(0, dl, DestVT));
6903
+ } else if (SrcAS == ARM64AS::PTR32_UPTR) {
6904
+ return DAG.getNode(ISD::ZERO_EXTEND, dl, DestVT, Src,
6905
+ DAG.getTargetConstant(0, dl, DestVT));
6906
+ } else if ((DestAS == ARM64AS::PTR32_SPTR) ||
6907
+ (DestAS == ARM64AS::PTR32_UPTR)) {
6908
+ SDValue Ext = DAG.getAnyExtOrTrunc(Src, dl, DestVT);
6909
+ SDValue Trunc = DAG.getZeroExtendInReg(Ext, dl, DestVT);
6910
+ return Trunc;
6911
+ } else {
6912
+ return Src;
6913
+ }
6914
+ }
6915
+
6882
6916
// Custom lowering for any store, vector or scalar and/or default or with
6883
6917
// a truncate operations. Currently only custom lower truncate operation
6884
6918
// from vector v4i16 to v4i8 or volatile stores of i128.
@@ -7540,6 +7574,8 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
7540
7574
case ISD::SIGN_EXTEND:
7541
7575
case ISD::ZERO_EXTEND:
7542
7576
return LowerFixedLengthVectorIntExtendToSVE(Op, DAG);
7577
+ case ISD::ADDRSPACECAST:
7578
+ return LowerADDRSPACECAST(Op, DAG);
7543
7579
case ISD::SIGN_EXTEND_INREG: {
7544
7580
// Only custom lower when ExtraVT has a legal byte based element type.
7545
7581
EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
@@ -23740,6 +23776,26 @@ static SDValue performLOADCombine(SDNode *N,
23740
23776
performTBISimplification(N->getOperand(1), DCI, DAG);
23741
23777
23742
23778
LoadSDNode *LD = cast<LoadSDNode>(N);
23779
+ EVT RegVT = LD->getValueType(0);
23780
+ EVT MemVT = LD->getMemoryVT();
23781
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
23782
+ SDLoc DL(LD);
23783
+
23784
+ // Cast ptr32 and ptr64 pointers to the default address space before a load.
23785
+ unsigned AddrSpace = LD->getAddressSpace();
23786
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
23787
+ AddrSpace == ARM64AS::PTR32_UPTR) {
23788
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
23789
+ if (PtrVT != LD->getBasePtr().getSimpleValueType()) {
23790
+ SDValue Cast =
23791
+ DAG.getAddrSpaceCast(DL, PtrVT, LD->getBasePtr(), AddrSpace, 0);
23792
+ return DAG.getExtLoad(LD->getExtensionType(), DL, RegVT, LD->getChain(),
23793
+ Cast, LD->getPointerInfo(), MemVT,
23794
+ LD->getOriginalAlign(),
23795
+ LD->getMemOperand()->getFlags());
23796
+ }
23797
+ }
23798
+
23743
23799
if (LD->isVolatile() || !Subtarget->isLittleEndian())
23744
23800
return SDValue(N, 0);
23745
23801
@@ -23749,13 +23805,11 @@ static SDValue performLOADCombine(SDNode *N,
23749
23805
if (!LD->isNonTemporal())
23750
23806
return SDValue(N, 0);
23751
23807
23752
- EVT MemVT = LD->getMemoryVT();
23753
23808
if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 ||
23754
23809
MemVT.getSizeInBits() % 256 == 0 ||
23755
23810
256 % MemVT.getScalarSizeInBits() != 0)
23756
23811
return SDValue(N, 0);
23757
23812
23758
- SDLoc DL(LD);
23759
23813
SDValue Chain = LD->getChain();
23760
23814
SDValue BasePtr = LD->getBasePtr();
23761
23815
SDNodeFlags Flags = LD->getFlags();
@@ -24015,12 +24069,28 @@ static SDValue performSTORECombine(SDNode *N,
24015
24069
SDValue Value = ST->getValue();
24016
24070
SDValue Ptr = ST->getBasePtr();
24017
24071
EVT ValueVT = Value.getValueType();
24072
+ EVT MemVT = ST->getMemoryVT();
24073
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
24074
+ SDLoc DL(ST);
24018
24075
24019
24076
auto hasValidElementTypeForFPTruncStore = [](EVT VT) {
24020
24077
EVT EltVT = VT.getVectorElementType();
24021
24078
return EltVT == MVT::f32 || EltVT == MVT::f64;
24022
24079
};
24023
24080
24081
+ // Cast ptr32 and ptr64 pointers to the default address space before a store.
24082
+ unsigned AddrSpace = ST->getAddressSpace();
24083
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
24084
+ AddrSpace == ARM64AS::PTR32_UPTR) {
24085
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
24086
+ if (PtrVT != Ptr.getSimpleValueType()) {
24087
+ SDValue Cast = DAG.getAddrSpaceCast(DL, PtrVT, Ptr, AddrSpace, 0);
24088
+ return DAG.getStore(Chain, DL, Value, Cast, ST->getPointerInfo(),
24089
+ ST->getOriginalAlign(),
24090
+ ST->getMemOperand()->getFlags(), ST->getAAInfo());
24091
+ }
24092
+ }
24093
+
24024
24094
if (SDValue Res = combineI8TruncStore(ST, DAG, Subtarget))
24025
24095
return Res;
24026
24096
@@ -24034,8 +24104,8 @@ static SDValue performSTORECombine(SDNode *N,
24034
24104
ValueVT.isFixedLengthVector() &&
24035
24105
ValueVT.getFixedSizeInBits() >= Subtarget->getMinSVEVectorSizeInBits() &&
24036
24106
hasValidElementTypeForFPTruncStore(Value.getOperand(0).getValueType()))
24037
- return DAG.getTruncStore(Chain, SDLoc(N) , Value.getOperand(0), Ptr,
24038
- ST->getMemoryVT(), ST-> getMemOperand());
24107
+ return DAG.getTruncStore(Chain, DL , Value.getOperand(0), Ptr, MemVT ,
24108
+ ST->getMemOperand());
24039
24109
24040
24110
if (SDValue Split = splitStores(N, DCI, DAG, Subtarget))
24041
24111
return Split;
@@ -27519,6 +27589,11 @@ void AArch64TargetLowering::ReplaceNodeResults(
27519
27589
ReplaceATOMIC_LOAD_128Results(N, Results, DAG, Subtarget);
27520
27590
return;
27521
27591
}
27592
+ case ISD::ADDRSPACECAST: {
27593
+ SDValue V = LowerADDRSPACECAST(SDValue(N, 0), DAG);
27594
+ Results.push_back(V);
27595
+ return;
27596
+ }
27522
27597
case ISD::ATOMIC_LOAD:
27523
27598
case ISD::LOAD: {
27524
27599
MemSDNode *LoadNode = cast<MemSDNode>(N);
0 commit comments