diff options
| author | Craig Topper <craig.topper@intel.com> | 2018-07-28 00:27:25 +0000 | 
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2018-07-28 00:27:25 +0000 | 
| commit | 50b1d4303d0e710007bc2ebc895a378e53204400 (patch) | |
| tree | d490fef34a7494321498866f9a42f60f3744c601 /llvm/lib | |
| parent | 5666c7e4bd629bb6329cf8ac498507ef7bef673c (diff) | |
| download | bcm5719-llvm-50b1d4303d0e710007bc2ebc895a378e53204400.tar.gz bcm5719-llvm-50b1d4303d0e710007bc2ebc895a378e53204400.zip  | |
[DAGCombiner] Teach DAG combiner that A-(B-C) can be folded to A+(C-B)
This can be useful since addition is commutable, and subtraction is not.
This matches a transform that is also done by InstCombine.
llvm-svn: 338181
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 6 | 
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 7a99687757f..963081c2e95 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2671,6 +2671,12 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {      return DAG.getNode(ISD::SUB, DL, VT, N0.getOperand(0),                         N0.getOperand(1).getOperand(0)); +  // fold (A-(B-C)) -> A+(C-B) +  if (N1.getOpcode() == ISD::SUB && N1.hasOneUse()) +    return DAG.getNode(ISD::ADD, DL, VT, N0, +                       DAG.getNode(ISD::SUB, DL, VT, N1.getOperand(1), +                                   N1.getOperand(0))); +    // fold (X - (-Y * Z)) -> (X + (Y * Z))    if (N1.getOpcode() == ISD::MUL && N1.hasOneUse()) {      if (N1.getOperand(0).getOpcode() == ISD::SUB &&  | 

