1; RUN: opt < %s -jump-threading -S | FileCheck %s 2; RUN: opt < %s -passes=jump-threading -S | FileCheck %s 3 4target 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" 5target triple = "i386-apple-darwin7" 6 7; Test that we can thread through the block with the partially redundant load (%2). 8; rdar://6402033 9define i32 @test1(i32* %P) nounwind { 10; CHECK-LABEL: @test1( 11entry: 12 %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1] 13 %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1] 14 br i1 %1, label %bb1, label %bb 15 16bb: ; preds = %entry 17; CHECK: bb1.thread: 18; CHECK: store 19; CHECK: br label %bb3 20 store i32 42, i32* %P, align 4 21 br label %bb1 22 23bb1: ; preds = %entry, %bb 24 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ] ; <i32> [#uses=2] 25 %2 = load i32, i32* %P, align 4 ; <i32> [#uses=1] 26 %3 = icmp sgt i32 %2, 36 ; <i1> [#uses=1] 27 br i1 %3, label %bb3, label %bb2 28 29bb2: ; preds = %bb1 30 %4 = tail call i32 (...) @f2() nounwind ; <i32> [#uses=0] 31 ret i32 %res.0 32 33bb3: ; preds = %bb1 34; CHECK: bb3: 35; CHECK: %res.01 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ] 36; CHECK: ret i32 %res.01 37 ret i32 %res.0 38} 39 40declare i32 @f1(...) 41 42declare i32 @f2(...) 43 44 45;; Check that we preserve TBAA information. 46; rdar://11039258 47 48define i32 @test2(i32* %P) nounwind { 49; CHECK-LABEL: @test2( 50entry: 51 %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1] 52 %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1] 53 br i1 %1, label %bb1, label %bb 54 55bb: ; preds = %entry 56; CHECK: bb1.thread: 57; CHECK: store{{.*}}, !tbaa !0 58; CHECK: br label %bb3 59 store i32 42, i32* %P, align 4, !tbaa !0 60 br label %bb1 61 62bb1: ; preds = %entry, %bb 63 %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ] 64 %2 = load i32, i32* %P, align 4, !tbaa !0 65 %3 = icmp sgt i32 %2, 36 66 br i1 %3, label %bb3, label %bb2 67 68bb2: ; preds = %bb1 69 %4 = tail call i32 (...) @f2() nounwind 70 ret i32 %res.0 71 72bb3: ; preds = %bb1 73; CHECK: bb3: 74; CHECK: %res.01 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ] 75; CHECK: ret i32 %res.01 76 ret i32 %res.0 77} 78 79define i32 @test3(i8** %x, i1 %f) { 80; Correctly thread loads of different (but compatible) types, placing bitcasts 81; as necessary in the predecessors. This is especially tricky because the same 82; predecessor ends up with two entries in the PHI node and they must share 83; a single cast. 84; CHECK-LABEL: @test3( 85entry: 86 %0 = bitcast i8** %x to i32** 87 %1 = load i32*, i32** %0, align 8 88 br i1 %f, label %if.end57, label %if.then56 89; CHECK: %[[LOAD:.*]] = load i32*, i32** 90; CHECK: %[[CAST:.*]] = bitcast i32* %[[LOAD]] to i8* 91 92if.then56: 93 br label %if.end57 94 95if.end57: 96 %2 = load i8*, i8** %x, align 8 97 %tobool59 = icmp eq i8* %2, null 98 br i1 %tobool59, label %return, label %if.then60 99; CHECK: %[[PHI:.*]] = phi i8* [ %[[CAST]], %[[PRED:[^ ]+]] ], [ %[[CAST]], %[[PRED]] ] 100; CHECK-NEXT: %[[CMP:.*]] = icmp eq i8* %[[PHI]], null 101; CHECK-NEXT: br i1 %[[CMP]] 102 103if.then60: 104 ret i32 42 105 106return: 107 ret i32 13 108} 109 110!0 = !{!3, !3, i64 0} 111!1 = !{!"omnipotent char", !2} 112!2 = !{!"Simple C/C++ TBAA", null} 113!3 = !{!"int", !1} 114