1; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' < %s | FileCheck %s 2; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -addr-sink-using-gep=false < %s | FileCheck %s 3 4; This target data layout is modified to have a non-integral addrspace(1), 5; in order to verify that codegenprepare does not try to introduce illegal 6; inttoptrs. 7target datalayout = 8"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-ni:1" 9target triple = "x86_64-unknown-linux-gnu" 10 11define void @test_simple(i1 %cond, ptr addrspace(1) %base) { 12; CHECK-LABEL: @test_simple 13; CHECK-NOT: inttoptr {{.*}} to ptr addrspace(1) 14entry: 15 %addr = getelementptr inbounds i64, ptr addrspace(1) %base, i64 5 16 br i1 %cond, label %if.then, label %fallthrough 17 18if.then: 19 %v = load i32, ptr addrspace(1) %addr, align 4 20 br label %fallthrough 21 22fallthrough: 23 ret void 24} 25 26 27define void @test_inttoptr_base(i1 %cond, i64 %base) { 28; CHECK-LABEL: @test_inttoptr_base 29; CHECK-NOT: inttoptr {{.*}} to ptr addrspace(1) 30entry: 31; Doing the inttoptr in the integral addrspace(0) followed by an explicit 32; (frontend-introduced) addrspacecast is fine. We cannot however introduce 33; a direct inttoptr to addrspace(1) 34 %baseptr = inttoptr i64 %base to ptr 35 %baseptrni = addrspacecast ptr %baseptr to ptr addrspace(1) 36 %addr = getelementptr inbounds i64, ptr addrspace(1) %baseptrni, i64 5 37 br i1 %cond, label %if.then, label %fallthrough 38 39if.then: 40 %v = load i32, ptr addrspace(1) %addr, align 4 41 br label %fallthrough 42 43fallthrough: 44 ret void 45} 46 47define void @test_ptrtoint_base(i1 %cond, ptr addrspace(1) %base) { 48; CHECK-LABEL: @test_ptrtoint_base 49; CHECK-NOT: ptrtoint addrspace(1)* {{.*}} to i64 50entry: 51; This one is inserted by the frontend, so it's fine. We're not allowed to 52; directly ptrtoint %base ourselves though 53 %baseptr0 = addrspacecast ptr addrspace(1) %base to ptr 54 %toint = ptrtoint ptr %baseptr0 to i64 55 %added = add i64 %toint, 8 56 %toptr = inttoptr i64 %added to ptr 57 %geped = getelementptr i64, ptr %toptr, i64 2 58 br i1 %cond, label %if.then, label %fallthrough 59 60if.then: 61 %v = load i64, ptr %geped, align 4 62 br label %fallthrough 63 64fallthrough: 65 ret void 66} 67