1 ; RUN: opt -S -mtriple=nvptx64-nvidia-cuda -infer-address-spaces %s | FileCheck %s
3 %struct.S = type { [5 x i32] }
7 @g1 = linkonce_odr addrspace(3) global %struct.S zeroinitializer, comdat, align 4
10 ; CHECK: %x0 = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x() #2
11 ; CHECK: %idxprom.i = zext i32 %x0 to i64
12 ; CHECK: %arrayidx.i = getelementptr %struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 %idxprom.i
13 ; CHECK: tail call void @f1(i32* %arrayidx.i, i32 undef) #0
14 ; CHECK: %x1 = load i32, i32 addrspace(3)* getelementptr inbounds (%struct.S, %struct.S addrspace(3)* @g1, i64 0, i32 0, i64 0), align 4
15 ; CHECK: %L.sroa.0.0.insert.ext.i = zext i32 %x1 to i64
16 ; CHECK: tail call void @f2(i64* null, i64 %L.sroa.0.0.insert.ext.i) #0
18 define void @foo() local_unnamed_addr #0 {
20 %x0 = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x() #2
21 %idxprom.i = zext i32 %x0 to i64
22 %arrayidx.i = getelementptr %struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 %idxprom.i
23 tail call void @f1(i32* %arrayidx.i, i32 undef) #0
24 %x1 = load i32, i32* getelementptr (%struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 0), align 4
25 %L.sroa.0.0.insert.ext.i = zext i32 %x1 to i64
26 tail call void @f2(i64* null, i64 %L.sroa.0.0.insert.ext.i) #0
30 declare void @f1(i32*, i32) local_unnamed_addr #0
31 declare void @f2(i64*, i64) local_unnamed_addr #0
32 declare i32 @llvm.nvvm.read.ptx.sreg.tid.x() #1
34 ; Make sure we can clone GEP which uses complex constant expressions as indices.
35 ; https://bugs.llvm.org/show_bug.cgi?id=51099
36 @g2 = internal addrspace(3) global [128 x i8] undef, align 1
38 ; CHECK-LABEL: @complex_ce(
39 ; CHECK: %0 = load float, float addrspace(3)* bitcast
40 ; CHECK-SAME: i8 addrspace(3)* getelementptr (i8,
41 ; CHECK-SAME: i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 0, i64 0),
42 ; CHECK-SAME: i64 sub (
43 ; CHECK-SAME i64 ptrtoint (
44 ; CHECK-SAME i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 0, i64 123) to i64),
45 ; CHECK-SAME: i64 ptrtoint (
46 ; CHECK-SAME: i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 2, i64 0) to i64)))
47 ; CHECK-SAME: to float addrspace(3)*)
48 ; Function Attrs: norecurse nounwind
49 define float @complex_ce(i8* nocapture readnone %a, i8* nocapture readnone %b, i8* nocapture readnone %c) local_unnamed_addr #0 {
51 %0 = load float, float* bitcast (
53 i8, i8* getelementptr inbounds (
55 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*),
60 i8* getelementptr inbounds (
62 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*),
67 i8* getelementptr inbounds (
69 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*),
79 attributes #0 = { convergent nounwind }
80 attributes #1 = { nounwind readnone }
81 attributes #2 = { nounwind }