1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -mtriple=nvptx64-nvidia-cuda -infer-address-spaces %s | FileCheck %s 3 4%struct.S = type { [5 x i32] } 5 6$g1 = comdat any 7 8@g1 = linkonce_odr addrspace(3) global %struct.S zeroinitializer, comdat, align 4 9 10define void @foo() local_unnamed_addr #0 { 11; CHECK-LABEL: @foo( 12; CHECK-NEXT: entry: 13; CHECK-NEXT: [[X0:%.*]] = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x() #[[ATTR2:[0-9]+]] 14; CHECK-NEXT: [[IDXPROM_I:%.*]] = zext i32 [[X0]] to i64 15; CHECK-NEXT: [[ARRAYIDX_I:%.*]] = getelementptr [[STRUCT_S:%.*]], %struct.S* addrspacecast ([[STRUCT_S]] addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 [[IDXPROM_I]] 16; CHECK-NEXT: tail call void @f1(i32* [[ARRAYIDX_I]], i32 undef) #[[ATTR0:[0-9]+]] 17; CHECK-NEXT: [[X1:%.*]] = load i32, i32 addrspace(3)* getelementptr inbounds ([[STRUCT_S]], [[STRUCT_S]] addrspace(3)* @g1, i64 0, i32 0, i64 0), align 4 18; CHECK-NEXT: [[L_SROA_0_0_INSERT_EXT_I:%.*]] = zext i32 [[X1]] to i64 19; CHECK-NEXT: tail call void @f2(i64* null, i64 [[L_SROA_0_0_INSERT_EXT_I]]) #[[ATTR0]] 20; CHECK-NEXT: ret void 21; 22entry: 23 %x0 = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x() #2 24 %idxprom.i = zext i32 %x0 to i64 25 %arrayidx.i = getelementptr %struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 %idxprom.i 26 tail call void @f1(i32* %arrayidx.i, i32 undef) #0 27 %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 28 %L.sroa.0.0.insert.ext.i = zext i32 %x1 to i64 29 tail call void @f2(i64* null, i64 %L.sroa.0.0.insert.ext.i) #0 30 ret void 31} 32 33declare void @f1(i32*, i32) local_unnamed_addr #0 34declare void @f2(i64*, i64) local_unnamed_addr #0 35declare i32 @llvm.nvvm.read.ptx.sreg.tid.x() #1 36 37; Make sure we can clone GEP which uses complex constant expressions as indices. 38; https://bugs.llvm.org/show_bug.cgi?id=51099 39@g2 = internal addrspace(3) global [128 x i8] undef, align 1 40 41define float @complex_ce(i8* nocapture readnone %a, i8* nocapture readnone %b, i8* nocapture readnone %c) local_unnamed_addr #0 { 42; CHECK-LABEL: @complex_ce( 43; CHECK-NEXT: entry: 44; CHECK-NEXT: [[TMP0:%.*]] = load float, float addrspace(3)* bitcast (i8 addrspace(3)* getelementptr (i8, i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 0, i64 0), i64 sub (i64 ptrtoint (i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 0, i64 123) to i64), i64 ptrtoint (i8 addrspace(3)* getelementptr inbounds ([128 x i8], [128 x i8] addrspace(3)* @g2, i64 2, i64 0) to i64))) to float addrspace(3)*), align 4 45; CHECK-NEXT: ret float [[TMP0]] 46; 47entry: 48 %0 = load float, float* bitcast ( 49 i8* getelementptr ( 50 i8, i8* getelementptr inbounds ( 51 [128 x i8], 52 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*), 53 i64 0, 54 i64 0), 55 i64 sub ( 56 i64 ptrtoint ( 57 i8* getelementptr inbounds ( 58 [128 x i8], 59 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*), 60 i64 0, 61 i64 123) 62 to i64), 63 i64 ptrtoint ( 64 i8* getelementptr inbounds ( 65 [128 x i8], 66 [128 x i8]* addrspacecast ([128 x i8] addrspace(3)* @g2 to [128 x i8]*), 67 i64 2, 68 i64 0) 69 to i64))) 70 to float*), align 4 71 ret float %0 72} 73 74 75 76attributes #0 = { convergent nounwind } 77attributes #1 = { nounwind readnone } 78attributes #2 = { nounwind } 79