; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instsimplify -S -verify | FileCheck %s ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Vector Operations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; insertelement define @insertelement_idx_undef( %a) { ; CHECK-LABEL: @insertelement_idx_undef( ; CHECK-NEXT: ret undef ; %r = insertelement %a, i32 5, i64 undef ret %r } define @insertelement_value_undef( %a) { ; CHECK-LABEL: @insertelement_value_undef( ; CHECK-NEXT: [[R:%.*]] = insertelement [[A:%.*]], i32 undef, i64 0 ; CHECK-NEXT: ret [[R]] ; %r = insertelement %a, i32 undef, i64 0 ret %r } define @insertelement_idx_maybe_out_of_bound( %a) { ; CHECK-LABEL: @insertelement_idx_maybe_out_of_bound( ; CHECK-NEXT: [[R:%.*]] = insertelement [[A:%.*]], i32 5, i64 4 ; CHECK-NEXT: ret [[R]] ; %r = insertelement %a, i32 5, i64 4 ret %r } define @insertelement_idx_large_bound( %a) { ; CHECK-LABEL: @insertelement_idx_large_bound( ; CHECK-NEXT: [[R:%.*]] = insertelement [[A:%.*]], i32 5, i64 12345 ; CHECK-NEXT: ret [[R]] ; %r = insertelement %a, i32 5, i64 12345 ret %r } define @insert_extract_element_same_vec_idx_1( %a) { ; CHECK-LABEL: @insert_extract_element_same_vec_idx_1( ; CHECK-NEXT: ret [[A:%.*]] ; %v = extractelement %a, i64 1 %r = insertelement %a, i32 %v, i64 1 ret %r } define @insertelement_inline_to_ret() { ; CHECK-LABEL: @insertelement_inline_to_ret( ; CHECK-NEXT: ret insertelement ( undef, i32 1, i32 0) ; %i = insertelement undef, i32 1, i32 0 ret %i } define @insertelement_shufflevector_inline_to_ret() { ; CHECK-LABEL: @insertelement_shufflevector_inline_to_ret( ; CHECK-NEXT: ret shufflevector ( insertelement ( undef, i32 1, i32 0), undef, zeroinitializer) ; %i = insertelement undef, i32 1, i32 0 %i2 = shufflevector %i, undef, zeroinitializer ret %i2 } ; extractelement define i32 @extractelement_idx_undef( %a) { ; CHECK-LABEL: @extractelement_idx_undef( ; CHECK-NEXT: ret i32 undef ; %r = extractelement %a, i64 undef ret i32 %r } define i32 @extractelement_vec_undef( %a) { ; CHECK-LABEL: @extractelement_vec_undef( ; CHECK-NEXT: ret i32 undef ; %r = extractelement undef, i64 1 ret i32 %r } define i32 @extractelement_idx_maybe_out_of_bound( %a) { ; CHECK-LABEL: @extractelement_idx_maybe_out_of_bound( ; CHECK-NEXT: [[R:%.*]] = extractelement [[A:%.*]], i64 4 ; CHECK-NEXT: ret i32 [[R]] ; %r = extractelement %a, i64 4 ret i32 %r } define i32 @extractelement_idx_large_bound( %a) { ; CHECK-LABEL: @extractelement_idx_large_bound( ; CHECK-NEXT: [[R:%.*]] = extractelement [[A:%.*]], i64 12345 ; CHECK-NEXT: ret i32 [[R]] ; %r = extractelement %a, i64 12345 ret i32 %r } define i32 @insert_extract_element_same_vec_idx_2() { ; CHECK-LABEL: @insert_extract_element_same_vec_idx_2( ; CHECK-NEXT: ret i32 1 ; %v = insertelement undef, i32 1, i64 4 %r = extractelement %v, i64 4 ret i32 %r } define i32 @insert_extract_element_same_vec_idx_3() { ; CHECK-LABEL: @insert_extract_element_same_vec_idx_3( ; CHECK-NEXT: ret i32 1 ; %r = extractelement insertelement ( undef, i32 1, i64 4), i64 4 ret i32 %r } define i32 @insert_extract_element_same_vec_idx_4() { ; CHECK-LABEL: @insert_extract_element_same_vec_idx_4( ; CHECK-NEXT: ret i32 1 ; %r = extractelement insertelement ( insertelement ( undef, i32 1, i32 4), i32 2, i64 3), i64 4 ret i32 %r } ; more complicated expressions define @cmp_le_smax_always_true( %x) { ; CHECK-LABEL: @cmp_le_smax_always_true( ; CHECK-NEXT: ret shufflevector ( insertelement ( undef, i1 true, i32 0), undef, zeroinitializer) %cmp = icmp sle %x, shufflevector ( insertelement ( undef, i64 9223372036854775807, i32 0), undef, zeroinitializer) ret %cmp } define @bitcast() { ; CHECK-LABEL: @bitcast( ; CHECK-NEXT: ret bitcast ( shufflevector ( insertelement ( undef, i32 1, i32 0), undef, zeroinitializer) to ) ; %i1 = insertelement undef, i32 1, i32 0 %i2 = shufflevector %i1, undef, zeroinitializer %i3 = bitcast %i2 to ret %i3 } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Memory Access and Addressing Operations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; getelementptr define @getelementptr_constant_foldable_1() { ; CHECK-LABEL: @getelementptr_constant_foldable_1( ; CHECK-NEXT: ret zeroinitializer ; %ptr = getelementptr i32, zeroinitializer, undef ret %ptr } define *> @getelementptr_constant_foldable_2() { ; CHECK-LABEL: @getelementptr_constant_foldable_2( ; CHECK-NEXT: ret *> zeroinitializer ; %ptr = getelementptr , * null, undef ret *> %ptr } ; fold getelementptr P, 0 -> P. define * @getelementptr_constant_foldable_3() { ; CHECK-LABEL: @getelementptr_constant_foldable_3( ; CHECK-NEXT: ret * null ; %ptr = getelementptr , * null, i64 0 ret * %ptr } define * @getelementptr_not_constant_foldable(i64 %x) { ; CHECK-LABEL: @getelementptr_not_constant_foldable( ; CHECK-NEXT: [[PTR:%.*]] = getelementptr , * null, i64 [[X:%.*]] ; CHECK-NEXT: ret * [[PTR]] ; %ptr = getelementptr , * null, i64 %x ret * %ptr } ; Check GEP's result is known to be non-null. define i1 @getelementptr_check_non_null(* %ptr) { ; CHECK-LABEL: @getelementptr_check_non_null( ; CHECK-NEXT: ret i1 false ; %x = getelementptr inbounds , * %ptr, i32 1 %cmp = icmp eq * %x, null ret i1 %cmp }