1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -gvn -S %s | FileCheck %s
3
4; Make sure GVN correctly sets the modified status when doing PRE.
5
6define i32 @test(i64 %v, i32* %ptr.1, i32** %ptr.2, i1 %c)  {
7; CHECK-LABEL: @test(
8; CHECK-NEXT:  entry:
9; CHECK-NEXT:    [[L_0:%.*]] = load i32, i32* [[PTR_1:%.*]], align 4
10; CHECK-NEXT:    br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
11; CHECK:       if.then:
12; CHECK-NEXT:    ret i32 10
13; CHECK:       if.end:
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:%.*]]
17; CHECK:       if.2.then:
18; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, i32* [[PTR_1]], i64 [[V:%.*]]
19; CHECK-NEXT:    [[L_2:%.*]] = load i32, i32* [[GEP_1]], align 4
20; CHECK-NEXT:    [[DOTPRE:%.*]] = zext i32 [[L_2]] to i64
21; CHECK-NEXT:    br label [[IF_2_END]]
22; CHECK:       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 i32*, i32** [[PTR_2:%.*]], align 8
26; CHECK-NEXT:    [[GEP_2:%.*]] = getelementptr inbounds i32, i32* [[PTR_1]], i64 [[REP_0_EXT_PRE_PHI]]
27; CHECK-NEXT:    [[L_4:%.*]] = load i32, i32* [[GEP_2]], align 4
28; CHECK-NEXT:    [[GEP_3:%.*]] = getelementptr inbounds i32, i32* [[L_3]], i64 10
29; CHECK-NEXT:    [[L_5:%.*]] = load i32, i32* [[GEP_3]], align 4
30; CHECK-NEXT:    [[R:%.*]] = add i32 [[L_4]], [[L_5]]
31; CHECK-NEXT:    ret i32 [[R]]
32;
33entry:
34  %l.0 = load i32, i32* %ptr.1, align 4
35  br i1 %c, label %if.then, label %if.end
36
37if.then:                                          ; preds = %entry
38  ret i32 10
39
40if.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
44
45if.2.then:                                         ; preds = %if.end
46  %gep.1 = getelementptr inbounds i32, i32* %ptr.1, i64 %v
47  %l.2 = load i32, i32* %gep.1, align 4
48  br label %if.2.end
49
50if.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 i32*, i32** %ptr.2, align 8
53  %rep.0.ext = zext i32 %rep.0 to i64
54  %gep.2 = getelementptr inbounds i32, i32* %ptr.1, i64 %rep.0.ext
55  %l.4 = load i32, i32* %gep.2, align 4
56  %gep.3 = getelementptr inbounds i32, i32* %l.3, i64 10
57  %l.5 = load i32, i32* %gep.3, align 4
58  %r = add i32 %l.4, %l.5
59  ret i32 %r
60}
61