1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -instcombine -S < %s | FileCheck %s 3 4; CHECK-LABEL: good1 5; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 6; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer 7; CHECK-NEXT: ret <4 x float> %[[BCAST]] 8define <4 x float> @good1(float %arg) { 9 %tmp = insertelement <4 x float> undef, float %arg, i32 0 10 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 11 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 12 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 13 ret <4 x float> %tmp6 14} 15 16; CHECK-LABEL: good2 17; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 18; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer 19; CHECK-NEXT: ret <4 x float> %[[BCAST]] 20define <4 x float> @good2(float %arg) { 21 %tmp = insertelement <4 x float> undef, float %arg, i32 1 22 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 2 23 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 0 24 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 25 ret <4 x float> %tmp6 26} 27 28; CHECK-LABEL: good3 29; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 30; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer 31; CHECK-NEXT: ret <4 x float> %[[BCAST]] 32define <4 x float> @good3(float %arg) { 33 %tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0 34 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 35 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 36 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 37 ret <4 x float> %tmp6 38} 39 40; CHECK-LABEL: good4 41; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0 42; CHECK-NEXT: %[[ADD:.*]] = fadd <4 x float> %[[INS]], %[[INS]] 43; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[ADD]], <4 x float> undef, <4 x i32> zeroinitializer 44; CHECK-NEXT: ret <4 x float> %[[BCAST]] 45define <4 x float> @good4(float %arg) { 46 %tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0 47 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 48 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 49 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 50 %tmp7 = fadd <4 x float> %tmp6, %tmp6 51 ret <4 x float> %tmp7 52} 53 54; CHECK-LABEL: @good5( 55; CHECK-NEXT: %ins1 = insertelement <4 x float> undef, float %v, i32 0 56; CHECK-NEXT: %a1 = fadd <4 x float> %ins1, %ins1 57; CHECK-NEXT: %ins4 = shufflevector <4 x float> %ins1, <4 x float> undef, <4 x i32> zeroinitializer 58; CHECK-NEXT: %res = fadd <4 x float> %a1, %ins4 59; CHECK-NEXT: ret <4 x float> %res 60define <4 x float> @good5(float %v) { 61 %ins1 = insertelement <4 x float> undef, float %v, i32 0 62 %a1 = fadd <4 x float> %ins1, %ins1 63 %ins2 = insertelement<4 x float> %ins1, float %v, i32 1 64 %ins3 = insertelement<4 x float> %ins2, float %v, i32 2 65 %ins4 = insertelement<4 x float> %ins3, float %v, i32 3 66 %res = fadd <4 x float> %a1, %ins4 67 ret <4 x float> %res 68} 69 70; CHECK-LABEL: bad1 71; CHECK-NOT: shufflevector 72define <4 x float> @bad1(float %arg) { 73 %tmp = insertelement <4 x float> undef, float %arg, i32 1 74 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 75 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 76 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 77 ret <4 x float> %tmp6 78} 79 80; CHECK-LABEL: bad2 81; CHECK-NOT: shufflevector 82define <4 x float> @bad2(float %arg) { 83 %tmp = insertelement <4 x float> undef, float %arg, i32 0 84 %tmp5 = insertelement <4 x float> %tmp, float %arg, i32 2 85 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 86 ret <4 x float> %tmp6 87} 88 89; CHECK-LABEL: bad3 90; CHECK-NOT: shufflevector 91define <4 x float> @bad3(float %arg, float %arg2) { 92 %tmp = insertelement <4 x float> undef, float %arg, i32 0 93 %tmp4 = insertelement <4 x float> %tmp, float %arg2, i32 1 94 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 95 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 96 ret <4 x float> %tmp6 97} 98 99; CHECK-LABEL: bad4 100; CHECK-NOT: shufflevector 101define <1 x float> @bad4(float %arg) { 102 %tmp = insertelement <1 x float> undef, float %arg, i32 0 103 ret <1 x float> %tmp 104} 105 106; CHECK-LABEL: bad5 107; CHECK-NOT: shufflevector 108define <4 x float> @bad5(float %arg) { 109 %tmp = insertelement <4 x float> undef, float %arg, i32 0 110 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 111 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2 112 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 113 %tmp7 = fadd <4 x float> %tmp6, %tmp4 114 ret <4 x float> %tmp7 115} 116 117; CHECK-LABEL: bad6 118; CHECK-NOT: shufflevector 119define <4 x float> @bad6(float %arg, i32 %k) { 120 %tmp = insertelement <4 x float> undef, float %arg, i32 0 121 %tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1 122 %tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 %k 123 %tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3 124 ret <4 x float> %tmp6 125} 126 127; CHECK-LABEL: @bad7( 128; CHECK-NOT: shufflevector 129define <4 x float> @bad7(float %v) { 130 %ins1 = insertelement <4 x float> undef, float %v, i32 1 131 %a1 = fadd <4 x float> %ins1, %ins1 132 %ins2 = insertelement<4 x float> %ins1, float %v, i32 2 133 %ins3 = insertelement<4 x float> %ins2, float %v, i32 3 134 %ins4 = insertelement<4 x float> %ins3, float %v, i32 0 135 %res = fadd <4 x float> %a1, %ins4 136 ret <4 x float> %res 137} 138