1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3 4define <4 x i32> @insert_known_idx(<4 x i32> %x) { 5; CHECK-LABEL: @insert_known_idx( 6; CHECK-NEXT: [[V1:%.*]] = and <4 x i32> [[X:%.*]], <i32 poison, i32 7, i32 7, i32 7> 7; CHECK-NEXT: [[V2:%.*]] = insertelement <4 x i32> [[V1]], i32 6, i64 0 8; CHECK-NEXT: ret <4 x i32> [[V2]] 9; 10 %v1 = and <4 x i32> %x, <i32 7, i32 7, i32 7, i32 7> 11 %v2 = insertelement <4 x i32> %v1, i32 6, i32 0 12 %v3 = and <4 x i32> %v2, <i32 7, i32 7, i32 7, i32 7> 13 ret <4 x i32> %v3 14} 15 16define <4 x i32> @insert_unknown_idx(<4 x i32> %x, i32 %idx) { 17; CHECK-LABEL: @insert_unknown_idx( 18; CHECK-NEXT: [[V1:%.*]] = and <4 x i32> [[X:%.*]], splat (i32 7) 19; CHECK-NEXT: [[V2:%.*]] = insertelement <4 x i32> [[V1]], i32 6, i32 [[IDX:%.*]] 20; CHECK-NEXT: ret <4 x i32> [[V2]] 21; 22 %v1 = and <4 x i32> %x, <i32 7, i32 7, i32 7, i32 7> 23 %v2 = insertelement <4 x i32> %v1, i32 6, i32 %idx 24 %v3 = and <4 x i32> %v2, <i32 7, i32 7, i32 7, i32 7> 25 ret <4 x i32> %v3 26} 27 28define <2 x i8> @insert_known_any_idx(<2 x i8> %xx, i8 %yy, i32 %idx) { 29; CHECK-LABEL: @insert_known_any_idx( 30; CHECK-NEXT: ret <2 x i8> splat (i8 16) 31; 32 %x = or <2 x i8> %xx, <i8 16, i8 16> 33 %y = or i8 %yy, 16 34 35 %ins = insertelement <2 x i8> %x, i8 %y, i32 %idx 36 %r = and <2 x i8> %ins, <i8 16, i8 16> 37 ret <2 x i8> %r 38} 39 40define <2 x i8> @insert_known_any_idx_fail1(<2 x i8> %xx, i8 %yy, i32 %idx) { 41; CHECK-LABEL: @insert_known_any_idx_fail1( 42; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 17, i8 33> 43; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], 16 44; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i8> [[X]], i8 [[Y]], i32 [[IDX:%.*]] 45; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[INS]], splat (i8 16) 46; CHECK-NEXT: ret <2 x i8> [[R]] 47; 48 %x = or <2 x i8> %xx, <i8 17, i8 33> 49 %y = or i8 %yy, 16 50 51 %ins = insertelement <2 x i8> %x, i8 %y, i32 %idx 52 %r = and <2 x i8> %ins, <i8 16, i8 16> 53 ret <2 x i8> %r 54} 55 56 57define <2 x i8> @insert_known_any_idx_fail2(<2 x i8> %xx, i8 %yy, i32 %idx) { 58; CHECK-LABEL: @insert_known_any_idx_fail2( 59; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 17, i8 31> 60; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], 15 61; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i8> [[X]], i8 [[Y]], i32 [[IDX:%.*]] 62; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[INS]], splat (i8 16) 63; CHECK-NEXT: ret <2 x i8> [[R]] 64; 65 %x = or <2 x i8> %xx, <i8 17, i8 31> 66 %y = or i8 %yy, 15 67 68 %ins = insertelement <2 x i8> %x, i8 %y, i32 %idx 69 %r = and <2 x i8> %ins, <i8 16, i8 16> 70 ret <2 x i8> %r 71} 72 73