llvm.org GIT mirror llvm / 63c21de
Revert r1296656, "Fix rdar://9289512 - not folding load into compare at -O0...", which broke a couple GCC test suite tests at -O0. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129914 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
3 changed file(s) with 16 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
279279
280280 void PrepareEHLandingPad();
281281 void SelectAllBasicBlocks(const Function &Fn);
282 bool TryToFoldFastISelLoad(const LoadInst *LI, const Instruction *FoldInst,
283 FastISel *FastIS);
282 bool TryToFoldFastISelLoad(const LoadInst *LI, FastISel *FastIS);
284283 void FinishBasicBlock();
285284
286285 void SelectBasicBlock(BasicBlock::const_iterator Begin,
745745
746746
747747
748 /// TryToFoldFastISelLoad - We're checking to see if we can fold the specified
749 /// load into the specified FoldInst. Note that we could have a sequence where
750 /// multiple LLVM IR instructions are folded into the same machineinstr. For
751 /// example we could have:
752 /// A: x = load i32 *P
753 /// B: y = icmp A, 42
754 /// C: br y, ...
755 ///
756 /// In this scenario, LI is "A", and FoldInst is "C". We know about "B" (and
757 /// any other folded instructions) because it is between A and C.
758 ///
759 /// If we succeed in folding the load into the operation, return true.
760 ///
748
761749 bool SelectionDAGISel::TryToFoldFastISelLoad(const LoadInst *LI,
762 const Instruction *FoldInst,
763750 FastISel *FastIS) {
764 SmallPtrSet FoldedInsts;
765 for (BasicBlock::const_iterator II = FoldInst; &*II != LI; --II)
766 FoldedInsts.insert(II);
767
768 // We know that the load has a single use, but don't know what it is. If it
769 // isn't one of the folded instructions, then we can't succeed here.
770 if (!FoldedInsts.count(LI->use_back()))
771 return false;
772
773751 // Don't try to fold volatile loads. Target has to deal with alignment
774752 // constraints.
775753 if (LI->isVolatile()) return false;
854832 /// Return false if it needs to be emitted.
855833 static bool isFoldedOrDeadInstruction(const Instruction *I,
856834 FunctionLoweringInfo *FuncInfo) {
857 return !I->mayWriteToMemory() && // Side-effecting instructions aren't folded.
858 !isa(I) && // Terminators aren't folded.
859 !isa(I) && // Debug instructions aren't folded.
860 !FuncInfo->isExportedInst(I); // Exported instrs must be computed.
835 return !I->mayWriteToMemory() &&
836 !isa(I) &&
837 !isa(I) &&
838 !FuncInfo->isExportedInst(I);
861839 }
862840
863841 void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
949927
950928 // Try to select the instruction with FastISel.
951929 if (FastIS->SelectInstruction(Inst)) {
952 // If fast isel succeeded, skip over all the folded instructions, and
953 // then see if there is a load right before the selected instructions.
954 // Try to fold the load if so.
955 const Instruction *BeforeInst = Inst;
956 while (BeforeInst != Begin) {
957 BeforeInst = llvm::prior(BasicBlock::const_iterator(BeforeInst));
958 if (!isFoldedOrDeadInstruction(BeforeInst, FuncInfo))
959 break;
960 }
961 if (BeforeInst != Inst && isa(BeforeInst) &&
962 BeforeInst->hasOneUse() &&
963 TryToFoldFastISelLoad(cast(BeforeInst), Inst, FastIS))
964 // If we succeeded, don't re-select the load.
965 BI = llvm::next(BasicBlock::const_iterator(BeforeInst));
930 // If fast isel succeeded, check to see if there is a single-use
931 // non-volatile load right before the selected instruction, and see if
932 // the load is used by the instruction. If so, try to fold it.
933 const Instruction *BeforeInst = 0;
934 if (Inst != Begin)
935 BeforeInst = llvm::prior(llvm::prior(BI));
936 if (BeforeInst && isa(BeforeInst) &&
937 BeforeInst->hasOneUse() && *BeforeInst->use_begin() == Inst &&
938 TryToFoldFastISelLoad(cast(BeforeInst), FastIS))
939 --BI; // If we succeeded, don't re-select the load.
966940 continue;
967941 }
968942
1111
1212 ; CHECK: test1:
1313 ; CHECK: andl $8,
14
15
16 ; rdar://9289512 - The load should fold into the compare.
17 define void @test2(i64 %x) nounwind ssp {
18 entry:
19 %x.addr = alloca i64, align 8
20 store i64 %x, i64* %x.addr, align 8
21 %tmp = load i64* %x.addr, align 8
22 %cmp = icmp sgt i64 %tmp, 42
23 br i1 %cmp, label %if.then, label %if.end
24
25 if.then: ; preds = %entry
26 br label %if.end
27
28 if.end: ; preds = %if.then, %entry
29 ret void
30 ; CHECK: test2:
31 ; CHECK: movq %rdi, -8(%rsp)
32 ; CHECK: cmpq $42, -8(%rsp)
33 }
34
35
3614
3715
3816 @G = external global i32