@@ -533,6 +533,9 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
533
533
setOperationAction(ISD::XOR, MVT::i32, Custom);
534
534
setOperationAction(ISD::XOR, MVT::i64, Custom);
535
535
536
+ setOperationAction(ISD::ADDRSPACECAST, MVT::i32, Custom);
537
+ setOperationAction(ISD::ADDRSPACECAST, MVT::i64, Custom);
538
+
536
539
// Virtually no operation on f128 is legal, but LLVM can't expand them when
537
540
// there's a valid register class, so we need custom operations in most cases.
538
541
setOperationAction(ISD::FABS, MVT::f128, Expand);
@@ -6722,6 +6725,37 @@ static SDValue LowerTruncateVectorStore(SDLoc DL, StoreSDNode *ST,
6722
6725
ST->getBasePtr(), ST->getMemOperand());
6723
6726
}
6724
6727
6728
+ static SDValue LowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) {
6729
+ SDLoc dl(Op);
6730
+ SDValue Src = Op.getOperand(0);
6731
+ MVT DestVT = Op.getSimpleValueType();
6732
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6733
+ AddrSpaceCastSDNode *N = cast<AddrSpaceCastSDNode>(Op.getNode());
6734
+
6735
+ unsigned SrcAS = N->getSrcAddressSpace();
6736
+ unsigned DestAS = N->getDestAddressSpace();
6737
+ assert(SrcAS != DestAS &&
6738
+ "addrspacecast must be between different address spaces");
6739
+ assert(TLI.getTargetMachine().getPointerSize(SrcAS) !=
6740
+ TLI.getTargetMachine().getPointerSize(DestAS) &&
6741
+ "addrspacecast must be between different ptr sizes");
6742
+
6743
+ if (SrcAS == ARM64AS::PTR32_SPTR) {
6744
+ return DAG.getNode(ISD::SIGN_EXTEND, dl, DestVT, Src,
6745
+ DAG.getTargetConstant(0, dl, DestVT));
6746
+ } else if (SrcAS == ARM64AS::PTR32_UPTR) {
6747
+ return DAG.getNode(ISD::ZERO_EXTEND, dl, DestVT, Src,
6748
+ DAG.getTargetConstant(0, dl, DestVT));
6749
+ } else if ((DestAS == ARM64AS::PTR32_SPTR) ||
6750
+ (DestAS == ARM64AS::PTR32_UPTR)) {
6751
+ SDValue Ext = DAG.getAnyExtOrTrunc(Src, dl, DestVT);
6752
+ SDValue Trunc = DAG.getZeroExtendInReg(Ext, dl, DestVT);
6753
+ return Trunc;
6754
+ } else {
6755
+ return Src;
6756
+ }
6757
+ }
6758
+
6725
6759
// Custom lowering for any store, vector or scalar and/or default or with
6726
6760
// a truncate operations. Currently only custom lower truncate operation
6727
6761
// from vector v4i16 to v4i8 or volatile stores of i128.
@@ -7375,6 +7409,8 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
7375
7409
case ISD::SIGN_EXTEND:
7376
7410
case ISD::ZERO_EXTEND:
7377
7411
return LowerFixedLengthVectorIntExtendToSVE(Op, DAG);
7412
+ case ISD::ADDRSPACECAST:
7413
+ return LowerADDRSPACECAST(Op, DAG);
7378
7414
case ISD::SIGN_EXTEND_INREG: {
7379
7415
// Only custom lower when ExtraVT has a legal byte based element type.
7380
7416
EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
@@ -23366,6 +23402,26 @@ static SDValue performLOADCombine(SDNode *N,
23366
23402
performTBISimplification(N->getOperand(1), DCI, DAG);
23367
23403
23368
23404
LoadSDNode *LD = cast<LoadSDNode>(N);
23405
+ EVT RegVT = LD->getValueType(0);
23406
+ EVT MemVT = LD->getMemoryVT();
23407
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
23408
+ SDLoc DL(LD);
23409
+
23410
+ // Cast ptr32 and ptr64 pointers to the default address space before a load.
23411
+ unsigned AddrSpace = LD->getAddressSpace();
23412
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
23413
+ AddrSpace == ARM64AS::PTR32_UPTR) {
23414
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
23415
+ if (PtrVT != LD->getBasePtr().getSimpleValueType()) {
23416
+ SDValue Cast =
23417
+ DAG.getAddrSpaceCast(DL, PtrVT, LD->getBasePtr(), AddrSpace, 0);
23418
+ return DAG.getExtLoad(LD->getExtensionType(), DL, RegVT, LD->getChain(),
23419
+ Cast, LD->getPointerInfo(), MemVT,
23420
+ LD->getOriginalAlign(),
23421
+ LD->getMemOperand()->getFlags());
23422
+ }
23423
+ }
23424
+
23369
23425
if (LD->isVolatile() || !Subtarget->isLittleEndian())
23370
23426
return SDValue(N, 0);
23371
23427
@@ -23375,13 +23431,11 @@ static SDValue performLOADCombine(SDNode *N,
23375
23431
if (!LD->isNonTemporal())
23376
23432
return SDValue(N, 0);
23377
23433
23378
- EVT MemVT = LD->getMemoryVT();
23379
23434
if (MemVT.isScalableVector() || MemVT.getSizeInBits() <= 256 ||
23380
23435
MemVT.getSizeInBits() % 256 == 0 ||
23381
23436
256 % MemVT.getScalarSizeInBits() != 0)
23382
23437
return SDValue(N, 0);
23383
23438
23384
- SDLoc DL(LD);
23385
23439
SDValue Chain = LD->getChain();
23386
23440
SDValue BasePtr = LD->getBasePtr();
23387
23441
SDNodeFlags Flags = LD->getFlags();
@@ -23641,12 +23695,28 @@ static SDValue performSTORECombine(SDNode *N,
23641
23695
SDValue Value = ST->getValue();
23642
23696
SDValue Ptr = ST->getBasePtr();
23643
23697
EVT ValueVT = Value.getValueType();
23698
+ EVT MemVT = ST->getMemoryVT();
23699
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
23700
+ SDLoc DL(ST);
23644
23701
23645
23702
auto hasValidElementTypeForFPTruncStore = [](EVT VT) {
23646
23703
EVT EltVT = VT.getVectorElementType();
23647
23704
return EltVT == MVT::f32 || EltVT == MVT::f64;
23648
23705
};
23649
23706
23707
+ // Cast ptr32 and ptr64 pointers to the default address space before a store.
23708
+ unsigned AddrSpace = ST->getAddressSpace();
23709
+ if (AddrSpace == ARM64AS::PTR64 || AddrSpace == ARM64AS::PTR32_SPTR ||
23710
+ AddrSpace == ARM64AS::PTR32_UPTR) {
23711
+ MVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
23712
+ if (PtrVT != Ptr.getSimpleValueType()) {
23713
+ SDValue Cast = DAG.getAddrSpaceCast(DL, PtrVT, Ptr, AddrSpace, 0);
23714
+ return DAG.getStore(Chain, DL, Value, Cast, ST->getPointerInfo(),
23715
+ ST->getOriginalAlign(),
23716
+ ST->getMemOperand()->getFlags(), ST->getAAInfo());
23717
+ }
23718
+ }
23719
+
23650
23720
if (SDValue Res = combineI8TruncStore(ST, DAG, Subtarget))
23651
23721
return Res;
23652
23722
@@ -23660,8 +23730,8 @@ static SDValue performSTORECombine(SDNode *N,
23660
23730
ValueVT.isFixedLengthVector() &&
23661
23731
ValueVT.getFixedSizeInBits() >= Subtarget->getMinSVEVectorSizeInBits() &&
23662
23732
hasValidElementTypeForFPTruncStore(Value.getOperand(0).getValueType()))
23663
- return DAG.getTruncStore(Chain, SDLoc(N) , Value.getOperand(0), Ptr,
23664
- ST->getMemoryVT(), ST-> getMemOperand());
23733
+ return DAG.getTruncStore(Chain, DL , Value.getOperand(0), Ptr, MemVT ,
23734
+ ST->getMemOperand());
23665
23735
23666
23736
if (SDValue Split = splitStores(N, DCI, DAG, Subtarget))
23667
23737
return Split;
@@ -26988,6 +27058,11 @@ void AArch64TargetLowering::ReplaceNodeResults(
26988
27058
ReplaceATOMIC_LOAD_128Results(N, Results, DAG, Subtarget);
26989
27059
return;
26990
27060
}
27061
+ case ISD::ADDRSPACECAST: {
27062
+ SDValue V = LowerADDRSPACECAST(SDValue(N, 0), DAG);
27063
+ Results.push_back(V);
27064
+ return;
27065
+ }
26991
27066
case ISD::ATOMIC_LOAD:
26992
27067
case ISD::LOAD: {
26993
27068
MemSDNode *LoadNode = cast<MemSDNode>(N);
0 commit comments