1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=gvn -S %s | FileCheck %s
4 ; Make sure GVN correctly sets the modified status when doing PRE.
6 define i32 @test(i64 %v, ptr %ptr.1, ptr %ptr.2, i1 %c) {
9 ; CHECK-NEXT: [[L_0:%.*]] = load i32, ptr [[PTR_1:%.*]], align 4
10 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
12 ; CHECK-NEXT: ret i32 10
14 ; CHECK-NEXT: [[L_0_EXT:%.*]] = zext i32 [[L_0]] to i64
15 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i64 [[L_0_EXT]], 10
16 ; CHECK-NEXT: br i1 [[C_2]], label [[IF_2_END:%.*]], label [[IF_2_THEN:%.*]]
18 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[PTR_1]], i64 [[V:%.*]]
19 ; CHECK-NEXT: [[L_2:%.*]] = load i32, ptr [[GEP_1]], align 4
20 ; CHECK-NEXT: [[DOTPRE:%.*]] = zext i32 [[L_2]] to i64
21 ; CHECK-NEXT: br label [[IF_2_END]]
23 ; CHECK-NEXT: [[REP_0_EXT_PRE_PHI:%.*]] = phi i64 [ [[DOTPRE]], [[IF_2_THEN]] ], [ 10, [[IF_END]] ]
24 ; CHECK-NEXT: [[REP_0:%.*]] = phi i32 [ [[L_2]], [[IF_2_THEN]] ], [ [[L_0]], [[IF_END]] ]
25 ; CHECK-NEXT: [[L_3:%.*]] = load ptr, ptr [[PTR_2:%.*]], align 8
26 ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i32, ptr [[PTR_1]], i64 [[REP_0_EXT_PRE_PHI]]
27 ; CHECK-NEXT: [[L_4:%.*]] = load i32, ptr [[GEP_2]], align 4
28 ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr inbounds i32, ptr [[L_3]], i64 10
29 ; CHECK-NEXT: [[L_5:%.*]] = load i32, ptr [[GEP_3]], align 4
30 ; CHECK-NEXT: [[R:%.*]] = add i32 [[L_4]], [[L_5]]
31 ; CHECK-NEXT: ret i32 [[R]]
34 %l.0 = load i32, ptr %ptr.1, align 4
35 br i1 %c, label %if.then, label %if.end
37 if.then: ; preds = %entry
40 if.end: ; preds = %entry
41 %l.0.ext = zext i32 %l.0 to i64
42 %c.2 = icmp eq i64 %l.0.ext, 10
43 br i1 %c.2, label %if.2.end, label %if.2.then
45 if.2.then: ; preds = %if.end
46 %gep.1 = getelementptr inbounds i32, ptr %ptr.1, i64 %v
47 %l.2 = load i32, ptr %gep.1, align 4
50 if.2.end: ; preds = %if.then7, %if.end
51 %rep.0 = phi i32 [ %l.2, %if.2.then ], [ %l.0, %if.end ]
52 %l.3 = load ptr, ptr %ptr.2, align 8
53 %rep.0.ext = zext i32 %rep.0 to i64
54 %gep.2 = getelementptr inbounds i32, ptr %ptr.1, i64 %rep.0.ext
55 %l.4 = load i32, ptr %gep.2, align 4
56 %gep.3 = getelementptr inbounds i32, ptr %l.3, i64 10
57 %l.5 = load i32, ptr %gep.3, align 4
58 %r = add i32 %l.4, %l.5