1; RUN: opt -S -codegenprepare < %s | FileCheck %s 2; RUN: opt -S -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, i64 addrspace(1)* %base) { 12; CHECK-LABEL: @test_simple 13; CHECK-NOT: inttoptr {{.*}} to i64 addrspace(1)* 14entry: 15 %addr = getelementptr inbounds i64, i64 addrspace(1)* %base, i64 5 16 %casted = bitcast i64 addrspace(1)* %addr to i32 addrspace(1)* 17 br i1 %cond, label %if.then, label %fallthrough 18 19if.then: 20 %v = load i32, i32 addrspace(1)* %casted, align 4 21 br label %fallthrough 22 23fallthrough: 24 ret void 25} 26 27 28define void @test_inttoptr_base(i1 %cond, i64 %base) { 29; CHECK-LABEL: @test_inttoptr_base 30; CHECK-NOT: inttoptr {{.*}} to i64 addrspace(1)* 31entry: 32; Doing the inttoptr in the integral addrspace(0) followed by an explicit 33; (frontend-introduced) addrspacecast is fine. We cannot however introduce 34; a direct inttoptr to addrspace(1) 35 %baseptr = inttoptr i64 %base to i64* 36 %baseptrni = addrspacecast i64 *%baseptr to i64 addrspace(1)* 37 %addr = getelementptr inbounds i64, i64 addrspace(1)* %baseptrni, i64 5 38 %casted = bitcast i64 addrspace(1)* %addr to i32 addrspace(1)* 39 br i1 %cond, label %if.then, label %fallthrough 40 41if.then: 42 %v = load i32, i32 addrspace(1)* %casted, align 4 43 br label %fallthrough 44 45fallthrough: 46 ret void 47} 48 49define void @test_ptrtoint_base(i1 %cond, i64 addrspace(1)* %base) { 50; CHECK-LABEL: @test_ptrtoint_base 51; CHECK-NOT: ptrtoint addrspace(1)* {{.*}} to i64 52entry: 53; This one is inserted by the frontend, so it's fine. We're not allowed to 54; directly ptrtoint %base ourselves though 55 %baseptr0 = addrspacecast i64 addrspace(1)* %base to i64* 56 %toint = ptrtoint i64* %baseptr0 to i64 57 %added = add i64 %toint, 8 58 %toptr = inttoptr i64 %added to i64* 59 %geped = getelementptr i64, i64* %toptr, i64 2 60 br i1 %cond, label %if.then, label %fallthrough 61 62if.then: 63 %v = load i64, i64* %geped, align 4 64 br label %fallthrough 65 66fallthrough: 67 ret void 68} 69