From 32c1e73603653779604bbe9bf493117814e8da75 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 12 Jun 2019 10:46:50 +0000 Subject: [PATCH] [XCore] LowerLOAD/LowerSTORE - Use allowsMemoryAccess wrapper. NFCI. Noticed in D63075 - there was a allowsMisalignedMemoryAccesses call to check for unaligned loads and a check for aligned legal type loads - which is exactly what allowsMemoryAccess does. llvm-svn: 363137 --- llvm/lib/Target/XCore/XCoreISelLowering.cpp | 42 +++++++-------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/llvm/lib/Target/XCore/XCoreISelLowering.cpp b/llvm/lib/Target/XCore/XCoreISelLowering.cpp index 51dbf016392f..2145ba5a6f88 100644 --- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp +++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp @@ -406,23 +406,16 @@ static bool isWordAligned(SDValue Value, SelectionDAG &DAG) return Known.countMinTrailingZeros() >= 2; } -SDValue XCoreTargetLowering:: -LowerLOAD(SDValue Op, SelectionDAG &DAG) const { +SDValue XCoreTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const { const TargetLowering &TLI = DAG.getTargetLoweringInfo(); + LLVMContext &Context = *DAG.getContext(); LoadSDNode *LD = cast(Op); assert(LD->getExtensionType() == ISD::NON_EXTLOAD && "Unexpected extension type"); assert(LD->getMemoryVT() == MVT::i32 && "Unexpected load EVT"); - if (allowsMisalignedMemoryAccesses(LD->getMemoryVT(), - LD->getAddressSpace(), - LD->getAlignment())) - return SDValue(); - auto &TD = DAG.getDataLayout(); - unsigned ABIAlignment = TD.getABITypeAlignment( - LD->getMemoryVT().getTypeForEVT(*DAG.getContext())); - // Leave aligned load alone. - if (LD->getAlignment() >= ABIAlignment) + if (allowsMemoryAccess(Context, DAG.getDataLayout(), LD->getMemoryVT(), + *LD->getMemOperand())) return SDValue(); SDValue Chain = LD->getChain(); @@ -469,7 +462,7 @@ LowerLOAD(SDValue Op, SelectionDAG &DAG) const { } // Lower to a call to __misaligned_load(BasePtr). - Type *IntPtrTy = TD.getIntPtrType(*DAG.getContext()); + Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(Context); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; @@ -489,23 +482,16 @@ LowerLOAD(SDValue Op, SelectionDAG &DAG) const { return DAG.getMergeValues(Ops, DL); } -SDValue XCoreTargetLowering:: -LowerSTORE(SDValue Op, SelectionDAG &DAG) const -{ +SDValue XCoreTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const { + LLVMContext &Context = *DAG.getContext(); StoreSDNode *ST = cast(Op); assert(!ST->isTruncatingStore() && "Unexpected store type"); assert(ST->getMemoryVT() == MVT::i32 && "Unexpected store EVT"); - if (allowsMisalignedMemoryAccesses(ST->getMemoryVT(), - ST->getAddressSpace(), - ST->getAlignment())) { + + if (allowsMemoryAccess(Context, DAG.getDataLayout(), ST->getMemoryVT(), + *ST->getMemOperand())) return SDValue(); - } - unsigned ABIAlignment = DAG.getDataLayout().getABITypeAlignment( - ST->getMemoryVT().getTypeForEVT(*DAG.getContext())); - // Leave aligned store alone. - if (ST->getAlignment() >= ABIAlignment) { - return SDValue(); - } + SDValue Chain = ST->getChain(); SDValue BasePtr = ST->getBasePtr(); SDValue Value = ST->getValue(); @@ -514,7 +500,7 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG) const if (ST->getAlignment() == 2) { SDValue Low = Value; SDValue High = DAG.getNode(ISD::SRL, dl, MVT::i32, Value, - DAG.getConstant(16, dl, MVT::i32)); + DAG.getConstant(16, dl, MVT::i32)); SDValue StoreLow = DAG.getTruncStore( Chain, dl, Low, BasePtr, ST->getPointerInfo(), MVT::i16, /* Alignment = */ 2, ST->getMemOperand()->getFlags()); @@ -527,7 +513,7 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG) const } // Lower to a call to __misaligned_store(BasePtr, Value). - Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext()); + Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(Context); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; @@ -540,7 +526,7 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG) const TargetLowering::CallLoweringInfo CLI(DAG); CLI.setDebugLoc(dl).setChain(Chain).setCallee( - CallingConv::C, Type::getVoidTy(*DAG.getContext()), + CallingConv::C, Type::getVoidTy(Context), DAG.getExternalSymbol("__misaligned_store", getPointerTy(DAG.getDataLayout())), std::move(Args));