summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-04-04 14:46:13 +0000
committerSanjay Patel <spatel@rotateright.com>2019-04-04 14:46:13 +0000
commit17648b848ef6cc37547c6290d8960eb97fd6dab5 (patch)
treeda19b21b7e7a24172100159a594d4ad3f89bb1d9 /llvm/lib/Target
parentb920a7f65b13237dc4d5b2b836b29a954fff440a (diff)
downloadbcm5719-llvm-17648b848ef6cc37547c6290d8960eb97fd6dab5.tar.gz
bcm5719-llvm-17648b848ef6cc37547c6290d8960eb97fd6dab5.zip
[x86] eliminate unnecessary broadcast of horizontal op
This is another pattern that comes up if we more aggressively scalarize FP ops. llvm-svn: 357703
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index b17d7276e0b..e0c3aaac723 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -32790,10 +32790,19 @@ static SDValue combineShuffleOfConcatUndef(SDNode *N, SelectionDAG &DAG,
/// Eliminate a redundant shuffle of a horizontal math op.
static SDValue foldShuffleOfHorizOp(SDNode *N) {
unsigned Opcode = N->getOpcode();
- if (Opcode != X86ISD::MOVDDUP)
+ if (Opcode != X86ISD::MOVDDUP && Opcode != X86ISD::VBROADCAST)
if (Opcode != ISD::VECTOR_SHUFFLE || !N->getOperand(1).isUndef())
return SDValue();
+ // For a broadcast, peek through an extract element of index 0 to find the
+ // horizontal op: broadcast (ext_vec_elt HOp, 0)
+ if (Opcode == X86ISD::VBROADCAST) {
+ SDValue SrcOp = N->getOperand(0);
+ if (SrcOp.getOpcode() == ISD::EXTRACT_VECTOR_ELT &&
+ SrcOp.getValueType() == MVT::f64 && isNullConstant(SrcOp.getOperand(1)))
+ N = SrcOp.getNode();
+ }
+
SDValue HOp = N->getOperand(0);
if (HOp.getOpcode() != X86ISD::HADD && HOp.getOpcode() != X86ISD::FHADD &&
HOp.getOpcode() != X86ISD::HSUB && HOp.getOpcode() != X86ISD::FHSUB)
@@ -32808,10 +32817,11 @@ static SDValue foldShuffleOfHorizOp(SDNode *N) {
return SDValue();
// When the operands of a horizontal math op are identical, the low half of
- // the result is the same as the high half. If the shuffle is also replicating
- // low and high halves, we don't need the shuffle.
- if (Opcode == X86ISD::MOVDDUP) {
+ // the result is the same as the high half. If a target shuffle is also
+ // replicating low and high halves, we don't need the shuffle.
+ if (Opcode == X86ISD::MOVDDUP || Opcode == X86ISD::VBROADCAST) {
// movddup (hadd X, X) --> hadd X, X
+ // broadcast (extract_vec_elt (hadd X, X), 0) --> hadd X, X
assert((HOp.getValueType() == MVT::v2f64 ||
HOp.getValueType() == MVT::v4f64) && "Unexpected type for h-op");
return HOp;
OpenPOWER on IntegriCloud