@@ -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);
@@ -6880,6 +6883,37 @@ static SDValue LowerTruncateVectorStore(SDLoc DL, StoreSDNode *ST,
6880
6883
ST->getBasePtr(), ST->getMemOperand());
6881
6884
}
6882
6885
6886
+ static SDValue LowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) {
6887
+ SDLoc dl(Op);
6888
+ SDValue Src = Op.getOperand(0);
6889
+ MVT DestVT = Op.getSimpleValueType();
6890
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6891
+ AddrSpaceCastSDNode *N = cast<AddrSpaceCastSDNode>(Op.getNode());
6892
+
6893
+ unsigned SrcAS = N->getSrcAddressSpace();
6894
+ unsigned DestAS = N->getDestAddressSpace();
6895
+ assert(SrcAS != DestAS &&
6896
+ "addrspacecast must be between different address spaces");
6897
+ assert(TLI.getTargetMachine().getPointerSize(SrcAS) !=
6898
+ TLI.getTargetMachine().getPointerSize(DestAS) &&
6899
+ "addrspacecast must be between different ptr sizes");
6900
+
6901
+ if (SrcAS == ARM64AS::PTR32_SPTR) {
6902
+ return DAG.getNode(ISD::SIGN_EXTEND, dl, DestVT, Src,
6903
+ DAG.getTargetConstant(0, dl, DestVT));
6904
+ } else if (SrcAS == ARM64AS::PTR32_UPTR) {
6905
+ return DAG.getNode(ISD::ZERO_EXTEND, dl, DestVT, Src,
6906
+ DAG.getTargetConstant(0, dl, DestVT));
6907
+ } else if ((DestAS == ARM64AS::PTR32_SPTR) ||
6908
+ (DestAS == ARM64AS::PTR32_UPTR)) {
6909
+ SDValue Ext = DAG.getAnyExtOrTrunc(Src, dl, DestVT);
6910
+ SDValue Trunc = DAG.getZeroExtendInReg(Ext, dl, DestVT);
6911
+ return Trunc;
6912
+ } else {
6913
+ return Src;
6914
+ }
6915
+ }
6916
+
6883
6917
// Custom lowering for any store, vector or scalar and/or default or with
6884
6918
// a truncate operations. Currently only custom lower truncate operation
6885
6919
// from vector v4i16 to v4i8 or volatile stores of i128.
@@ -7541,6 +7575,8 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
7541
7575
case ISD::SIGN_EXTEND:
7542
7576
case ISD::ZERO_EXTEND:
7543
7577
return LowerFixedLengthVectorIntExtendToSVE(Op, DAG);
7578
+ case ISD::ADDRSPACECAST:
7579
+ return LowerADDRSPACECAST(Op, DAG);
7544
7580
case ISD::SIGN_EXTEND_INREG: {
7545
7581
// Only custom lower when ExtraVT has a legal byte based element type.
7546
7582
EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
@@ -23558,6 +23594,26 @@ static SDValue performLOADCombine(SDNode *N,
23558
23594
performTBISimplification(N->getOperand(1), DCI, DAG);
23559
23595
23560
23596
LoadSDNode *LD = cast<LoadSDNode>(N);
23597
+ EVT RegVT = LD->getValueType(0);
23598
+ EVT MemVT = LD->getMemoryVT();
23599
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
23600
+ SDLoc DL(LD);
23601
+
23602
+ // Cast ptr32 and ptr64 pointers to the default address space before a load.
23603
+ unsigned AddrSpace = LD->getAddressSpace();
23604
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
23605
+ AddrSpace == ARM64AS::PTR32_UPTR) {
23606
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
23607
+ if (PtrVT != LD->getBasePtr().getSimpleValueType()) {
23608
+ SDValue Cast =
23609
+ DAG.getAddrSpaceCast(DL, PtrVT, LD->getBasePtr(), AddrSpace, 0);
23610
+ return DAG.getExtLoad(LD->getExtensionType(), DL, RegVT, LD->getChain(),
23611
+ Cast, LD->getPointerInfo(), MemVT,
23612
+ LD->getOriginalAlign(),
23613
+ LD->getMemOperand()->getFlags());
23614
+ }
23615
+ }
23616
+
23561
23617
if (LD->isVolatile() || !Subtarget->isLittleEndian())
23562
23618
return SDValue(N, 0);
23563
23619
@@ -23567,13 +23623,11 @@ static SDValue performLOADCombine(SDNode *N,
23567
23623
if (!LD->isNonTemporal())
23568
23624
return SDValue(N, 0);
23569
23625
23570
- EVT MemVT = LD->getMemoryVT();
23571
23626
if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 ||
23572
23627
MemVT.getSizeInBits() % 256 == 0 ||
23573
23628
256 % MemVT.getScalarSizeInBits() != 0)
23574
23629
return SDValue(N, 0);
23575
23630
23576
- SDLoc DL(LD);
23577
23631
SDValue Chain = LD->getChain();
23578
23632
SDValue BasePtr = LD->getBasePtr();
23579
23633
SDNodeFlags Flags = LD->getFlags();
@@ -23833,12 +23887,28 @@ static SDValue performSTORECombine(SDNode *N,
23833
23887
SDValue Value = ST->getValue();
23834
23888
SDValue Ptr = ST->getBasePtr();
23835
23889
EVT ValueVT = Value.getValueType();
23890
+ EVT MemVT = ST->getMemoryVT();
23891
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
23892
+ SDLoc DL(ST);
23836
23893
23837
23894
auto hasValidElementTypeForFPTruncStore = [](EVT VT) {
23838
23895
EVT EltVT = VT.getVectorElementType();
23839
23896
return EltVT == MVT::f32 || EltVT == MVT::f64;
23840
23897
};
23841
23898
23899
+ // Cast ptr32 and ptr64 pointers to the default address space before a store.
23900
+ unsigned AddrSpace = ST->getAddressSpace();
23901
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
23902
+ AddrSpace == ARM64AS::PTR32_UPTR) {
23903
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
23904
+ if (PtrVT != Ptr.getSimpleValueType()) {
23905
+ SDValue Cast = DAG.getAddrSpaceCast(DL, PtrVT, Ptr, AddrSpace, 0);
23906
+ return DAG.getStore(Chain, DL, Value, Cast, ST->getPointerInfo(),
23907
+ ST->getOriginalAlign(),
23908
+ ST->getMemOperand()->getFlags(), ST->getAAInfo());
23909
+ }
23910
+ }
23911
+
23842
23912
if (SDValue Res = combineI8TruncStore(ST, DAG, Subtarget))
23843
23913
return Res;
23844
23914
@@ -23852,8 +23922,8 @@ static SDValue performSTORECombine(SDNode *N,
23852
23922
ValueVT.isFixedLengthVector() &&
23853
23923
ValueVT.getFixedSizeInBits() >= Subtarget->getMinSVEVectorSizeInBits() &&
23854
23924
hasValidElementTypeForFPTruncStore(Value.getOperand(0).getValueType()))
23855
- return DAG.getTruncStore(Chain, SDLoc(N) , Value.getOperand(0), Ptr,
23856
- ST->getMemoryVT(), ST-> getMemOperand());
23925
+ return DAG.getTruncStore(Chain, DL , Value.getOperand(0), Ptr, MemVT ,
23926
+ ST->getMemOperand());
23857
23927
23858
23928
if (SDValue Split = splitStores(N, DCI, DAG, Subtarget))
23859
23929
return Split;
@@ -27394,6 +27464,11 @@ void AArch64TargetLowering::ReplaceNodeResults(
27394
27464
ReplaceATOMIC_LOAD_128Results(N, Results, DAG, Subtarget);
27395
27465
return;
27396
27466
}
27467
+ case ISD::ADDRSPACECAST: {
27468
+ SDValue V = LowerADDRSPACECAST(SDValue(N, 0), DAG);
27469
+ Results.push_back(V);
27470
+ return;
27471
+ }
27397
27472
case ISD::ATOMIC_LOAD:
27398
27473
case ISD::LOAD: {
27399
27474
MemSDNode *LoadNode = cast<MemSDNode>(N);
0 commit comments