Skip to content

Commit 35127d7

Browse files
committed
Merging r372606:
------------------------------------------------------------------------ r372606 | spatel | 2019-09-23 06:30:23 -0700 (Mon, 23 Sep 2019) | 3 lines [x86] fix assert with horizontal math + broadcast of vector (PR43402) https://bugs.llvm.org/show_bug.cgi?id=43402 ------------------------------------------------------------------------ llvm-svn: 374633
1 parent 171c0c2 commit 35127d7

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33651,14 +33651,14 @@ static SDValue foldShuffleOfHorizOp(SDNode *N, SelectionDAG &DAG) {
3365133651

3365233652
// When the operands of a horizontal math op are identical, the low half of
3365333653
// the result is the same as the high half. If a target shuffle is also
33654-
// replicating low and high halves, we don't need the shuffle.
33654+
// replicating low and high halves (and without changing the type/length of
33655+
// the vector), we don't need the shuffle.
3365533656
if (Opcode == X86ISD::MOVDDUP || Opcode == X86ISD::VBROADCAST) {
33656-
if (HOp.getScalarValueSizeInBits() == 64) {
33657+
if (HOp.getScalarValueSizeInBits() == 64 && HOp.getValueType() == VT) {
3365733658
// movddup (hadd X, X) --> hadd X, X
3365833659
// broadcast (extract_vec_elt (hadd X, X), 0) --> hadd X, X
3365933660
assert((HOp.getValueType() == MVT::v2f64 ||
33660-
HOp.getValueType() == MVT::v4f64) && HOp.getValueType() == VT &&
33661-
"Unexpected type for h-op");
33661+
HOp.getValueType() == MVT::v4f64) && "Unexpected type for h-op");
3366233662
return updateHOp(HOp, DAG);
3366333663
}
3366433664
return SDValue();

llvm/lib/Target/X86/X86ISelLowering.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ namespace llvm {
422422
// Tests Types Of a FP Values for scalar types.
423423
VFPCLASSS,
424424

425-
// Broadcast scalar to vector.
425+
// Broadcast (splat) scalar or element 0 of a vector. If the operand is
426+
// a vector, this node may change the vector length as part of the splat.
426427
VBROADCAST,
427428
// Broadcast mask to vector.
428429
VBROADCASTM,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=i686-- -mattr=avx2 | FileCheck %s
3+
4+
; The broadcast node takes a vector operand as input and changes its length.
5+
6+
define <4 x double> @PR43402(i64 %x) {
7+
; CHECK-LABEL: PR43402:
8+
; CHECK: # %bb.0:
9+
; CHECK-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
10+
; CHECK-NEXT: vunpcklps {{.*#+}} xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
11+
; CHECK-NEXT: vsubpd {{\.LCPI.*}}, %xmm0, %xmm0
12+
; CHECK-NEXT: vhaddpd %xmm0, %xmm0, %xmm0
13+
; CHECK-NEXT: vbroadcastsd %xmm0, %ymm0
14+
; CHECK-NEXT: retl
15+
%conv = uitofp i64 %x to double
16+
%t2 = insertelement <4 x double> undef, double %conv, i32 0
17+
%t3 = shufflevector <4 x double> %t2, <4 x double> undef, <4 x i32> zeroinitializer
18+
ret <4 x double> %t3
19+
}
20+

0 commit comments

Comments
 (0)