1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4target datalayout = "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-n8:16:32:64" 5target triple = "x86_64-pc-win32" 6 7%myStruct = type { float, [3 x float], [4 x float], i32 } 8 9; make sure that we are not crashing when creating an illegal type 10define void @func(%myStruct addrspace(1)* nocapture %p) nounwind { 11; CHECK-LABEL: @func( 12; CHECK-NEXT: ret void 13; 14 %A = getelementptr inbounds %myStruct, %myStruct addrspace(1)* %p, i64 0 15 %B = addrspacecast %myStruct addrspace(1)* %A to %myStruct* 16 %C = getelementptr inbounds %myStruct, %myStruct* %B, i32 0, i32 1 17 %D = getelementptr inbounds [3 x float], [3 x float]* %C, i32 0, i32 2 18 %E = load float, float* %D, align 4 19 %F = fsub float %E, undef 20 ret void 21} 22 23@array = internal addrspace(3) global [256 x float] zeroinitializer, align 4 24@scalar = internal addrspace(3) global float 0.000000e+00, align 4 25 26define void @keep_necessary_addrspacecast(i64 %i, float** %out0, float** %out1) { 27; CHECK-LABEL: @keep_necessary_addrspacecast( 28; CHECK-NEXT: [[T01:%.*]] = getelementptr [256 x float], [256 x float] addrspace(3)* @array, i64 0, i64 [[I:%.*]] 29; CHECK-NEXT: [[T0:%.*]] = addrspacecast float addrspace(3)* [[T01]] to float* 30; CHECK-NEXT: [[TMP1:%.*]] = getelementptr float, float addrspace(3)* @scalar, i64 [[I]] 31; CHECK-NEXT: [[T1:%.*]] = addrspacecast float addrspace(3)* [[TMP1]] to float* 32; CHECK-NEXT: store float* [[T0]], float** [[OUT0:%.*]], align 4 33; CHECK-NEXT: store float* [[T1]], float** [[OUT1:%.*]], align 4 34; CHECK-NEXT: ret void 35; 36 %t0 = getelementptr [256 x float], [256 x float]* addrspacecast ([256 x float] addrspace(3)* @array to [256 x float]*), i64 0, i64 %i 37 %t1 = getelementptr [0 x float], [0 x float]* addrspacecast (float addrspace(3)* @scalar to [0 x float]*), i64 0, i64 %i 38 store float* %t0, float** %out0, align 4 39 store float* %t1, float** %out1, align 4 40 ret void 41} 42 43declare void @escape_alloca(i16*) 44 45; check that addrspacecast is not ignored (leading to an assertion failure) 46; when trying to mark a GEP as inbounds 47define { i8, i8 } @inbounds_after_addrspacecast() { 48; CHECK-LABEL: @inbounds_after_addrspacecast( 49; CHECK-NEXT: [[T0:%.*]] = alloca i16, align 2 50; CHECK-NEXT: call void @escape_alloca(i16* nonnull [[T0]]) 51; CHECK-NEXT: [[TMPCAST:%.*]] = bitcast i16* [[T0]] to [2 x i8]* 52; CHECK-NEXT: [[T1:%.*]] = addrspacecast [2 x i8]* [[TMPCAST]] to [2 x i8] addrspace(11)* 53; CHECK-NEXT: [[T2:%.*]] = getelementptr [2 x i8], [2 x i8] addrspace(11)* [[T1]], i64 0, i64 1 54; CHECK-NEXT: [[T3:%.*]] = load i8, i8 addrspace(11)* [[T2]], align 1 55; CHECK-NEXT: [[INSERT:%.*]] = insertvalue { i8, i8 } zeroinitializer, i8 [[T3]], 1 56; CHECK-NEXT: ret { i8, i8 } [[INSERT]] 57; 58 %t0 = alloca i16, align 2 59 call void @escape_alloca(i16* %t0) 60 %tmpcast = bitcast i16* %t0 to [2 x i8]* 61 %t1 = addrspacecast [2 x i8]* %tmpcast to [2 x i8] addrspace(11)* 62 %t2 = getelementptr [2 x i8], [2 x i8] addrspace(11)* %t1, i64 0, i64 1 63 %t3 = load i8, i8 addrspace(11)* %t2, align 1 64 %insert = insertvalue { i8, i8 } zeroinitializer, i8 %t3, 1 65 ret { i8, i8 } %insert 66} 67 68 69declare spir_func <16 x i32> @my_extern_func() 70 71; check that a bitcast is not generated when we need an addrspace cast 72define void @bitcast_after_gep(<16 x i32>* %t0) { 73; CHECK-LABEL: @bitcast_after_gep( 74; CHECK-NEXT: [[T4:%.*]] = addrspacecast <16 x i32>* [[T0:%.*]] to <16 x i32> addrspace(3)* 75; CHECK-NEXT: [[CALL:%.*]] = call spir_func <16 x i32> @my_extern_func() 76; CHECK-NEXT: store <16 x i32> [[CALL]], <16 x i32> addrspace(3)* [[T4]], align 64 77; CHECK-NEXT: ret void 78; 79 %t1 = bitcast <16 x i32>* %t0 to [16 x i32]* 80 %t2 = addrspacecast [16 x i32]* %t1 to [16 x i32] addrspace(3)* 81 %t3 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %t2, i64 0, i64 0 82 %t4 = bitcast i32 addrspace(3)* %t3 to <16 x i32> addrspace(3)* 83 %call = call spir_func <16 x i32> @my_extern_func() 84 store <16 x i32> %call, <16 x i32> addrspace(3)* %t4 85 ret void 86} 87