; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -instcombine < %s | FileCheck %s ; This test is used to verify we are not crashing at Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!". define @gep_index_type_is_scalable(i8* %p) { ; CHECK-LABEL: @gep_index_type_is_scalable( ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* [[P:%.*]], undef ; CHECK-NEXT: ret [[GEP]] ; %gep = getelementptr i8, i8* %p, undef ret %gep } ; This test serves to verify code changes for "GEP.getNumIndices() == 1". define * @gep_num_of_indices_1(* %p) { ; CHECK-LABEL: @gep_num_of_indices_1( ; CHECK-NEXT: [[GEP:%.*]] = getelementptr , * [[P:%.*]], i64 1 ; CHECK-NEXT: ret * [[GEP]] ; %gep = getelementptr , * %p, i64 1 ret * %gep } ; This test serves to verify code changes for "GEP.getNumOperands() == 2". define void @gep_bitcast(i8* %p) { ; CHECK-LABEL: @gep_bitcast( ; CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[P:%.*]] to * ; CHECK-NEXT: store zeroinitializer, * [[CAST]], align 16 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr , * [[CAST]], i64 1 ; CHECK-NEXT: store zeroinitializer, * [[GEP2]], align 16 ; CHECK-NEXT: ret void ; %cast = bitcast i8* %p to * %gep1 = getelementptr , * %cast, i64 0 store zeroinitializer, * %gep1 %gep2 = getelementptr , * %cast, i64 1 store zeroinitializer, * %gep2 ret void } ; These tests serve to verify code changes when underlying gep ptr is alloca. ; This test is to verify 'inbounds' is added when it's valid to accumulate constant offset. define i32 @gep_alloca_inbounds_vscale_zero() { ; CHECK-LABEL: @gep_alloca_inbounds_vscale_zero( ; CHECK-NEXT: [[A:%.*]] = alloca , align 16 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds , * [[A]], i64 0, i64 2 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[TMP]], align 8 ; CHECK-NEXT: ret i32 [[LOAD]] ; %a = alloca %tmp = getelementptr , * %a, i32 0, i32 2 %load = load i32, i32* %tmp ret i32 %load } ; This test is to verify 'inbounds' is not added when a constant offset can not be determined at compile-time. define i32 @gep_alloca_inbounds_vscale_nonzero() { ; CHECK-LABEL: @gep_alloca_inbounds_vscale_nonzero( ; CHECK-NEXT: [[A:%.*]] = alloca , align 16 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr , * [[A]], i64 1, i64 2 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[TMP]], align 8 ; CHECK-NEXT: ret i32 [[LOAD]] ; %a = alloca %tmp = getelementptr , * %a, i32 1, i32 2 %load = load i32, i32* %tmp ret i32 %load }