133b939c3SRoman Lebedev; RUN: opt -S -passes=consthoist < %s | FileCheck %s 2cee313d2SEric Christopher 3cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 4cee313d2SEric Christophertarget triple = "x86_64-apple-macosx10.9.0" 5cee313d2SEric Christopher 6cee313d2SEric Christopher; PR18626 7*055fb779SNikita Popovdefine ptr @test1(i1 %cmp, ptr %tmp) { 8cee313d2SEric Christopherentry: 9*055fb779SNikita Popov call void @foo(ptr inttoptr (i64 68719476735 to ptr)) 10cee313d2SEric Christopher br i1 %cmp, label %if.end, label %return 11cee313d2SEric Christopher 12cee313d2SEric Christopherif.end: ; preds = %bb1 13*055fb779SNikita Popov call void @foo(ptr inttoptr (i64 68719476736 to ptr)) 14cee313d2SEric Christopher br label %return 15cee313d2SEric Christopher 16cee313d2SEric Christopherreturn: 17*055fb779SNikita Popov %retval.0 = phi ptr [ null, %entry ], [ inttoptr (i64 68719476736 to ptr), %if.end ] 18*055fb779SNikita Popov store i64 1172321806, ptr %tmp 19*055fb779SNikita Popov ret ptr %retval.0 20cee313d2SEric Christopher 21cee313d2SEric Christopher; CHECK-LABEL: @test1 22cee313d2SEric Christopher; CHECK: if.end: 23*055fb779SNikita Popov; CHECK: %2 = inttoptr i64 %const to ptr 24cee313d2SEric Christopher; CHECK-NEXT: br 25cee313d2SEric Christopher; CHECK: return: 26*055fb779SNikita Popov; CHECK-NEXT: %retval.0 = phi ptr [ null, %entry ], [ %2, %if.end ] 27cee313d2SEric Christopher} 28cee313d2SEric Christopher 29*055fb779SNikita Popovdefine void @test2(i1 %cmp, ptr %tmp) { 30cee313d2SEric Christopherentry: 31*055fb779SNikita Popov call void @foo(ptr inttoptr (i64 68719476736 to ptr)) 32cee313d2SEric Christopher br i1 %cmp, label %if.end, label %return 33cee313d2SEric Christopher 34cee313d2SEric Christopherif.end: ; preds = %bb1 35*055fb779SNikita Popov call void @foo(ptr inttoptr (i64 68719476736 to ptr)) 36cee313d2SEric Christopher br label %return 37cee313d2SEric Christopher 38cee313d2SEric Christopherreturn: 39*055fb779SNikita Popov store ptr inttoptr (i64 68719476735 to ptr), ptr %tmp 40cee313d2SEric Christopher ret void 41cee313d2SEric Christopher 42cee313d2SEric Christopher; CHECK-LABEL: @test2 43cee313d2SEric Christopher; CHECK: return: 44cee313d2SEric Christopher; CHECK-NEXT: %const_mat = add i64 %const, -1 45*055fb779SNikita Popov; CHECK-NEXT: inttoptr i64 %const_mat to ptr 46cee313d2SEric Christopher} 47cee313d2SEric Christopher 48*055fb779SNikita Popovdeclare void @foo(ptr) 49cee313d2SEric Christopher 50cee313d2SEric Christopher; PR18768 51cee313d2SEric Christopherdefine i32 @test3(i1 %c) { 52cee313d2SEric Christopherentry: 53cee313d2SEric Christopher br i1 %c, label %if.then, label %if.end3 54cee313d2SEric Christopher 55cee313d2SEric Christopherif.then: ; preds = %entry 56cee313d2SEric Christopher br label %if.end3 57cee313d2SEric Christopher 58cee313d2SEric Christopherif.end3: ; preds = %if.then, %entry 59*055fb779SNikita Popov %d.0 = phi ptr [ inttoptr (i64 985162435264511 to ptr), %entry ], [ null, %if.then ] 60*055fb779SNikita Popov %cmp4 = icmp eq ptr %d.0, inttoptr (i64 985162435264511 to ptr) 61*055fb779SNikita Popov %cmp6 = icmp eq ptr %d.0, inttoptr (i64 985162418487296 to ptr) 62cee313d2SEric Christopher %or = or i1 %cmp4, %cmp6 63cee313d2SEric Christopher br i1 %or, label %if.then8, label %if.end9 64cee313d2SEric Christopher 65cee313d2SEric Christopherif.then8: ; preds = %if.end3 66cee313d2SEric Christopher ret i32 1 67cee313d2SEric Christopher 68cee313d2SEric Christopherif.end9: ; preds = %if.then8, %if.end3 69cee313d2SEric Christopher ret i32 undef 70cee313d2SEric Christopher} 71cee313d2SEric Christopher 72cee313d2SEric Christopher; <rdar://problem/16394449> 73cee313d2SEric Christopherdefine i64 @switch_test1(i64 %a) { 74cee313d2SEric Christopher; CHECK-LABEL: @switch_test1 75cee313d2SEric Christopher; CHECK: %0 = phi i64 [ %const, %case2 ], [ %const_mat, %Entry ], [ %const_mat, %Entry ] 76cee313d2SEric ChristopherEntry: 77cee313d2SEric Christopher %sel = add i64 %a, 4519019440 78cee313d2SEric Christopher switch i64 %sel, label %fail [ 79cee313d2SEric Christopher i64 462, label %continuation 80cee313d2SEric Christopher i64 449, label %case2 81cee313d2SEric Christopher i64 443, label %continuation 82cee313d2SEric Christopher ] 83cee313d2SEric Christopher 84cee313d2SEric Christophercase2: 85cee313d2SEric Christopher br label %continuation 86cee313d2SEric Christopher 87cee313d2SEric Christophercontinuation: 88cee313d2SEric Christopher %0 = phi i64 [ 4519019440, %case2 ], [ 4519019460, %Entry ], [ 4519019460, %Entry ] 89cee313d2SEric Christopher ret i64 0; 90cee313d2SEric Christopher 91cee313d2SEric Christopherfail: 92cee313d2SEric Christopher ret i64 -1; 93cee313d2SEric Christopher} 94cee313d2SEric Christopher 95cee313d2SEric Christopherdefine i64 @switch_test2(i64 %a) { 96cee313d2SEric Christopher; CHECK-LABEL: @switch_test2 97*055fb779SNikita Popov; CHECK: %2 = phi ptr [ %1, %case2 ], [ %0, %Entry ], [ %0, %Entry ] 98cee313d2SEric ChristopherEntry: 99cee313d2SEric Christopher %sel = add i64 %a, 4519019440 100cee313d2SEric Christopher switch i64 %sel, label %fail [ 101cee313d2SEric Christopher i64 462, label %continuation 102cee313d2SEric Christopher i64 449, label %case2 103cee313d2SEric Christopher i64 443, label %continuation 104cee313d2SEric Christopher ] 105cee313d2SEric Christopher 106cee313d2SEric Christophercase2: 107cee313d2SEric Christopher br label %continuation 108cee313d2SEric Christopher 109cee313d2SEric Christophercontinuation: 110*055fb779SNikita Popov %0 = phi ptr [ inttoptr(i64 4519019440 to ptr), %case2 ], [ inttoptr(i64 4519019460 to ptr), %Entry ], [ inttoptr(i64 4519019460 to ptr), %Entry ] 111cee313d2SEric Christopher ret i64 0; 112cee313d2SEric Christopher 113cee313d2SEric Christopherfail: 114cee313d2SEric Christopher ret i64 -1; 115cee313d2SEric Christopher} 116cee313d2SEric Christopher 117