156 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=instcombine %s -S | FileCheck %s3 4@block = global [64 x [8192 x i8]] zeroinitializer, align 15 6define <2 x ptr> @vectorindex1() {7; CHECK-LABEL: @vectorindex1(8; CHECK-NEXT: ret <2 x ptr> getelementptr inbounds ([64 x [8192 x i8]], ptr @block, <2 x i64> zeroinitializer, <2 x i64> <i64 0, i64 1>, <2 x i64> splat (i64 8192))9;10 %1 = getelementptr inbounds [64 x [8192 x i8]], ptr @block, i64 0, <2 x i64> <i64 0, i64 1>, i64 819211 ret <2 x ptr> %112}13 14define <2 x ptr> @vectorindex2() {15; CHECK-LABEL: @vectorindex2(16; CHECK-NEXT: ret <2 x ptr> getelementptr inbounds ([64 x [8192 x i8]], ptr @block, <2 x i64> zeroinitializer, <2 x i64> splat (i64 1), <2 x i64> <i64 8191, i64 8193>)17;18 %1 = getelementptr inbounds [64 x [8192 x i8]], ptr @block, i64 0, i64 1, <2 x i64> <i64 8191, i64 8193>19 ret <2 x ptr> %120}21 22define <2 x ptr> @vectorindex3() {23; CHECK-LABEL: @vectorindex3(24; CHECK-NEXT: ret <2 x ptr> getelementptr inbounds ([64 x [8192 x i8]], ptr @block, <2 x i64> zeroinitializer, <2 x i64> <i64 0, i64 1>, <2 x i64> <i64 8191, i64 8193>)25;26 %1 = getelementptr inbounds [64 x [8192 x i8]], ptr @block, i64 0, <2 x i64> <i64 0, i64 1>, <2 x i64> <i64 8191, i64 8193>27 ret <2 x ptr> %128}29 30; Negative test - datalayout's alloc size for the 2 types must match.31 32define ptr @bitcast_vec_to_array_gep(ptr %x, i64 %y, i64 %z) {33; CHECK-LABEL: @bitcast_vec_to_array_gep(34; CHECK-NEXT: [[GEP:%.*]] = getelementptr [7 x i32], ptr [[GEP_SPLIT:%.*]], i64 [[Z:%.*]]35; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[GEP]], i64 [[Z1:%.*]]36; CHECK-NEXT: ret ptr [[GEP1]]37;38 %gep = getelementptr [7 x i32], ptr %x, i64 %y, i64 %z39 ret ptr %gep40}41 42; Negative test - datalayout's alloc size for the 2 types must match.43 44define ptr @bitcast_array_to_vec_gep(ptr %x, i64 %y, i64 %z) {45; CHECK-LABEL: @bitcast_array_to_vec_gep(46; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds <3 x i32>, ptr [[GEP_SPLIT:%.*]], i64 [[Z:%.*]]47; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[GEP]], i64 [[Z1:%.*]]48; CHECK-NEXT: ret ptr [[GEP1]]49;50 %gep = getelementptr inbounds <3 x i32>, ptr %x, i64 %y, i64 %z51 ret ptr %gep52}53 54; Sizes and types match - safe to remove bitcast.55 56define ptr @bitcast_vec_to_array_gep_matching_alloc_size(ptr %x, i64 %y, i64 %z) {57; CHECK-LABEL: @bitcast_vec_to_array_gep_matching_alloc_size(58; CHECK-NEXT: [[GEP:%.*]] = getelementptr [4 x i32], ptr [[GEP_SPLIT:%.*]], i64 [[Z:%.*]]59; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[GEP]], i64 [[Z1:%.*]]60; CHECK-NEXT: ret ptr [[GEP1]]61;62 %gep = getelementptr [4 x i32], ptr %x, i64 %y, i64 %z63 ret ptr %gep64}65 66; Sizes and types match - safe to remove bitcast.67 68define ptr @bitcast_array_to_vec_gep_matching_alloc_size(ptr %x, i64 %y, i64 %z) {69; CHECK-LABEL: @bitcast_array_to_vec_gep_matching_alloc_size(70; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds <4 x i32>, ptr [[GEP_SPLIT:%.*]], i64 [[Z:%.*]]71; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i32, ptr [[GEP]], i64 [[Z1:%.*]]72; CHECK-NEXT: ret ptr [[GEP1]]73;74 %gep = getelementptr inbounds <4 x i32>, ptr %x, i64 %y, i64 %z75 ret ptr %gep76}77 78; Negative test - datalayout's alloc size for the 2 types must match.79 80define ptr addrspace(3) @bitcast_vec_to_array_addrspace(ptr %x, i64 %y, i64 %z) {81; CHECK-LABEL: @bitcast_vec_to_array_addrspace(82; CHECK-NEXT: [[ASC:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(3)83; CHECK-NEXT: [[GEP_SPLIT:%.*]] = getelementptr [7 x i32], ptr addrspace(3) [[ASC]], i64 [[Y:%.*]]84; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr addrspace(3) [[GEP_SPLIT]], i64 [[Z:%.*]]85; CHECK-NEXT: ret ptr addrspace(3) [[GEP]]86;87 %asc = addrspacecast ptr %x to ptr addrspace(3)88 %gep = getelementptr [7 x i32], ptr addrspace(3) %asc, i64 %y, i64 %z89 ret ptr addrspace(3) %gep90}91 92; Negative test - datalayout's alloc size for the 2 types must match.93 94define ptr addrspace(3) @inbounds_bitcast_vec_to_array_addrspace(ptr %x, i64 %y, i64 %z) {95; CHECK-LABEL: @inbounds_bitcast_vec_to_array_addrspace(96; CHECK-NEXT: [[ASC:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(3)97; CHECK-NEXT: [[GEP_SPLIT:%.*]] = getelementptr inbounds [7 x i32], ptr addrspace(3) [[ASC]], i64 [[Y:%.*]]98; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr addrspace(3) [[GEP_SPLIT]], i64 [[Z:%.*]]99; CHECK-NEXT: ret ptr addrspace(3) [[GEP]]100;101 %asc = addrspacecast ptr %x to ptr addrspace(3)102 %gep = getelementptr inbounds [7 x i32], ptr addrspace(3) %asc, i64 %y, i64 %z103 ret ptr addrspace(3) %gep104}105 106; Sizes and types match - safe to remove bitcast.107 108define ptr addrspace(3) @bitcast_vec_to_array_addrspace_matching_alloc_size(ptr %x, i64 %y, i64 %z) {109; CHECK-LABEL: @bitcast_vec_to_array_addrspace_matching_alloc_size(110; CHECK-NEXT: [[ASC:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(3)111; CHECK-NEXT: [[GEP_SPLIT:%.*]] = getelementptr [4 x i32], ptr addrspace(3) [[ASC]], i64 [[Y:%.*]]112; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr addrspace(3) [[GEP_SPLIT]], i64 [[Z:%.*]]113; CHECK-NEXT: ret ptr addrspace(3) [[GEP]]114;115 %asc = addrspacecast ptr %x to ptr addrspace(3)116 %gep = getelementptr [4 x i32], ptr addrspace(3) %asc, i64 %y, i64 %z117 ret ptr addrspace(3) %gep118}119 120; Sizes and types match - safe to remove bitcast.121 122define ptr addrspace(3) @inbounds_bitcast_vec_to_array_addrspace_matching_alloc_size(ptr %x, i64 %y, i64 %z) {123; CHECK-LABEL: @inbounds_bitcast_vec_to_array_addrspace_matching_alloc_size(124; CHECK-NEXT: [[ASC:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(3)125; CHECK-NEXT: [[GEP_SPLIT:%.*]] = getelementptr inbounds [4 x i32], ptr addrspace(3) [[ASC]], i64 [[Y:%.*]]126; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr addrspace(3) [[GEP_SPLIT]], i64 [[Z:%.*]]127; CHECK-NEXT: ret ptr addrspace(3) [[GEP]]128;129 %asc = addrspacecast ptr %x to ptr addrspace(3)130 %gep = getelementptr inbounds [4 x i32], ptr addrspace(3) %asc, i64 %y, i64 %z131 ret ptr addrspace(3) %gep132}133 134; Negative test - avoid doing bitcast on ptr, because '16' should be scaled by 'vscale'.135 136define ptr @test_accumulate_constant_offset_vscale_nonzero(<vscale x 16 x i1> %pg, ptr %base) {137; CHECK-LABEL: @test_accumulate_constant_offset_vscale_nonzero(138; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()139; CHECK-NEXT: [[TMP2:%.*]] = shl nuw i64 [[TMP1]], 4140; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[TMP2]]141; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[TMP3]], i64 4142; CHECK-NEXT: ret ptr [[GEP]]143;144 %gep = getelementptr <vscale x 16 x i8>, ptr %base, i64 1, i64 4145 ret ptr %gep146}147 148define ptr @test_accumulate_constant_offset_vscale_zero(<vscale x 16 x i1> %pg, ptr %base) {149; CHECK-LABEL: @test_accumulate_constant_offset_vscale_zero(150; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 4151; CHECK-NEXT: ret ptr [[GEP]]152;153 %gep = getelementptr <vscale x 16 x i8>, ptr %base, i64 0, i64 4154 ret ptr %gep155}156