1; RUN: opt -S -gvn -enable-load-pre < %s | FileCheck %s 2; 3; Make sure the load in bb3.backedge is removed and moved into bb1 after the 4; call. This makes the non-call case faster. 5; 6; This test is derived from this C++ code (GCC PR 37810): 7; void g(); 8; struct A { 9; int n; int m; 10; A& operator++(void) { ++n; if (n == m) g(); return *this; } 11; A() : n(0), m(0) { } 12; friend bool operator!=(A const& a1, A const& a2) { return a1.n != a2.n; } 13; }; 14; void testfunction(A& iter) { A const end; while (iter != end) ++iter; } 15; 16target 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" 17target triple = "i386-apple-darwin7" 18 %struct.A = type { i32, i32 } 19 20define void @_Z12testfunctionR1A(%struct.A* %iter) { 21entry: 22 %0 = getelementptr %struct.A, %struct.A* %iter, i32 0, i32 0 ; <i32*> [#uses=3] 23 %1 = load i32, i32* %0, align 4 ; <i32> [#uses=2] 24 %2 = icmp eq i32 %1, 0 ; <i1> [#uses=1] 25 br i1 %2, label %return, label %bb.nph 26 27bb.nph: ; preds = %entry 28 %3 = getelementptr %struct.A, %struct.A* %iter, i32 0, i32 1 ; <i32*> [#uses=1] 29 br label %bb 30 31bb: ; preds = %bb3.backedge, %bb.nph 32 %.rle = phi i32 [ %1, %bb.nph ], [ %7, %bb3.backedge ] ; <i32> [#uses=1] 33 %4 = add i32 %.rle, 1 ; <i32> [#uses=2] 34 store i32 %4, i32* %0, align 4 35 %5 = load i32, i32* %3, align 4 ; <i32> [#uses=1] 36 %6 = icmp eq i32 %4, %5 ; <i1> [#uses=1] 37 br i1 %6, label %bb1, label %bb3.backedge 38 39bb1: ; preds = %bb 40 tail call void @_Z1gv() 41 br label %bb3.backedge 42 43bb3.backedge: ; preds = %bb, %bb1 44; CHECK: bb3.backedge: 45; CHECK-NEXT: phi 46; CHECK-NEXT: icmp 47 %7 = load i32, i32* %0, align 4 ; <i32> [#uses=2] 48 %8 = icmp eq i32 %7, 0 ; <i1> [#uses=1] 49 br i1 %8, label %return, label %bb 50 51return: ; preds = %bb3.backedge, %entry 52 ret void 53} 54 55declare void @_Z1gv() 56