1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3 4define <2 x float> @vtrn1(<2 x i32> %v) 5; CHECK-LABEL: @vtrn1( 6; CHECK-NEXT: entry: 7; CHECK-NEXT: [[TMP0:%.*]] = bitcast <2 x i32> [[V:%.*]] to <2 x float> 8; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[TMP0]], <2 x float> poison, <2 x i32> zeroinitializer 9; CHECK-NEXT: ret <2 x float> [[R]] 10; 11{ 12entry: 13 %vb1 = bitcast <2 x i32> %v to <2 x float> 14 %vb2 = bitcast <2 x i32> %v to <2 x float> 15 %r = shufflevector <2 x float> %vb1, <2 x float> %vb2, <2 x i32> <i32 0, i32 2> 16 ret <2 x float> %r 17} 18 19define <2 x float> @vtrn2(<2 x i32> %x, <2 x i32> %y) { 20; CHECK-LABEL: @vtrn2( 21; CHECK-NEXT: entry: 22; CHECK-NEXT: [[R_UNCASTED:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> <i32 1, i32 3> 23; CHECK-NEXT: [[R:%.*]] = bitcast <2 x i32> [[R_UNCASTED]] to <2 x float> 24; CHECK-NEXT: ret <2 x float> [[R]] 25; 26entry: 27 %xb = bitcast <2 x i32> %x to <2 x float> 28 %yb = bitcast <2 x i32> %y to <2 x float> 29 %r = shufflevector <2 x float> %xb, <2 x float> %yb, <2 x i32> <i32 1, i32 3> 30 ret <2 x float> %r 31} 32 33 34define <4 x float> @bc_shuf_lenchange(<2 x i32> %x, <2 x i32> %y) { 35; CHECK-LABEL: @bc_shuf_lenchange( 36; CHECK-NEXT: [[R_UNCASTED:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <4 x i32> <i32 3, i32 2, i32 1, i32 0> 37; CHECK-NEXT: [[R:%.*]] = bitcast <4 x i32> [[R_UNCASTED]] to <4 x float> 38; CHECK-NEXT: ret <4 x float> [[R]] 39; 40 %xb = bitcast <2 x i32> %x to <2 x float> 41 %yb = bitcast <2 x i32> %y to <2 x float> 42 %r = shufflevector <2 x float> %xb, <2 x float> %yb, <4 x i32> <i32 3, i32 2, i32 1, i32 0> 43 ret <4 x float> %r 44} 45 46 47define <4 x float> @bc_shuf_nonvec(i64 %x, i64 %y) { 48; CHECK-LABEL: @bc_shuf_nonvec( 49; CHECK-NEXT: [[XB:%.*]] = bitcast i64 [[X:%.*]] to <2 x float> 50; CHECK-NEXT: [[YB:%.*]] = bitcast i64 [[Y:%.*]] to <2 x float> 51; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[XB]], <2 x float> [[YB]], <4 x i32> <i32 3, i32 2, i32 1, i32 0> 52; CHECK-NEXT: ret <4 x float> [[R]] 53; 54 %xb = bitcast i64 %x to <2 x float> 55 %yb = bitcast i64 %y to <2 x float> 56 %r = shufflevector <2 x float> %xb, <2 x float> %yb, <4 x i32> <i32 3, i32 2, i32 1, i32 0> 57 ret <4 x float> %r 58} 59 60define <4 x double> @bc_shuf_size(<4 x i32> %x, <4 x i32> %y) { 61; CHECK-LABEL: @bc_shuf_size( 62; CHECK-NEXT: [[XB:%.*]] = bitcast <4 x i32> [[X:%.*]] to <2 x double> 63; CHECK-NEXT: [[YB:%.*]] = bitcast <4 x i32> [[Y:%.*]] to <2 x double> 64; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x double> [[XB]], <2 x double> [[YB]], <4 x i32> <i32 1, i32 3, i32 0, i32 2> 65; CHECK-NEXT: ret <4 x double> [[R]] 66; 67 %xb = bitcast <4 x i32> %x to <2 x double> 68 %yb = bitcast <4 x i32> %y to <2 x double> 69 %r = shufflevector <2 x double> %xb, <2 x double> %yb, <4 x i32> <i32 1, i32 3, i32 0, i32 2> 70 ret <4 x double> %r 71} 72 73define <2 x double> @bc_shuf_mismatch(<4 x i32> %x, <2 x i64> %y) { 74; CHECK-LABEL: @bc_shuf_mismatch( 75; CHECK-NEXT: [[XB:%.*]] = bitcast <4 x i32> [[X:%.*]] to <2 x double> 76; CHECK-NEXT: [[YB:%.*]] = bitcast <2 x i64> [[Y:%.*]] to <2 x double> 77; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x double> [[XB]], <2 x double> [[YB]], <2 x i32> <i32 1, i32 3> 78; CHECK-NEXT: ret <2 x double> [[R]] 79; 80 %xb = bitcast <4 x i32> %x to <2 x double> 81 %yb = bitcast <2 x i64> %y to <2 x double> 82 %r = shufflevector <2 x double> %xb, <2 x double> %yb, <2 x i32> <i32 1, i32 3> 83 ret <2 x double> %r 84} 85 86define <8 x half> @bc_shuf_i8_float(<8 x i8> %x, <8 x i8> %y) { 87; CHECK-LABEL: @bc_shuf_i8_float( 88; CHECK-NEXT: [[XB:%.*]] = bitcast <8 x i8> [[X:%.*]] to <4 x half> 89; CHECK-NEXT: [[YB:%.*]] = bitcast <8 x i8> [[Y:%.*]] to <4 x half> 90; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x half> [[XB]], <4 x half> [[YB]], <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4> 91; CHECK-NEXT: ret <8 x half> [[R]] 92; 93 %xb = bitcast <8 x i8> %x to <4 x half> 94 %yb = bitcast <8 x i8> %y to <4 x half> 95 %r = shufflevector <4 x half> %xb, <4 x half> %yb, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 7, i32 6, i32 5, i32 4> 96 ret <8 x half> %r 97} 98 99define <4 x i16> @bc_shuf_elemtype_mismatch(<2 x half> %x, <2 x bfloat> %y) { 100; CHECK-LABEL: @bc_shuf_elemtype_mismatch( 101; CHECK-NEXT: [[XB:%.*]] = bitcast <2 x half> [[X:%.*]] to <2 x i16> 102; CHECK-NEXT: [[YB:%.*]] = bitcast <2 x bfloat> [[Y:%.*]] to <2 x i16> 103; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i16> [[XB]], <2 x i16> [[YB]], <4 x i32> <i32 3, i32 2, i32 1, i32 0> 104; CHECK-NEXT: ret <4 x i16> [[R]] 105; 106 %xb = bitcast <2 x half> %x to <2 x i16> 107 %yb = bitcast <2 x bfloat> %y to <2 x i16> 108 %r = shufflevector <2 x i16> %xb, <2 x i16> %yb, <4 x i32> <i32 3, i32 2, i32 1, i32 0> 109 ret <4 x i16> %r 110} 111 112define <2 x float> @bc_shuf_reuse(<4 x i32> %x){ 113; CHECK-LABEL: @bc_shuf_reuse( 114; CHECK-NEXT: [[XB:%.*]] = bitcast <4 x i32> [[X:%.*]] to <4 x float> 115; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[XB]], <4 x float> poison, <2 x i32> zeroinitializer 116; CHECK-NEXT: ret <2 x float> [[R]] 117; 118 %xb = bitcast <4 x i32> %x to <4 x float> 119 %r = shufflevector <4 x float> %xb, <4 x float> %xb, <2 x i32> <i32 0, i32 4> 120 ret <2 x float> %r 121} 122 123define <4 x float> @bc_shuf_y_hasoneuse(<4 x i32> %x, <4 x i32> %y){ 124; CHECK-LABEL: @bc_shuf_y_hasoneuse( 125; CHECK-NEXT: [[XB:%.*]] = bitcast <4 x i32> [[X:%.*]] to <4 x float> 126; CHECK-NEXT: [[SHUF_UNCASTED:%.*]] = shufflevector <4 x i32> [[X]], <4 x i32> [[Y:%.*]], <4 x i32> <i32 0, i32 1, i32 4, i32 5> 127; CHECK-NEXT: [[SHUF:%.*]] = bitcast <4 x i32> [[SHUF_UNCASTED]] to <4 x float> 128; CHECK-NEXT: [[R:%.*]] = fadd <4 x float> [[XB]], [[SHUF]] 129; CHECK-NEXT: ret <4 x float> [[R]] 130; 131 %xb = bitcast <4 x i32> %x to <4 x float> 132 %yb = bitcast <4 x i32> %y to <4 x float> 133 %shuf = shufflevector <4 x float> %xb, <4 x float> %yb, <4 x i32> <i32 0, i32 1, i32 4, i32 5> 134 %r = fadd <4 x float> %xb, %shuf 135 ret <4 x float> %r 136} 137 138define <4 x float> @bc_shuf_neither_hasoneuse(<4 x i32> %x, <4 x i32> %y){ 139; CHECK-LABEL: @bc_shuf_neither_hasoneuse( 140; CHECK-NEXT: [[XB:%.*]] = bitcast <4 x i32> [[X:%.*]] to <4 x float> 141; CHECK-NEXT: [[YB:%.*]] = bitcast <4 x i32> [[Y:%.*]] to <4 x float> 142; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x float> [[XB]], <4 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1> 143; CHECK-NEXT: [[SUM:%.*]] = fadd <4 x float> [[XB]], [[YB]] 144; CHECK-NEXT: [[R:%.*]] = fadd <4 x float> [[SUM]], [[SHUF]] 145; CHECK-NEXT: ret <4 x float> [[R]] 146; 147 %xb = bitcast <4 x i32> %x to <4 x float> 148 %yb = bitcast <4 x i32> %y to <4 x float> 149 %shuf = shufflevector <4 x float> %xb, <4 x float> %xb, <4 x i32> <i32 0, i32 1, i32 4, i32 5> 150 %sum = fadd <4 x float> %xb, %yb 151 %r = fadd <4 x float> %sum, %shuf 152 ret <4 x float> %r 153} 154