llvm.org GIT mirror llvm / 0a9e3d6
final step needed to resolve PR6627, which allows us to flatten the code down to a nice and tidy: %x1 = load i32* %0, align 4 %1 = icmp eq i32 %x1, 1179403647 br i1 %1, label %if.then, label %if.end instead of doing lots of loads and branches. May the FreeBSD bootloader long fit in its allocated space. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130416 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
3 changed file(s) with 79 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
431431 /// addToLeaderTable - Push a new Value to the LeaderTable onto the list for
432432 /// its value number.
433433 void addToLeaderTable(uint32_t N, Value *V, BasicBlock *BB) {
434 LeaderTableEntry& Curr = LeaderTable[N];
434 LeaderTableEntry &Curr = LeaderTable[N];
435435 if (!Curr.Val) {
436436 Curr.Val = V;
437437 Curr.BB = BB;
438438 return;
439439 }
440440
441 LeaderTableEntry* Node = TableAllocator.Allocate();
441 LeaderTableEntry *Node = TableAllocator.Allocate();
442442 Node->Val = V;
443443 Node->BB = BB;
444444 Node->Next = Curr.Next;
943943
944944 Value *PtrVal = SrcVal->getPointerOperand();
945945
946 IRBuilder<> Builder(SrcVal->getParent(), SrcVal);
946 // Insert the new load after the old load. This ensures that subsequent
947 // memdep queries will find the new load. We can't easily remove the old
948 // load completely because it is already in the value numbering table.
949 IRBuilder<> Builder(SrcVal->getParent(), ++BasicBlock::iterator(SrcVal));
947950 const Type *DestPTy =
948951 IntegerType::get(LoadTy->getContext(), NewLoadSize*8);
949952 DestPTy = PointerType::get(DestPTy,
966969 RV = Builder.CreateTrunc(RV, SrcVal->getType());
967970 SrcVal->replaceAllUsesWith(RV);
968971 gvn.getMemDep().removeInstruction(SrcVal);
972 //gvn.markInstructionForDeletion(SrcVal);
969973 SrcVal = NewLoad;
970974 }
971975
None ; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
0 ; RUN: opt < %s -basicaa -gvn -S -die | FileCheck %s
11
22 ; 32-bit little endian target.
33 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
596596 ;; Load Widening
597597 ;;===----------------------------------------------------------------------===;;
598598
599 %widening1 = type { i32, i8, i8 }
599 %widening1 = type { i32, i8, i8, i8, i8 }
600600
601601 @f = global %widening1 zeroinitializer, align 4
602602
603 define i32 @test_widening1() nounwind ssp noredzone {
603 define i32 @test_widening1(i8* %P) nounwind ssp noredzone {
604604 entry:
605605 %tmp = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 1), align 4
606606 %conv = zext i8 %tmp to i32
615615 ; CHECK-ret i32
616616 }
617617
618
618 define i32 @test_widening2() nounwind ssp noredzone {
619 entry:
620 %tmp = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 1), align 4
621 %conv = zext i8 %tmp to i32
622 %tmp1 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 2), align 1
623 %conv2 = zext i8 %tmp1 to i32
624 %add = add nsw i32 %conv, %conv2
625
626 %tmp2 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 3), align 2
627 %conv3 = zext i8 %tmp2 to i32
628 %add2 = add nsw i32 %add, %conv3
629
630 %tmp3 = load i8* getelementptr inbounds (%widening1* @f, i64 0, i32 4), align 1
631 %conv4 = zext i8 %tmp3 to i32
632 %add3 = add nsw i32 %add2, %conv3
633
634 ret i32 %add3
635 ; CHECK: @test_widening2
636 ; CHECK-NOT: load
637 ; CHECK: load i32*
638 ; CHECK-NOT: load
639 ; CHECK-ret i32
640 }
641
5959 %call25 = call i32 (...)* @doo()
6060 br label %if.end
6161
62 if.end: ; preds = %if.then, %land.lhs.true17, %land.lhs.true9, %land.lhs.true, %entry
62 if.end:
6363 ret void
6464
6565 ; CHECK: @test2
7070
7171 declare i32 @doo(...)
7272
73 ; PR6627 - This should all be flattened down to one compare. This is the same
74 ; as test2, except that the initial load is done as an i8 instead of i32, thus
75 ; requiring widening.
76 define void @test2a(i8* %arrayidx) nounwind ssp {
77 entry:
78 %x1 = load i8* %arrayidx, align 4
79 %conv = zext i8 %x1 to i32
80 %cmp = icmp eq i32 %conv, 127
81 br i1 %cmp, label %land.lhs.true, label %if.end
82
83 land.lhs.true: ; preds = %entry
84 %arrayidx4 = getelementptr inbounds i8* %arrayidx, i64 1
85 %tmp5 = load i8* %arrayidx4, align 1
86 %conv6 = zext i8 %tmp5 to i32
87 %cmp7 = icmp eq i32 %conv6, 69
88 br i1 %cmp7, label %land.lhs.true9, label %if.end
89
90 land.lhs.true9: ; preds = %land.lhs.true
91 %arrayidx12 = getelementptr inbounds i8* %arrayidx, i64 2
92 %tmp13 = load i8* %arrayidx12, align 1
93 %conv14 = zext i8 %tmp13 to i32
94 %cmp15 = icmp eq i32 %conv14, 76
95 br i1 %cmp15, label %land.lhs.true17, label %if.end
96
97 land.lhs.true17: ; preds = %land.lhs.true9
98 %arrayidx20 = getelementptr inbounds i8* %arrayidx, i64 3
99 %tmp21 = load i8* %arrayidx20, align 1
100 %conv22 = zext i8 %tmp21 to i32
101 %cmp23 = icmp eq i32 %conv22, 70
102 br i1 %cmp23, label %if.then, label %if.end
103
104 if.then: ; preds = %land.lhs.true17
105 %call25 = call i32 (...)* @doo()
106 br label %if.end
107
108 if.end:
109 ret void
110
111 ; CHECK: @test2a
112 ; CHECK: %x1 = load i32* {{.*}}, align 4
113 ; CHECK-NEXT: icmp eq i32 %x1, 1179403647
114 ; CHECK-NEXT: br i1 {{.*}}, label %if.then, label %if.end
115 }
116