llvm.org GIT mirror llvm / ff89dcb
-Revert parts of 84326 and 84411. Distinquishing between fixed and non-fixed stack slots and giving them different PseudoSourceValue's did not fix the problem of post-alloc scheduling miscompiling llvm itself. - Apply Dan's conservative workaround by assuming any non fixed stack slots can alias other memory locations. This means a load from spill slot #1 cannot move above a store of spill slot #2. - Enable post-alloc scheduling for x86 at optimization leverl Default and above. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84424 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 10 years ago
15 changed file(s) with 99 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
3838 ///
3939 virtual bool isConstant(const MachineFrameInfo *) const;
4040
41 /// isAliased - Test whether the memory pointed to by this
42 /// PseudoSourceValue may also be pointed to by an LLVM IR Value.
43 virtual bool isAliased() const;
44
4145 /// classof - Methods for support type inquiry through isa, cast, and
4246 /// dyn_cast:
4347 ///
6262
6363 virtual bool isConstant(const MachineFrameInfo *MFI) const;
6464
65 virtual bool isAliased() const;
66
6567 virtual void printCustom(raw_ostream &OS) const {
6668 OS << "FixedStack" << FI;
6769 }
8890 return false;
8991 }
9092
93 bool PseudoSourceValue::isAliased() const {
94 if (this == getStack() ||
95 this == getGOT() ||
96 this == getConstantPool() ||
97 this == getJumpTable())
98 return false;
99 llvm_unreachable("Unknown PseudoSourceValue!");
100 return true;
101 }
102
91103 bool FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo *MFI) const{
92104 return MFI && MFI->isImmutableObjectIndex(FI);
93105 }
106
107 bool FixedStackPseudoSourceValue::isAliased() const{
108 // Negative frame indices are used for special things that don't
109 // appear in LLVM IR. Non-negative indices may be used for things
110 // like static allocas.
111 return FI >= 0;
112 }
105105 return 0;
106106
107107 V = getUnderlyingObject(V);
108 if (!isa(V) && !isIdentifiedObject(V))
109 return 0;
110
111 return V;
108 if (const PseudoSourceValue *PSV = dyn_cast(V)) {
109 // For now, ignore PseudoSourceValues which may alias LLVM IR values
110 // because the code that uses this function has no way to cope with
111 // such aliases.
112 if (PSV->isAliased())
113 return 0;
114 return V;
115 }
116
117 if (isIdentifiedObject(V))
118 return V;
119
120 return 0;
112121 }
113122
114123 void ScheduleDAGInstrs::StartBlock(MachineBasicBlock *BB) {
638638 EVT PtrVT = TLI.getPointerTy();
639639 SDValue StackPtr = DAG.CreateStackTemporary(VT);
640640
641 int SPFI = cast(StackPtr.getNode())->getIndex();
642
641643 // Store the vector.
642644 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Tmp1, StackPtr,
643 PseudoSourceValue::getStack(), 0);
645 PseudoSourceValue::getFixedStack(SPFI), 0);
644646
645647 // Truncate or zero extend offset to target pointer type.
646648 unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND;
651653 SDValue StackPtr2 = DAG.getNode(ISD::ADD, dl, IdxVT, Tmp3, StackPtr);
652654 // Store the scalar value.
653655 Ch = DAG.getTruncStore(Ch, dl, Tmp2, StackPtr2,
654 PseudoSourceValue::getStack(), 0, EltVT);
656 PseudoSourceValue::getFixedStack(SPFI), 0, EltVT);
655657 // Load the updated vector.
656658 return DAG.getLoad(VT, dl, Ch, StackPtr,
657 PseudoSourceValue::getStack(), 0);
659 PseudoSourceValue::getFixedStack(SPFI), 0);
658660 }
659661
660662
15141516 EVT OpVT = Node->getOperand(0).getValueType();
15151517 DebugLoc dl = Node->getDebugLoc();
15161518 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1517 const Value *SV = PseudoSourceValue::getStack();
1519 int FI = cast(FIPtr.getNode())->getIndex();
1520 const Value *SV = PseudoSourceValue::getFixedStack(FI);
15181521
15191522 // Emit a store of each element to the stack slot.
15201523 SmallVector Stores;
17081711 getTypeForEVT(*DAG.getContext()));
17091712 SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
17101713
1714 FrameIndexSDNode *StackPtrFI = cast(FIPtr);
1715 int SPFI = StackPtrFI->getIndex();
1716 const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
1717
17111718 unsigned SrcSize = SrcOp.getValueType().getSizeInBits();
17121719 unsigned SlotSize = SlotVT.getSizeInBits();
17131720 unsigned DestSize = DestVT.getSizeInBits();
17141721 unsigned DestAlign =
1715 TLI.getTargetData()->getPrefTypeAlignment(DestVT.
1716 getTypeForEVT(*DAG.getContext()));
1722 TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForEVT(*DAG.getContext()));
17171723
17181724 // Emit a store to the stack slot. Use a truncstore if the input value is
17191725 // later than DestVT.
17201726 SDValue Store;
1721 const Value *SV = PseudoSourceValue::getStack();
1727
17221728 if (SrcSize > SlotSize)
17231729 Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
17241730 SV, 0, SlotVT, false, SrcAlign);
17431749 // then load the whole vector back out.
17441750 SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0));
17451751
1752 FrameIndexSDNode *StackPtrFI = cast(StackPtr);
1753 int SPFI = StackPtrFI->getIndex();
1754
17461755 SDValue Ch = DAG.getTruncStore(DAG.getEntryNode(), dl, Node->getOperand(0),
17471756 StackPtr,
1748 PseudoSourceValue::getStack(), 0,
1757 PseudoSourceValue::getFixedStack(SPFI), 0,
17491758 Node->getValueType(0).getVectorElementType());
17501759 return DAG.getLoad(Node->getValueType(0), dl, Ch, StackPtr,
1751 PseudoSourceValue::getStack(), 0);
1760 PseudoSourceValue::getFixedStack(SPFI), 0);
17521761 }
17531762
17541763
117117 TLI.getTargetData()->getPrefTypeAlignment(NOutVT.
118118 getTypeForEVT(*DAG.getContext()));
119119 SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment);
120 const Value *SV = PseudoSourceValue::getStack();
120 int SPFI = cast(StackPtr.getNode())->getIndex();
121 const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
121122
122123 // Emit a store to the stack slot.
123124 SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, InOp, StackPtr, SV, 0);
10561056 EVT EltVT = VecVT.getVectorElementType();
10571057 DebugLoc dl = N->getDebugLoc();
10581058 SDValue StackPtr = DAG.CreateStackTemporary(VecVT);
1059 const Value *SV = PseudoSourceValue::getStack();
1059 int SPFI = cast(StackPtr.getNode())->getIndex();
1060 const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
10601061 SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, SV, 0);
10611062
10621063 // Load back the required element.
35063506 SDValue Ptr, SDValue Cmp,
35073507 SDValue Swp, const Value* PtrVal,
35083508 unsigned Alignment) {
3509 MachineFunction &MF = getMachineFunction();
3510 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
3511
35123509 if (Alignment == 0) // Ensure that codegen never sees alignment 0
35133510 Alignment = getEVTAlignment(MemVT);
35143511
35153512 // Check if the memory reference references a frame index
35163513 if (!PtrVal)
35173514 if (const FrameIndexSDNode *FI =
3518 dyn_cast(Ptr.getNode())) {
3519 if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
3520 PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
3521 else
3522 PtrVal = PseudoSourceValue::getStack();
3523 }
3524
3515 dyn_cast(Ptr.getNode()))
3516 PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
3517
3518 MachineFunction &MF = getMachineFunction();
35253519 unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
35263520
35273521 // For now, atomics are considered to be volatile always.
35653559 SDValue Ptr, SDValue Val,
35663560 const Value* PtrVal,
35673561 unsigned Alignment) {
3568 MachineFunction &MF = getMachineFunction();
3569 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
3570
35713562 if (Alignment == 0) // Ensure that codegen never sees alignment 0
35723563 Alignment = getEVTAlignment(MemVT);
35733564
35743565 // Check if the memory reference references a frame index
35753566 if (!PtrVal)
35763567 if (const FrameIndexSDNode *FI =
3577 dyn_cast(Ptr.getNode()))
3578 if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
3579 PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
3580 else
3581 PtrVal = PseudoSourceValue::getStack();
3582
3568 dyn_cast(Ptr.getNode()))
3569 PtrVal = PseudoSourceValue::getFixedStack(FI->getIndex());
3570
3571 MachineFunction &MF = getMachineFunction();
35833572 unsigned Flags = MachineMemOperand::MOLoad | MachineMemOperand::MOStore;
35843573
35853574 // For now, atomics are considered to be volatile always.
37173706 SDValue Ptr, SDValue Offset,
37183707 const Value *SV, int SVOffset, EVT MemVT,
37193708 bool isVolatile, unsigned Alignment) {
3720 MachineFunction &MF = getMachineFunction();
3721 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
3722
37233709 if (Alignment == 0) // Ensure that codegen never sees alignment 0
37243710 Alignment = getEVTAlignment(VT);
37253711
37263712 // Check if the memory reference references a frame index
37273713 if (!SV)
37283714 if (const FrameIndexSDNode *FI =
3729 dyn_cast(Ptr.getNode()))
3730 if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
3731 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3732 else
3733 SV = PseudoSourceValue::getStack();
3734
3715 dyn_cast(Ptr.getNode()))
3716 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3717
3718 MachineFunction &MF = getMachineFunction();
37353719 unsigned Flags = MachineMemOperand::MOLoad;
37363720 if (isVolatile)
37373721 Flags |= MachineMemOperand::MOVolatile;
38213805 SDValue SelectionDAG::getStore(SDValue Chain, DebugLoc dl, SDValue Val,
38223806 SDValue Ptr, const Value *SV, int SVOffset,
38233807 bool isVolatile, unsigned Alignment) {
3824 MachineFunction &MF = getMachineFunction();
3825 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
3826
38273808 if (Alignment == 0) // Ensure that codegen never sees alignment 0
38283809 Alignment = getEVTAlignment(Val.getValueType());
38293810
38303811 // Check if the memory reference references a frame index
38313812 if (!SV)
38323813 if (const FrameIndexSDNode *FI =
3833 dyn_cast(Ptr.getNode()))
3834 if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
3835 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3836 else
3837 SV = PseudoSourceValue::getStack();
3838
3814 dyn_cast(Ptr.getNode()))
3815 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3816
3817 MachineFunction &MF = getMachineFunction();
38393818 unsigned Flags = MachineMemOperand::MOStore;
38403819 if (isVolatile)
38413820 Flags |= MachineMemOperand::MOVolatile;
38723851 SDValue Ptr, const Value *SV,
38733852 int SVOffset, EVT SVT,
38743853 bool isVolatile, unsigned Alignment) {
3875 MachineFunction &MF = getMachineFunction();
3876 MachineFrameInfo *FrameInfo = MF.getFrameInfo();
3877
38783854 if (Alignment == 0) // Ensure that codegen never sees alignment 0
38793855 Alignment = getEVTAlignment(SVT);
38803856
38813857 // Check if the memory reference references a frame index
38823858 if (!SV)
38833859 if (const FrameIndexSDNode *FI =
3884 dyn_cast(Ptr.getNode()))
3885 if (FrameInfo->isFixedObjectIndex(FI->getIndex()))
3886 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3887 else
3888 SV = PseudoSourceValue::getStack();
3889
3860 dyn_cast(Ptr.getNode()))
3861 SV = PseudoSourceValue::getFixedStack(FI->getIndex());
3862
3863 MachineFunction &MF = getMachineFunction();
38903864 unsigned Flags = MachineMemOperand::MOStore;
38913865 if (isVolatile)
38923866 Flags |= MachineMemOperand::MOVolatile;
41954195 SDValue FIN = DAG.getFrameIndex(FI, PtrTy);
41964196
41974197 // Store the stack protector onto the stack.
4198 const Value *SV = MFI->isFixedObjectIndex(FI)
4199 ? PseudoSourceValue::getFixedStack(FI)
4200 : PseudoSourceValue::getStack();
42014198 SDValue Result = DAG.getStore(getRoot(), getCurDebugLoc(), Src, FIN,
4202 SV, 0, true);
4199 PseudoSourceValue::getFixedStack(FI),
4200 0, true);
42034201 setValue(&I, Result);
42044202 DAG.setRoot(Result);
42054203 return 0;
465465 // Update the memory references. This changes the MachineMemOperands
466466 // directly. They may be in use by multiple instructions, however all
467467 // instructions using OldFI are being rewritten to use NewFI.
468 const Value *OldSV = MFI->isFixedObjectIndex(OldFI)
469 ? PseudoSourceValue::getFixedStack(OldFI) : PseudoSourceValue::getStack();
470 const Value *NewSV = MFI->isFixedObjectIndex(NewFI)
471 ? PseudoSourceValue::getFixedStack(NewFI) : PseudoSourceValue::getStack();
468 const Value *OldSV = PseudoSourceValue::getFixedStack(OldFI);
469 const Value *NewSV = PseudoSourceValue::getFixedStack(NewFI);
472470 for (MachineInstr::mmo_iterator I = MI->memoperands_begin(),
473471 E = MI->memoperands_end(); I != E; ++I)
474472 if ((*I)->getValue() == OldSV)
185185 "Folded a use to a non-load!");
186186 const MachineFrameInfo &MFI = *MF.getFrameInfo();
187187 assert(MFI.getObjectOffset(FrameIndex) != -1);
188 const Value *SV = MFI.isFixedObjectIndex(FrameIndex)
189 ? PseudoSourceValue::getFixedStack(FrameIndex)
190 : PseudoSourceValue::getStack();
191188 MachineMemOperand *MMO =
192 MF.getMachineMemOperand(SV,
189 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIndex),
193190 Flags, /*Offset=*/0,
194191 MFI.getObjectSize(FrameIndex),
195192 MFI.getObjectAlignment(FrameIndex));
669669 MachineFunction &MF = *MBB.getParent();
670670 MachineFrameInfo &MFI = *MF.getFrameInfo();
671671
672 const Value *SV = (MFI.isFixedObjectIndex(FI) ||
673 MFI.isSpillSlotObjectIndex(FI))
674 ? PseudoSourceValue::getFixedStack(FI) : PseudoSourceValue::getStack();
675672 MachineMemOperand *MMO =
676 MF.getMachineMemOperand(SV,
673 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
677674 MachineMemOperand::MOStore, 0,
678675 MFI.getObjectSize(FI),
679676 MFI.getObjectAlignment(FI));
710707 MachineFunction &MF = *MBB.getParent();
711708 MachineFrameInfo &MFI = *MF.getFrameInfo();
712709
713 const Value *SV = (MFI.isFixedObjectIndex(FI) ||
714 MFI.isSpillSlotObjectIndex(FI))
715 ? PseudoSourceValue::getFixedStack(FI) : PseudoSourceValue::getStack();
716710 MachineMemOperand *MMO =
717 MF.getMachineMemOperand(SV,
711 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
718712 MachineMemOperand::MOLoad, 0,
719713 MFI.getObjectSize(FI),
720714 MFI.getObjectAlignment(FI));
22242224 /// StoreTailCallArgumentsToStackSlot - Stores arguments to their stack slot.
22252225 static void
22262226 StoreTailCallArgumentsToStackSlot(SelectionDAG &DAG,
2227 SDValue Chain,
2227 SDValue Chain,
22282228 const SmallVector &TailCallArgs,
22292229 SmallVector &MemOpChains,
22302230 DebugLoc dl) {
33873387
33883388 // STD the extended value into the stack slot.
33893389 MachineMemOperand *MMO =
3390 MF.getMachineMemOperand(PseudoSourceValue::getStack(),
3390 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIdx),
33913391 MachineMemOperand::MOStore, 0, 8, 8);
33923392 SDValue Ops[] = { DAG.getEntryNode(), Ext64, FIdx };
33933393 SDValue Store =
15611561 SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64);
15621562 SDValue Store =
15631563 DAG.getStore(Val.getValue(1), dl, Val, FIN,
1564 PseudoSourceValue::getStack(),
1564 PseudoSourceValue::getFixedStack(RegSaveFrameIndex),
15651565 Offset);
15661566 MemOps.push_back(Store);
15671567 Offset += 8;
17641764 case CCValAssign::Indirect: {
17651765 // Store the argument.
17661766 SDValue SpillSlot = DAG.CreateStackTemporary(VA.getValVT());
1767 int FI = cast(SpillSlot)->getIndex();
17671768 Chain = DAG.getStore(Chain, dl, Arg, SpillSlot,
1768 PseudoSourceValue::getStack(), 0);
1769 PseudoSourceValue::getFixedStack(FI), 0);
17691770 Arg = SpillSlot;
17701771 break;
17711772 }
48664867 SDValue StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
48674868 SDValue Chain = DAG.getStore(DAG.getEntryNode(), dl, Op.getOperand(0),
48684869 StackSlot,
4869 PseudoSourceValue::getStack(), 0);
4870 PseudoSourceValue::getFixedStack(SSFI), 0);
48704871 return BuildFILD(Op, SrcVT, Chain, StackSlot, DAG);
48714872 }
48724873
49074908 Ops.push_back(InFlag);
49084909 Chain = DAG.getNode(X86ISD::FST, dl, Tys, &Ops[0], Ops.size());
49094910 Result = DAG.getLoad(Op.getValueType(), dl, Chain, StackSlot,
4910 PseudoSourceValue::getStack(), 0);
4911 PseudoSourceValue::getFixedStack(SSFI), 0);
49114912 }
49124913
49134914 return Result;
51225123 if (isScalarFPTypeInSSEReg(Op.getOperand(0).getValueType())) {
51235124 assert(DstTy == MVT::i64 && "Invalid FP_TO_SINT to lower!");
51245125 Chain = DAG.getStore(Chain, dl, Value, StackSlot,
5125 PseudoSourceValue::getStack(), 0);
5126 PseudoSourceValue::getFixedStack(SSFI), 0);
51265127 SDVTList Tys = DAG.getVTList(Op.getOperand(0).getValueType(), MVT::Other);
51275128 SDValue Ops[] = {
51285129 Chain, StackSlot, DAG.getValueType(Op.getOperand(0).getValueType())
77177718 // stores were performed.
77187719 const BasicBlock *LLVM_BB = MBB->getBasicBlock();
77197720 MachineFunction *F = MBB->getParent();
7720 MachineFrameInfo *MFI = F->getFrameInfo();
77217721 MachineFunction::iterator MBBIter = MBB;
77227722 ++MBBIter;
77237723 MachineBasicBlock *XMMSaveMBB = F->CreateMachineBasicBlock(LLVM_BB);
77497749 }
77507750
77517751 // In the XMM save block, save all the XMM argument registers.
7752 const Value *SV = MFI->isFixedObjectIndex(RegSaveFrameIndex)
7753 ? PseudoSourceValue::getFixedStack(RegSaveFrameIndex)
7754 : PseudoSourceValue::getStack();
77557752 for (int i = 3, e = MI->getNumOperands(); i != e; ++i) {
77567753 int64_t Offset = (i - 3) * 16 + VarArgsFPOffset;
77577754 MachineMemOperand *MMO =
7758 F->getMachineMemOperand(SV, MachineMemOperand::MOStore, Offset,
7759 /*Size=*/16, /*Align=*/16);
7755 F->getMachineMemOperand(
7756 PseudoSourceValue::getFixedStack(RegSaveFrameIndex),
7757 MachineMemOperand::MOStore, Offset,
7758 /*Size=*/16, /*Align=*/16);
77607759 BuildMI(XMMSaveMBB, DL, TII->get(X86::MOVAPSmr))
77617760 .addFrameIndex(RegSaveFrameIndex)
77627761 .addImm(/*Scale=*/1)
142142 Flags |= MachineMemOperand::MOLoad;
143143 if (TID.mayStore())
144144 Flags |= MachineMemOperand::MOStore;
145 const Value *SV = (MFI.isFixedObjectIndex(FI) ||
146 MFI.isSpillSlotObjectIndex(FI))
147 ? PseudoSourceValue::getFixedStack(FI) : PseudoSourceValue::getStack();
148145 MachineMemOperand *MMO =
149 MF.getMachineMemOperand(SV,
146 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
150147 Flags, Offset,
151148 MFI.getObjectSize(FI),
152149 MFI.getObjectAlignment(FI));
219219 /// at 'More' optimization level.
220220 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel) const {
221221 // FIXME: This causes llvm to miscompile itself on i386. :-(
222 return false/*OptLevel >= CodeGenOpt::Default*/;
222 return OptLevel >= CodeGenOpt::Default;
223223 }
224224 };
225225