// lanes of each operand as:
// v4X32: A[0] + A[1] , A[2] + A[3] , B[0] + B[1] , B[2] + B[3]
// ...similarly for v2f64 and v8i16.
- // TODO: 256-bit is not the same because...x86.
- if (HOp.getOperand(0) != HOp.getOperand(1) || HOp.getValueSizeInBits() != 128)
+ // TODO: Handle UNDEF operands.
+ if (HOp.getOperand(0) != HOp.getOperand(1))
return SDValue();
// When the operands of a horizontal math op are identical, the low half of
// TODO: Other mask possibilities like {1,1} and {1,0} could be added here,
// but this should be tied to whatever horizontal op matching and shuffle
// canonicalization are producing.
- if (isTargetShuffleEquivalent(Mask, { 0, 0 }) ||
- isTargetShuffleEquivalent(Mask, { 0, 1, 0, 1 }) ||
- isTargetShuffleEquivalent(Mask, { 0, 1, 2, 3, 0, 1, 2, 3 }))
+ if (HOp.getValueSizeInBits() == 128 &&
+ (isTargetShuffleEquivalent(Mask, {0, 0}) ||
+ isTargetShuffleEquivalent(Mask, {0, 1, 0, 1}) ||
+ isTargetShuffleEquivalent(Mask, {0, 1, 2, 3, 0, 1, 2, 3})))
+ return HOp;
+
+ if (HOp.getValueSizeInBits() == 256 &&
+ (isTargetShuffleEquivalent(Mask, {0, 0, 2, 2}) ||
+ isTargetShuffleEquivalent(Mask, {0, 1, 0, 1, 4, 5, 4, 5})))
return HOp;
return SDValue();
; AVX-LABEL: hadd_v8f32b:
; AVX: # %bb.0:
; AVX-NEXT: vhaddps %ymm0, %ymm0, %ymm0
-; AVX-NEXT: vmovddup {{.*#+}} ymm0 = ymm0[0,0,2,2]
; AVX-NEXT: retq
%a0 = shufflevector <8 x float> %a, <8 x float> undef, <8 x i32> <i32 0, i32 2, i32 undef, i32 undef, i32 4, i32 6, i32 undef, i32 undef>
%a1 = shufflevector <8 x float> %a, <8 x float> undef, <8 x i32> <i32 1, i32 3, i32 undef, i32 undef, i32 5, i32 7, i32 undef, i32 undef>
; AVX-LABEL: hsub_v8f32b:
; AVX: # %bb.0:
; AVX-NEXT: vhsubps %ymm0, %ymm0, %ymm0
-; AVX-NEXT: vmovddup {{.*#+}} ymm0 = ymm0[0,0,2,2]
; AVX-NEXT: retq
%a0 = shufflevector <8 x float> %a, <8 x float> undef, <8 x i32> <i32 0, i32 2, i32 undef, i32 undef, i32 4, i32 6, i32 undef, i32 undef>
%a1 = shufflevector <8 x float> %a, <8 x float> undef, <8 x i32> <i32 1, i32 3, i32 undef, i32 undef, i32 5, i32 7, i32 undef, i32 undef>
; AVX-LABEL: hadd_v4f64:
; AVX: # %bb.0:
; AVX-NEXT: vhaddpd %ymm0, %ymm0, %ymm0
-; AVX-NEXT: vmovddup {{.*#+}} ymm0 = ymm0[0,0,2,2]
; AVX-NEXT: retq
%a0 = shufflevector <4 x double> %a, <4 x double> undef, <4 x i32> <i32 0, i32 undef, i32 2, i32 undef>
%a1 = shufflevector <4 x double> %a, <4 x double> undef, <4 x i32> <i32 1, i32 undef, i32 3, i32 undef>
; AVX-LABEL: hsub_v4f64:
; AVX: # %bb.0:
; AVX-NEXT: vhsubpd %ymm0, %ymm0, %ymm0
-; AVX-NEXT: vmovddup {{.*#+}} ymm0 = ymm0[0,0,2,2]
; AVX-NEXT: retq
%a0 = shufflevector <4 x double> %a, <4 x double> undef, <4 x i32> <i32 0, i32 undef, i32 2, i32 undef>
%a1 = shufflevector <4 x double> %a, <4 x double> undef, <4 x i32> <i32 1, i32 undef, i32 3, i32 undef>
; AVX2-LABEL: hadd_v8i32b:
; AVX2: # %bb.0:
; AVX2-NEXT: vphaddd %ymm0, %ymm0, %ymm0
-; AVX2-NEXT: vpshufd {{.*#+}} ymm0 = ymm0[0,1,0,1,4,5,4,5]
; AVX2-NEXT: retq
%a0 = shufflevector <8 x i32> %a, <8 x i32> undef, <8 x i32> <i32 0, i32 2, i32 undef, i32 undef, i32 4, i32 6, i32 undef, i32 undef>
%a1 = shufflevector <8 x i32> %a, <8 x i32> undef, <8 x i32> <i32 1, i32 3, i32 undef, i32 undef, i32 5, i32 7, i32 undef, i32 undef>
; AVX2-LABEL: hsub_v8i32b:
; AVX2: # %bb.0:
; AVX2-NEXT: vphsubd %ymm0, %ymm0, %ymm0
-; AVX2-NEXT: vpshufd {{.*#+}} ymm0 = ymm0[0,1,0,1,4,5,4,5]
; AVX2-NEXT: retq
%a0 = shufflevector <8 x i32> %a, <8 x i32> undef, <8 x i32> <i32 0, i32 2, i32 undef, i32 undef, i32 4, i32 6, i32 undef, i32 undef>
%a1 = shufflevector <8 x i32> %a, <8 x i32> undef, <8 x i32> <i32 1, i32 3, i32 undef, i32 undef, i32 5, i32 7, i32 undef, i32 undef>