1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -gvn -enable-load-pre < %s | FileCheck %s
4 ; Make sure the load in bb3.backedge is removed and moved into bb1 after the
5 ; call. This makes the non-call case faster.
7 ; This test is derived from this C++ code (GCC PR 37810):
11 ; A& operator++(void) { ++n; if (n == m) g(); return *this; }
12 ; A() : n(0), m(0) { }
13 ; friend bool operator!=(A const& a1, A const& a2) { return a1.n != a2.n; }
15 ; void testfunction(A& iter) { A const end; while (iter != end) ++iter; }
17 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"
18 target triple = "i386-apple-darwin7"
19 %struct.A = type { i32, i32 }
21 define void @_Z12testfunctionR1A(%struct.A* %iter) {
22 ; CHECK-LABEL: @_Z12testfunctionR1A(
24 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr [[STRUCT_A:%.*]], %struct.A* [[ITER:%.*]], i32 0, i32 0
25 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
26 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
27 ; CHECK-NEXT: br i1 [[TMP2]], label [[RETURN:%.*]], label [[BB_NPH:%.*]]
29 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr [[STRUCT_A]], %struct.A* [[ITER]], i32 0, i32 1
30 ; CHECK-NEXT: br label [[BB:%.*]]
32 ; CHECK-NEXT: [[DOTRLE:%.*]] = phi i32 [ [[TMP1]], [[BB_NPH]] ], [ [[TMP7:%.*]], [[BB3_BACKEDGE:%.*]] ]
33 ; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[DOTRLE]], 1
34 ; CHECK-NEXT: store i32 [[TMP4]], i32* [[TMP0]], align 4
35 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[TMP3]], align 4
36 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i32 [[TMP4]], [[TMP5]]
37 ; CHECK-NEXT: br i1 [[TMP6]], label [[BB1:%.*]], label [[BB3_BACKEDGE]]
39 ; CHECK-NEXT: tail call void @_Z1gv()
40 ; CHECK-NEXT: [[DOTPRE:%.*]] = load i32, i32* [[TMP0]], align 4
41 ; CHECK-NEXT: br label [[BB3_BACKEDGE]]
42 ; CHECK: bb3.backedge:
43 ; CHECK-NEXT: [[TMP7]] = phi i32 [ [[DOTPRE]], [[BB1]] ], [ [[TMP4]], [[BB]] ]
44 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[TMP7]], 0
45 ; CHECK-NEXT: br i1 [[TMP8]], label [[RETURN]], label [[BB]]
47 ; CHECK-NEXT: ret void
50 %0 = getelementptr %struct.A, %struct.A* %iter, i32 0, i32 0 ; <i32*> [#uses=3]
51 %1 = load i32, i32* %0, align 4 ; <i32> [#uses=2]
52 %2 = icmp eq i32 %1, 0 ; <i1> [#uses=1]
53 br i1 %2, label %return, label %bb.nph
55 bb.nph: ; preds = %entry
56 %3 = getelementptr %struct.A, %struct.A* %iter, i32 0, i32 1 ; <i32*> [#uses=1]
59 bb: ; preds = %bb3.backedge, %bb.nph
60 %.rle = phi i32 [ %1, %bb.nph ], [ %7, %bb3.backedge ] ; <i32> [#uses=1]
61 %4 = add i32 %.rle, 1 ; <i32> [#uses=2]
62 store i32 %4, i32* %0, align 4
63 %5 = load i32, i32* %3, align 4 ; <i32> [#uses=1]
64 %6 = icmp eq i32 %4, %5 ; <i1> [#uses=1]
65 br i1 %6, label %bb1, label %bb3.backedge
68 tail call void @_Z1gv()
69 br label %bb3.backedge
71 bb3.backedge: ; preds = %bb, %bb1
72 %7 = load i32, i32* %0, align 4 ; <i32> [#uses=2]
73 %8 = icmp eq i32 %7, 0 ; <i1> [#uses=1]
74 br i1 %8, label %return, label %bb
76 return: ; preds = %bb3.backedge, %entry