1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=gvn -S | FileCheck %s 3 4; GVN should eliminate the fully redundant %9 GEP which 5; allows DEAD to be removed. This is PR3198. 6 7; The %7 and %4 loads combine to make %DEAD unneeded. 8target 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" 9target triple = "i386-apple-darwin7" 10@H = common global [100 x i32] zeroinitializer, align 32 ; <ptr> [#uses=3] 11@G = common global i32 0 ; <ptr> [#uses=2] 12 13define i32 @test(i32 %i) nounwind { 14; CHECK-LABEL: @test( 15; CHECK-NEXT: entry: 16; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 (...) @foo() #[[ATTR0:[0-9]+]] 17; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 0 18; CHECK-NEXT: br i1 [[TMP1]], label [[BB1:%.*]], label [[BB:%.*]] 19; CHECK: bb: 20; CHECK-NEXT: [[TMP2:%.*]] = tail call i32 (...) @bar() #[[ATTR0]] 21; CHECK-NEXT: [[TMP3:%.*]] = getelementptr [100 x i32], ptr @H, i32 0, i32 [[I:%.*]] 22; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[TMP3]], align 4 23; CHECK-NEXT: store i32 [[TMP4]], ptr @G, align 4 24; CHECK-NEXT: br label [[BB3:%.*]] 25; CHECK: bb1: 26; CHECK-NEXT: [[TMP5:%.*]] = tail call i32 (...) @baz() #[[ATTR0]] 27; CHECK-NEXT: [[TMP6:%.*]] = getelementptr [100 x i32], ptr @H, i32 0, i32 [[I]] 28; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[TMP6]], align 4 29; CHECK-NEXT: store i32 [[TMP7]], ptr @G, align 4 30; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[TMP7]], 0 31; CHECK-NEXT: br i1 [[TMP8]], label [[BB3]], label [[BB4:%.*]] 32; CHECK: bb3: 33; CHECK-NEXT: [[DEAD:%.*]] = phi i32 [ 0, [[BB1]] ], [ [[TMP4]], [[BB]] ] 34; CHECK-NEXT: [[TMP9:%.*]] = getelementptr [100 x i32], ptr @H, i32 0, i32 [[I]] 35; CHECK-NEXT: ret i32 [[DEAD]] 36; CHECK: bb4: 37; CHECK-NEXT: ret i32 0 38; 39entry: 40 %0 = tail call i32 (...) @foo() nounwind ; <i32> [#uses=1] 41 %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1] 42 br i1 %1, label %bb1, label %bb 43 44bb: ; preds = %entry 45 %2 = tail call i32 (...) @bar() nounwind ; <i32> [#uses=0] 46 %3 = getelementptr [100 x i32], ptr @H, i32 0, i32 %i ; <ptr> [#uses=1] 47 %4 = load i32, ptr %3, align 4 ; <i32> [#uses=1] 48 store i32 %4, ptr @G, align 4 49 br label %bb3 50 51bb1: ; preds = %entry 52 %5 = tail call i32 (...) @baz() nounwind ; <i32> [#uses=0] 53 %6 = getelementptr [100 x i32], ptr @H, i32 0, i32 %i ; <ptr> [#uses=1] 54 %7 = load i32, ptr %6, align 4 ; <i32> [#uses=2] 55 store i32 %7, ptr @G, align 4 56 %8 = icmp eq i32 %7, 0 ; <i1> [#uses=1] 57 br i1 %8, label %bb3, label %bb4 58 59bb3: ; preds = %bb1, %bb 60 %9 = getelementptr [100 x i32], ptr @H, i32 0, i32 %i ; <ptr> [#uses=1] 61 %DEAD = load i32, ptr %9, align 4 ; <i32> [#uses=1] 62 ret i32 %DEAD 63 64bb4: ; preds = %bb1 65 ret i32 0 66} 67 68declare i32 @foo(...) 69 70declare i32 @bar(...) 71 72declare i32 @baz(...) 73