1 ; RUN: opt < %s -gvn -S | FileCheck %s 2 3 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" 4 target triple = "i386-apple-darwin7" 5 6 define i32 @test1(i32* %b, i32* %c) nounwind { 7 ; CHECK: @test1 8 entry: 9 %g = alloca i32 10 %t1 = icmp eq i32* %b, null 11 br i1 %t1, label %bb, label %bb1 12 13 bb: 14 %t2 = load i32* %c, align 4 15 %t3 = add i32 %t2, 1 16 store i32 %t3, i32* %g, align 4 17 br label %bb2 18 19 bb1: ; preds = %entry 20 %t5 = load i32* %b, align 4 21 %t6 = add i32 %t5, 1 22 store i32 %t6, i32* %g, align 4 23 br label %bb2 24 25 bb2: ; preds = %bb1, %bb 26 %c_addr.0 = phi i32* [ %g, %bb1 ], [ %c, %bb ] 27 %b_addr.0 = phi i32* [ %b, %bb1 ], [ %g, %bb ] 28 %cv = load i32* %c_addr.0, align 4 29 %bv = load i32* %b_addr.0, align 4 30 ; CHECK: %bv = phi i32 31 ; CHECK: %cv = phi i32 32 ; CHECK-NOT: load 33 ; CHECK: ret i32 34 %ret = add i32 %cv, %bv 35 ret i32 %ret 36 } 37 38 define i8 @test2(i1 %cond, i32* %b, i32* %c) nounwind { 39 ; CHECK: @test2 40 entry: 41 br i1 %cond, label %bb, label %bb1 42 43 bb: 44 %b1 = bitcast i32* %b to i8* 45 store i8 4, i8* %b1 46 br label %bb2 47 48 bb1: 49 %c1 = bitcast i32* %c to i8* 50 store i8 92, i8* %c1 51 br label %bb2 52 53 bb2: 54 %d = phi i32* [ %c, %bb1 ], [ %b, %bb ] 55 %d1 = bitcast i32* %d to i8* 56 %dv = load i8* %d1 57 ; CHECK: %dv = phi i8 [ 92, %bb1 ], [ 4, %bb ] 58 ; CHECK-NOT: load 59 ; CHECK: ret i8 %dv 60 ret i8 %dv 61 } 62 63 define i32 @test3(i1 %cond, i32* %b, i32* %c) nounwind { 64 ; CHECK: @test3 65 entry: 66 br i1 %cond, label %bb, label %bb1 67 68 bb: 69 %b1 = getelementptr i32* %b, i32 17 70 store i32 4, i32* %b1 71 br label %bb2 72 73 bb1: 74 %c1 = getelementptr i32* %c, i32 7 75 store i32 82, i32* %c1 76 br label %bb2 77 78 bb2: 79 %d = phi i32* [ %c, %bb1 ], [ %b, %bb ] 80 %i = phi i32 [ 7, %bb1 ], [ 17, %bb ] 81 %d1 = getelementptr i32* %d, i32 %i 82 %dv = load i32* %d1 83 ; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ] 84 ; CHECK-NOT: load 85 ; CHECK: ret i32 %dv 86 ret i32 %dv 87 } 88 89 ; PR5313 90 define i32 @test4(i1 %cond, i32* %b, i32* %c) nounwind { 91 ; CHECK: @test4 92 entry: 93 br i1 %cond, label %bb, label %bb1 94 95 bb: 96 store i32 4, i32* %b 97 br label %bb2 98 99 bb1: 100 %c1 = getelementptr i32* %c, i32 7 101 store i32 82, i32* %c1 102 br label %bb2 103 104 bb2: 105 %d = phi i32* [ %c, %bb1 ], [ %b, %bb ] 106 %i = phi i32 [ 7, %bb1 ], [ 0, %bb ] 107 %d1 = getelementptr i32* %d, i32 %i 108 %dv = load i32* %d1 109 ; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ] 110 ; CHECK-NOT: load 111 ; CHECK: ret i32 %dv 112 ret i32 %dv 113 } 114 115 116 117 ; void test5(int N, double* G) { 118 ; for (long j = 1; j < 1000; j++) 119 ; G[j] = G[j] + G[j-1]; 120 ; } 121 ; 122 ; Should compile into one load in the loop. 123 define void @test5(i32 %N, double* nocapture %G) nounwind ssp { 124 ; CHECK: @test5 125 bb.nph: 126 br label %for.body 127 128 for.body: 129 %indvar = phi i64 [ 0, %bb.nph ], [ %tmp, %for.body ] 130 %arrayidx6 = getelementptr double* %G, i64 %indvar 131 %tmp = add i64 %indvar, 1 132 %arrayidx = getelementptr double* %G, i64 %tmp 133 %tmp3 = load double* %arrayidx 134 %tmp7 = load double* %arrayidx6 135 %add = fadd double %tmp3, %tmp7 136 store double %add, double* %arrayidx 137 %exitcond = icmp eq i64 %tmp, 999 138 br i1 %exitcond, label %for.end, label %for.body 139 ; CHECK: for.body: 140 ; CHECK: phi double 141 ; CHECK: load double 142 ; CHECK-NOT: load double 143 ; CHECK: br i1 144 for.end: 145 ret void 146 } 147