summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-10-15 16:47:01 +0000
committerSanjay Patel <spatel@rotateright.com>2018-10-15 16:47:01 +0000
commit89e2197c3379b51a008e0ca899d51864c73f7822 (patch)
tree222695fd565f1342f754ef1b17d8fae6a604e480 /llvm/lib/CodeGen/SelectionDAG
parent7cf5733f7f2a478e0c0fe1c584c12e9c62116d92 (diff)
downloadbcm5719-llvm-89e2197c3379b51a008e0ca899d51864c73f7822.tar.gz
bcm5719-llvm-89e2197c3379b51a008e0ca899d51864c73f7822.zip
[DAGCombiner] refactor folds for fadd (fmul X, -2.0), Y; NFCI
The transform doesn't work if the vector constant has undef elements. llvm-svn: 344532
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 846830b3b28..ab871a25d07 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -10851,14 +10851,6 @@ SDValue DAGCombiner::visitFMULForFMADistributiveCombine(SDNode *N) {
return SDValue();
}
-static bool isFMulNegTwo(SDValue &N) {
- if (N.getOpcode() != ISD::FMUL)
- return false;
- if (ConstantFPSDNode *CFP = isConstOrConstSplatFP(N.getOperand(1)))
- return CFP->isExactlyValue(-2.0);
- return false;
-}
-
SDValue DAGCombiner::visitFADD(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
@@ -10903,14 +10895,24 @@ SDValue DAGCombiner::visitFADD(SDNode *N) {
return DAG.getNode(ISD::FSUB, DL, VT, N1,
GetNegatedExpression(N0, DAG, LegalOperations), Flags);
- // fold (fadd A, (fmul B, -2.0)) -> (fsub A, (fadd B, B))
- // fold (fadd (fmul B, -2.0), A) -> (fsub A, (fadd B, B))
- if ((isFMulNegTwo(N0) && N0.hasOneUse()) ||
- (isFMulNegTwo(N1) && N1.hasOneUse())) {
- bool N1IsFMul = isFMulNegTwo(N1);
- SDValue AddOp = N1IsFMul ? N1.getOperand(0) : N0.getOperand(0);
- SDValue Add = DAG.getNode(ISD::FADD, DL, VT, AddOp, AddOp, Flags);
- return DAG.getNode(ISD::FSUB, DL, VT, N1IsFMul ? N0 : N1, Add, Flags);
+ auto isFMulNegTwo = [](SDValue FMul) {
+ if (!FMul.hasOneUse() || FMul.getOpcode() != ISD::FMUL)
+ return false;
+ auto *C = isConstOrConstSplatFP(FMul.getOperand(1));
+ return C && C->isExactlyValue(-2.0);
+ };
+
+ // fadd (fmul B, -2.0), A --> fsub A, (fadd B, B)
+ if (isFMulNegTwo(N0)) {
+ SDValue B = N0.getOperand(0);
+ SDValue Add = DAG.getNode(ISD::FADD, DL, VT, B, B, Flags);
+ return DAG.getNode(ISD::FSUB, DL, VT, N1, Add, Flags);
+ }
+ // fadd A, (fmul B, -2.0) --> fsub A, (fadd B, B)
+ if (isFMulNegTwo(N1)) {
+ SDValue B = N1.getOperand(0);
+ SDValue Add = DAG.getNode(ISD::FADD, DL, VT, B, B, Flags);
+ return DAG.getNode(ISD::FSUB, DL, VT, N0, Add, Flags);
}
// No FP constant should be created after legalization as Instruction
OpenPOWER on IntegriCloud