llvm.org GIT mirror llvm / 95c218a
PR400 phase 2. Propagate attributed load/store information through DAGs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36356 91177308-0d34-0410-b5e6-96231b3b80d8 Christopher Lamb 13 years ago
5 changed file(s) with 122 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
310310 /// determined by their operands, and they produce a value AND a token chain.
311311 ///
312312 SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
313 const Value *SV, int SVOffset, bool isVolatile=false);
313 const Value *SV, int SVOffset, bool isVolatile=false,
314 unsigned Alignment=0);
314315 SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
315316 SDOperand Chain, SDOperand Ptr, const Value *SV,
316 int SVOffset, MVT::ValueType EVT, bool isVolatile=false);
317 int SVOffset, MVT::ValueType EVT, bool isVolatile=false,
318 unsigned Alignment=0);
317319 SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
318320 SDOperand Offset, ISD::MemIndexedMode AM);
319321 SDOperand getVecLoad(unsigned Count, MVT::ValueType VT, SDOperand Chain,
322324 /// getStore - Helper function to build ISD::STORE nodes.
323325 ///
324326 SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
325 const Value *SV, int SVOffset, bool isVolatile=false);
327 const Value *SV, int SVOffset, bool isVolatile=false,
328 unsigned Alignment=0);
326329 SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
327330 const Value *SV, int SVOffset, MVT::ValueType TVT,
328 bool isVolatile=false);
331 bool isVolatile=false, unsigned Alignment=0);
329332 SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
330333 SDOperand Offset, ISD::MemIndexedMode AM);
331334
14371437 friend class SelectionDAG;
14381438 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
14391439 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1440 const Value *SV, int O=0, unsigned Align=1, bool Vol=false)
1440 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
14411441 : SDNode(ISD::LOAD, VTs),
14421442 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
14431443 Alignment(Align), IsVolatile(Vol) {
14451445 Ops[1] = ChainPtrOff[1]; // Ptr
14461446 Ops[2] = ChainPtrOff[2]; // Off
14471447 InitOperands(Ops, 3);
1448 assert(Align != 0 && "Loads should have non-zero aligment");
14481449 assert((getOffset().getOpcode() == ISD::UNDEF ||
14491450 AddrMode != ISD::UNINDEXED) &&
14501451 "Only indexed load has a non-undef offset operand");
15071508 Ops[2] = ChainValuePtrOff[2]; // Ptr
15081509 Ops[3] = ChainValuePtrOff[3]; // Off
15091510 InitOperands(Ops, 4);
1511 assert(Align != 0 && "Stores should have non-zero aligment");
15101512 assert((getOffset().getOpcode() == ISD::UNDEF ||
15111513 AddrMode != ISD::UNINDEXED) &&
15121514 "Only indexed store has a non-undef offset operand");
12621262 (!AfterLegalize || TLI.isLoadXLegal(ISD::ZEXTLOAD, EVT))) {
12631263 SDOperand ExtLoad = DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(),
12641264 LN0->getBasePtr(), LN0->getSrcValue(),
1265 LN0->getSrcValueOffset(), EVT);
1265 LN0->getSrcValueOffset(), EVT,
1266 LN0->isVolatile(),
1267 LN0->getAlignment());
12661268 AddToWorkList(N);
12671269 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
12681270 return SDOperand(N, 0); // Return N so it doesn't get rechecked!
12791281 (!AfterLegalize || TLI.isLoadXLegal(ISD::ZEXTLOAD, EVT))) {
12801282 SDOperand ExtLoad = DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(),
12811283 LN0->getBasePtr(), LN0->getSrcValue(),
1282 LN0->getSrcValueOffset(), EVT);
1284 LN0->getSrcValueOffset(), EVT,
1285 LN0->isVolatile(),
1286 LN0->getAlignment());
12831287 AddToWorkList(N);
12841288 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
12851289 return SDOperand(N, 0); // Return N so it doesn't get rechecked!
13191323 AddToWorkList(NewPtr.Val);
13201324 SDOperand Load =
13211325 DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(), NewPtr,
1322 LN0->getSrcValue(), LN0->getSrcValueOffset(), EVT);
1326 LN0->getSrcValue(), LN0->getSrcValueOffset(), EVT,
1327 LN0->isVolatile(), LN0->getAlignment());
13231328 AddToWorkList(N);
13241329 CombineTo(N0.Val, Load, Load.getValue(1));
13251330 return SDOperand(N, 0); // Return N so it doesn't get rechecked!
21192124 SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, LN0->getChain(),
21202125 LN0->getBasePtr(), LN0->getSrcValue(),
21212126 LN0->getSrcValueOffset(),
2122 N0.getValueType());
2127 N0.getValueType(),
2128 LN0->isVolatile());
21232129 CombineTo(N, ExtLoad);
21242130 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
21252131 ExtLoad.getValue(1));
21352141 if (!AfterLegalize || TLI.isLoadXLegal(ISD::SEXTLOAD, EVT)) {
21362142 SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, LN0->getChain(),
21372143 LN0->getBasePtr(), LN0->getSrcValue(),
2138 LN0->getSrcValueOffset(), EVT);
2144 LN0->getSrcValueOffset(), EVT,
2145 LN0->isVolatile(),
2146 LN0->getAlignment());
21392147 CombineTo(N, ExtLoad);
21402148 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
21412149 ExtLoad.getValue(1));
22112219 SDOperand ExtLoad = DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(),
22122220 LN0->getBasePtr(), LN0->getSrcValue(),
22132221 LN0->getSrcValueOffset(),
2214 N0.getValueType());
2222 N0.getValueType(),
2223 LN0->isVolatile(),
2224 LN0->getAlignment());
22152225 CombineTo(N, ExtLoad);
22162226 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
22172227 ExtLoad.getValue(1));
22262236 MVT::ValueType EVT = LN0->getLoadedVT();
22272237 SDOperand ExtLoad = DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(),
22282238 LN0->getBasePtr(), LN0->getSrcValue(),
2229 LN0->getSrcValueOffset(), EVT);
2239 LN0->getSrcValueOffset(), EVT,
2240 LN0->isVolatile(),
2241 LN0->getAlignment());
22302242 CombineTo(N, ExtLoad);
22312243 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
22322244 ExtLoad.getValue(1));
23022314 SDOperand ExtLoad = DAG.getExtLoad(ISD::EXTLOAD, VT, LN0->getChain(),
23032315 LN0->getBasePtr(), LN0->getSrcValue(),
23042316 LN0->getSrcValueOffset(),
2305 N0.getValueType());
2317 N0.getValueType(),
2318 LN0->isVolatile(),
2319 LN0->getAlignment());
23062320 CombineTo(N, ExtLoad);
23072321 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
23082322 ExtLoad.getValue(1));
23202334 SDOperand ExtLoad = DAG.getExtLoad(LN0->getExtensionType(), VT,
23212335 LN0->getChain(), LN0->getBasePtr(),
23222336 LN0->getSrcValue(),
2323 LN0->getSrcValueOffset(), EVT);
2337 LN0->getSrcValueOffset(), EVT,
2338 LN0->isVolatile(),
2339 LN0->getAlignment());
23242340 CombineTo(N, ExtLoad);
23252341 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
23262342 ExtLoad.getValue(1));
23972413 AddToWorkList(NewPtr.Val);
23982414 SDOperand Load = (ExtType == ISD::NON_EXTLOAD)
23992415 ? DAG.getLoad(VT, LN0->getChain(), NewPtr,
2400 LN0->getSrcValue(), LN0->getSrcValueOffset())
2416 LN0->getSrcValue(), LN0->getSrcValueOffset(),
2417 LN0->isVolatile(), LN0->getAlignment())
24012418 : DAG.getExtLoad(ExtType, VT, LN0->getChain(), NewPtr,
2402 LN0->getSrcValue(), LN0->getSrcValueOffset(), EVT);
2419 LN0->getSrcValue(), LN0->getSrcValueOffset(), EVT,
2420 LN0->isVolatile(), LN0->getAlignment());
24032421 AddToWorkList(N);
24042422 if (CombineSRL) {
24052423 std::vector NowDead;
24782496 LoadSDNode *LN0 = cast(N0);
24792497 SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, LN0->getChain(),
24802498 LN0->getBasePtr(), LN0->getSrcValue(),
2481 LN0->getSrcValueOffset(), EVT);
2499 LN0->getSrcValueOffset(), EVT,
2500 LN0->isVolatile(),
2501 LN0->getAlignment());
24822502 CombineTo(N, ExtLoad);
24832503 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
24842504 return SDOperand(N, 0); // Return N so it doesn't get rechecked!
24912511 LoadSDNode *LN0 = cast(N0);
24922512 SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, LN0->getChain(),
24932513 LN0->getBasePtr(), LN0->getSrcValue(),
2494 LN0->getSrcValueOffset(), EVT);
2514 LN0->getSrcValueOffset(), EVT,
2515 LN0->isVolatile(),
2516 LN0->getAlignment());
24952517 CombineTo(N, ExtLoad);
24962518 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
24972519 return SDOperand(N, 0); // Return N so it doesn't get rechecked!
25512573 if (0 && ISD::isNON_EXTLoad(N0.Val) && N0.hasOneUse()) {
25522574 LoadSDNode *LN0 = cast(N0);
25532575 SDOperand Load = DAG.getLoad(VT, LN0->getChain(), LN0->getBasePtr(),
2554 LN0->getSrcValue(), LN0->getSrcValueOffset());
2576 LN0->getSrcValue(), LN0->getSrcValueOffset(),
2577 LN0->isVolatile(), LN0->getAlignment());
25552578 AddToWorkList(N);
25562579 CombineTo(N0.Val, DAG.getNode(ISD::BIT_CONVERT, N0.getValueType(), Load),
25572580 Load.getValue(1));
29412964 SDOperand ExtLoad = DAG.getExtLoad(ISD::EXTLOAD, VT, LN0->getChain(),
29422965 LN0->getBasePtr(), LN0->getSrcValue(),
29432966 LN0->getSrcValueOffset(),
2944 N0.getValueType());
2967 N0.getValueType(),
2968 LN0->isVolatile(),
2969 LN0->getAlignment());
29452970 CombineTo(N, ExtLoad);
29462971 CombineTo(N0.Val, DAG.getNode(ISD::FP_ROUND, N0.getValueType(), ExtLoad),
29472972 ExtLoad.getValue(1));
33303355 // Replace the chain to void dependency.
33313356 if (LD->getExtensionType() == ISD::NON_EXTLOAD) {
33323357 ReplLoad = DAG.getLoad(N->getValueType(0), BetterChain, Ptr,
3333 LD->getSrcValue(), LD->getSrcValueOffset());
3358 LD->getSrcValue(), LD->getSrcValueOffset(),
3359 LD->isVolatile(), LD->getAlignment());
33343360 } else {
33353361 ReplLoad = DAG.getExtLoad(LD->getExtensionType(),
33363362 LD->getValueType(0),
33373363 BetterChain, Ptr, LD->getSrcValue(),
33383364 LD->getSrcValueOffset(),
3339 LD->getLoadedVT());
3365 LD->getLoadedVT(),
3366 LD->isVolatile(),
3367 LD->getAlignment());
33403368 }
33413369
33423370 // Create token factor to keep old chain connected.
40394067 if (LLD->getExtensionType() == ISD::NON_EXTLOAD)
40404068 Load = DAG.getLoad(TheSelect->getValueType(0), LLD->getChain(),
40414069 Addr,LLD->getSrcValue(),
4042 LLD->getSrcValueOffset());
4070 LLD->getSrcValueOffset(),
4071 LLD->isVolatile(),
4072 LLD->getAlignment());
40434073 else {
40444074 Load = DAG.getExtLoad(LLD->getExtensionType(),
40454075 TheSelect->getValueType(0),
40464076 LLD->getChain(), Addr, LLD->getSrcValue(),
40474077 LLD->getSrcValueOffset(),
4048 LLD->getLoadedVT());
4078 LLD->getLoadedVT(),
4079 LLD->isVolatile(),
4080 LLD->getAlignment());
40494081 }
40504082 // Users of the select now use the result of the load.
40514083 CombineTo(TheSelect, Load);
1414 #include "llvm/Constants.h"
1515 #include "llvm/GlobalVariable.h"
1616 #include "llvm/Intrinsics.h"
17 #include "llvm/DerivedTypes.h"
1718 #include "llvm/Assembly/Writer.h"
1819 #include "llvm/CodeGen/MachineBasicBlock.h"
1920 #include "llvm/CodeGen/MachineConstantPool.h"
2021 #include "llvm/Support/MathExtras.h"
2122 #include "llvm/Target/MRegisterInfo.h"
23 #include "llvm/Target/TargetData.h"
2224 #include "llvm/Target/TargetLowering.h"
2325 #include "llvm/Target/TargetInstrInfo.h"
2426 #include "llvm/Target/TargetMachine.h"
15371539 SDOperand SelectionDAG::getLoad(MVT::ValueType VT,
15381540 SDOperand Chain, SDOperand Ptr,
15391541 const Value *SV, int SVOffset,
1540 bool isVolatile) {
1541 // FIXME: Alignment == 1 for now.
1542 unsigned Alignment = 1;
1542 bool isVolatile, unsigned Alignment) {
15431543 SDVTList VTs = getVTList(VT, MVT::Other);
15441544 SDOperand Undef = getNode(ISD::UNDEF, Ptr.getValueType());
15451545 SDOperand Ops[] = { Chain, Ptr, Undef };
15551555 void *IP = 0;
15561556 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
15571557 return SDOperand(E, 0);
1558 if (Alignment == 0) { // Ensure that codegen never sees alignment 0
1559 const Type *Ty = 0;
1560 if (VT != MVT::Vector && VT != MVT::iPTR) {
1561 Ty = MVT::getTypeForValueType(VT);
1562 } else if (SV) {
1563 const PointerType *PT = dyn_cast(SV->getType());
1564 assert(PT && "Value for load must be a pointer");
1565 Ty = PT->getElementType();
1566 }
1567 assert(Ty && "Could not get type information for load");
1568 Alignment = TLI.getTargetData()->getABITypeAlignment(Ty);
1569 }
15581570 SDNode *N = new LoadSDNode(Ops, VTs, ISD::UNINDEXED,
15591571 ISD::NON_EXTLOAD, VT, SV, SVOffset, Alignment,
15601572 isVolatile);
15671579 SDOperand Chain, SDOperand Ptr,
15681580 const Value *SV,
15691581 int SVOffset, MVT::ValueType EVT,
1570 bool isVolatile) {
1582 bool isVolatile, unsigned Alignment) {
15711583 // If they are asking for an extending load from/to the same thing, return a
15721584 // normal load.
15731585 if (VT == EVT)
15821594 assert(MVT::isInteger(VT) == MVT::isInteger(EVT) &&
15831595 "Cannot convert from FP to Int or Int -> FP!");
15841596
1585 // FIXME: Alignment == 1 for now.
1586 unsigned Alignment = 1;
15871597 SDVTList VTs = getVTList(VT, MVT::Other);
15881598 SDOperand Undef = getNode(ISD::UNDEF, Ptr.getValueType());
15891599 SDOperand Ops[] = { Chain, Ptr, Undef };
15991609 void *IP = 0;
16001610 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
16011611 return SDOperand(E, 0);
1612 if (Alignment == 0) { // Ensure that codegen never sees alignment 0
1613 const Type *Ty = 0;
1614 if (VT != MVT::Vector && VT != MVT::iPTR) {
1615 Ty = MVT::getTypeForValueType(VT);
1616 } else if (SV) {
1617 const PointerType *PT = dyn_cast(SV->getType());
1618 assert(PT && "Value for load must be a pointer");
1619 Ty = PT->getElementType();
1620 }
1621 assert(Ty && "Could not get type information for load");
1622 Alignment = TLI.getTargetData()->getABITypeAlignment(Ty);
1623 }
16021624 SDNode *N = new LoadSDNode(Ops, VTs, ISD::UNINDEXED, ExtType, EVT,
16031625 SV, SVOffset, Alignment, isVolatile);
16041626 CSEMap.InsertNode(N, IP);
16461668
16471669 SDOperand SelectionDAG::getStore(SDOperand Chain, SDOperand Val,
16481670 SDOperand Ptr, const Value *SV, int SVOffset,
1649 bool isVolatile) {
1671 bool isVolatile, unsigned Alignment) {
16501672 MVT::ValueType VT = Val.getValueType();
16511673
1652 // FIXME: Alignment == 1 for now.
1653 unsigned Alignment = 1;
16541674 SDVTList VTs = getVTList(MVT::Other);
16551675 SDOperand Undef = getNode(ISD::UNDEF, Ptr.getValueType());
16561676 SDOperand Ops[] = { Chain, Val, Ptr, Undef };
16661686 void *IP = 0;
16671687 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
16681688 return SDOperand(E, 0);
1689 if (Alignment == 0) { // Ensure that codegen never sees alignment 0
1690 const Type *Ty = 0;
1691 if (VT != MVT::Vector && VT != MVT::iPTR) {
1692 Ty = MVT::getTypeForValueType(VT);
1693 } else if (SV) {
1694 const PointerType *PT = dyn_cast(SV->getType());
1695 assert(PT && "Value for store must be a pointer");
1696 Ty = PT->getElementType();
1697 }
1698 assert(Ty && "Could not get type information for store");
1699 Alignment = TLI.getTargetData()->getABITypeAlignment(Ty);
1700 }
16691701 SDNode *N = new StoreSDNode(Ops, VTs, ISD::UNINDEXED, false,
16701702 VT, SV, SVOffset, Alignment, isVolatile);
16711703 CSEMap.InsertNode(N, IP);
16761708 SDOperand SelectionDAG::getTruncStore(SDOperand Chain, SDOperand Val,
16771709 SDOperand Ptr, const Value *SV,
16781710 int SVOffset, MVT::ValueType SVT,
1679 bool isVolatile) {
1711 bool isVolatile, unsigned Alignment) {
16801712 MVT::ValueType VT = Val.getValueType();
16811713 bool isTrunc = VT != SVT;
16821714
16841716 assert(MVT::isInteger(VT) == MVT::isInteger(SVT) &&
16851717 "Can't do FP-INT conversion!");
16861718
1687 // FIXME: Alignment == 1 for now.
1688 unsigned Alignment = 1;
16891719 SDVTList VTs = getVTList(MVT::Other);
16901720 SDOperand Undef = getNode(ISD::UNDEF, Ptr.getValueType());
16911721 SDOperand Ops[] = { Chain, Val, Ptr, Undef };
17011731 void *IP = 0;
17021732 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
17031733 return SDOperand(E, 0);
1734 if (Alignment == 0) { // Ensure that codegen never sees alignment 0
1735 const Type *Ty = 0;
1736 if (VT != MVT::Vector && VT != MVT::iPTR) {
1737 Ty = MVT::getTypeForValueType(VT);
1738 } else if (SV) {
1739 const PointerType *PT = dyn_cast(SV->getType());
1740 assert(PT && "Value for store must be a pointer");
1741 Ty = PT->getElementType();
1742 }
1743 assert(Ty && "Could not get type information for store");
1744 Alignment = TLI.getTargetData()->getABITypeAlignment(Ty);
1745 }
17041746 SDNode *N = new StoreSDNode(Ops, VTs, ISD::UNINDEXED, isTrunc,
17051747 SVT, SV, SVOffset, Alignment, isVolatile);
17061748 CSEMap.InsertNode(N, IP);
497497
498498 SDOperand getLoadFrom(const Type *Ty, SDOperand Ptr,
499499 const Value *SV, SDOperand Root,
500 bool isVolatile);
500 bool isVolatile, unsigned Alignment);
501501
502502 SDOperand getIntPtrConstant(uint64_t Val) {
503503 return DAG.getConstant(Val, TLI.getPointerTy());
23122312 }
23132313
23142314 setValue(&I, getLoadFrom(I.getType(), Ptr, I.getOperand(0),
2315 Root, I.isVolatile()));
2315 Root, I.isVolatile(), I.getAlignment()));
23162316 }
23172317
23182318 SDOperand SelectionDAGLowering::getLoadFrom(const Type *Ty, SDOperand Ptr,
23192319 const Value *SV, SDOperand Root,
2320 bool isVolatile) {
2320 bool isVolatile,
2321 unsigned Alignment) {
23212322 SDOperand L;
23222323 if (const VectorType *PTy = dyn_cast(Ty)) {
23232324 MVT::ValueType PVT = TLI.getValueType(PTy->getElementType());
23242325 L = DAG.getVecLoad(PTy->getNumElements(), PVT, Root, Ptr,
23252326 DAG.getSrcValue(SV));
23262327 } else {
2327 L = DAG.getLoad(TLI.getValueType(Ty), Root, Ptr, SV, 0, isVolatile);
2328 L = DAG.getLoad(TLI.getValueType(Ty), Root, Ptr, SV, 0,
2329 isVolatile, Alignment);
23282330 }
23292331
23302332 if (isVolatile)
23412343 SDOperand Src = getValue(SrcV);
23422344 SDOperand Ptr = getValue(I.getOperand(1));
23432345 DAG.setRoot(DAG.getStore(getRoot(), Src, Ptr, I.getOperand(1), 0,
2344 I.isVolatile()));
2346 I.isVolatile(), I.getAlignment()));
23452347 }
23462348
23472349 /// IntrinsicCannotAccessMemory - Return true if the specified intrinsic cannot