1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4define double @a(<1 x i64> %y) { 5; CHECK-LABEL: @a( 6; CHECK-NEXT: [[BC:%.*]] = bitcast <1 x i64> [[Y:%.*]] to <1 x double> 7; CHECK-NEXT: [[C:%.*]] = extractelement <1 x double> [[BC]], i32 0 8; CHECK-NEXT: ret double [[C]] 9; 10 %c = bitcast <1 x i64> %y to double 11 ret double %c 12} 13 14define i64 @b(<1 x i64> %y) { 15; CHECK-LABEL: @b( 16; CHECK-NEXT: [[TMP1:%.*]] = extractelement <1 x i64> [[Y:%.*]], i32 0 17; CHECK-NEXT: ret i64 [[TMP1]] 18; 19 %c = bitcast <1 x i64> %y to i64 20 ret i64 %c 21} 22 23define <1 x i64> @c(double %y) { 24; CHECK-LABEL: @c( 25; CHECK-NEXT: [[C:%.*]] = bitcast double [[Y:%.*]] to <1 x i64> 26; CHECK-NEXT: ret <1 x i64> [[C]] 27; 28 %c = bitcast double %y to <1 x i64> 29 ret <1 x i64> %c 30} 31 32define <1 x i64> @d(i64 %y) { 33; CHECK-LABEL: @d( 34; CHECK-NEXT: [[C:%.*]] = insertelement <1 x i64> undef, i64 [[Y:%.*]], i32 0 35; CHECK-NEXT: ret <1 x i64> [[C]] 36; 37 %c = bitcast i64 %y to <1 x i64> 38 ret <1 x i64> %c 39} 40 41define x86_mmx @e(<1 x i64> %y) { 42; CHECK-LABEL: @e( 43; CHECK-NEXT: [[TMP1:%.*]] = extractelement <1 x i64> [[Y:%.*]], i32 0 44; CHECK-NEXT: [[C:%.*]] = bitcast i64 [[TMP1]] to x86_mmx 45; CHECK-NEXT: ret x86_mmx [[C]] 46; 47 %c = bitcast <1 x i64> %y to x86_mmx 48 ret x86_mmx %c 49} 50 51define <1 x i64> @f(x86_mmx %y) { 52; CHECK-LABEL: @f( 53; CHECK-NEXT: [[TMP1:%.*]] = bitcast x86_mmx [[Y:%.*]] to i64 54; CHECK-NEXT: [[C:%.*]] = insertelement <1 x i64> undef, i64 [[TMP1]], i32 0 55; CHECK-NEXT: ret <1 x i64> [[C]] 56; 57 %c = bitcast x86_mmx %y to <1 x i64> 58 ret <1 x i64> %c 59} 60 61define double @g(x86_mmx %x) { 62; CHECK-LABEL: @g( 63; CHECK-NEXT: entry: 64; CHECK-NEXT: [[TMP0:%.*]] = bitcast x86_mmx [[X:%.*]] to double 65; CHECK-NEXT: ret double [[TMP0]] 66; 67entry: 68 %0 = bitcast x86_mmx %x to <1 x i64> 69 %1 = bitcast <1 x i64> %0 to double 70 ret double %1 71} 72 73; FP source is ok. 74 75define <3 x i64> @bitcast_inselt_undef(double %x, i32 %idx) { 76; CHECK-LABEL: @bitcast_inselt_undef( 77; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i32 [[IDX:%.*]] 78; CHECK-NEXT: [[I:%.*]] = bitcast <3 x double> [[TMP1]] to <3 x i64> 79; CHECK-NEXT: ret <3 x i64> [[I]] 80; 81 %xb = bitcast double %x to i64 82 %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx 83 ret <3 x i64> %i 84} 85 86; Integer source is ok; index is anything. 87 88define <3 x float> @bitcast_inselt_undef_fp(i32 %x, i567 %idx) { 89; CHECK-LABEL: @bitcast_inselt_undef_fp( 90; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]] 91; CHECK-NEXT: [[I:%.*]] = bitcast <3 x i32> [[TMP1]] to <3 x float> 92; CHECK-NEXT: ret <3 x float> [[I]] 93; 94 %xb = bitcast i32 %x to float 95 %i = insertelement <3 x float> undef, float %xb, i567 %idx 96 ret <3 x float> %i 97} 98 99define <vscale x 3 x float> @bitcast_inselt_undef_vscale(i32 %x, i567 %idx) { 100; CHECK-LABEL: @bitcast_inselt_undef_vscale( 101; CHECK-NEXT: [[TMP1:%.*]] = insertelement <vscale x 3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]] 102; CHECK-NEXT: [[I:%.*]] = bitcast <vscale x 3 x i32> [[TMP1]] to <vscale x 3 x float> 103; CHECK-NEXT: ret <vscale x 3 x float> [[I]] 104; 105 %xb = bitcast i32 %x to float 106 %i = insertelement <vscale x 3 x float> undef, float %xb, i567 %idx 107 ret <vscale x 3 x float> %i 108} 109 110declare void @use(i64) 111 112; Negative test - extra use prevents canonicalization 113 114define <3 x i64> @bitcast_inselt_undef_extra_use(double %x, i32 %idx) { 115; CHECK-LABEL: @bitcast_inselt_undef_extra_use( 116; CHECK-NEXT: [[XB:%.*]] = bitcast double [[X:%.*]] to i64 117; CHECK-NEXT: call void @use(i64 [[XB]]) 118; CHECK-NEXT: [[I:%.*]] = insertelement <3 x i64> undef, i64 [[XB]], i32 [[IDX:%.*]] 119; CHECK-NEXT: ret <3 x i64> [[I]] 120; 121 %xb = bitcast double %x to i64 122 call void @use(i64 %xb) 123 %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx 124 ret <3 x i64> %i 125} 126 127; Negative test - source type must be scalar 128 129define <3 x i64> @bitcast_inselt_undef_vec_src(<2 x i32> %x, i32 %idx) { 130; CHECK-LABEL: @bitcast_inselt_undef_vec_src( 131; CHECK-NEXT: [[XB:%.*]] = bitcast <2 x i32> [[X:%.*]] to i64 132; CHECK-NEXT: [[I:%.*]] = insertelement <3 x i64> undef, i64 [[XB]], i32 [[IDX:%.*]] 133; CHECK-NEXT: ret <3 x i64> [[I]] 134; 135 %xb = bitcast <2 x i32> %x to i64 136 %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx 137 ret <3 x i64> %i 138} 139 140; Negative test - source type must be scalar 141 142define <3 x i64> @bitcast_inselt_undef_from_mmx(x86_mmx %x, i32 %idx) { 143; CHECK-LABEL: @bitcast_inselt_undef_from_mmx( 144; CHECK-NEXT: [[XB:%.*]] = bitcast x86_mmx [[X:%.*]] to i64 145; CHECK-NEXT: [[I:%.*]] = insertelement <3 x i64> undef, i64 [[XB]], i32 [[IDX:%.*]] 146; CHECK-NEXT: ret <3 x i64> [[I]] 147; 148 %xb = bitcast x86_mmx %x to i64 149 %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx 150 ret <3 x i64> %i 151} 152 153; Reduce number of casts 154 155define <2 x i64> @PR45748(double %x, double %y) { 156; CHECK-LABEL: @PR45748( 157; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x double> undef, double [[X:%.*]], i32 0 158; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x double> [[TMP1]], double [[Y:%.*]], i32 1 159; CHECK-NEXT: [[I1:%.*]] = bitcast <2 x double> [[TMP2]] to <2 x i64> 160; CHECK-NEXT: ret <2 x i64> [[I1]] 161; 162 %xb = bitcast double %x to i64 163 %i0 = insertelement <2 x i64> undef, i64 %xb, i32 0 164 %yb = bitcast double %y to i64 165 %i1 = insertelement <2 x i64> %i0, i64 %yb, i32 1 166 ret <2 x i64> %i1 167} 168