diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-05-07 21:52:22 +0000 | 
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2018-05-07 21:52:22 +0000 | 
| commit | 9bd6067db650f8d757935fe35f2911e66c7fdc23 (patch) | |
| tree | ecf5ea7d49bc3ee705f3e6add29373760a91013d /llvm/lib/CodeGen | |
| parent | cc42d08b1daf6874e7b65986443510bfc5e0abc3 (diff) | |
| download | bcm5719-llvm-9bd6067db650f8d757935fe35f2911e66c7fdc23.tar.gz bcm5719-llvm-9bd6067db650f8d757935fe35f2911e66c7fdc23.zip  | |
[DAGCombiner] Masked merge: enhance handling of 'andn' with immediates
Summary:
Split off from D46031.
The previous patch, D46493, completely disabled unfolding in case of immediates.
But we can do better:
{F6120274} {F6120277}
https://rise4fun.com/Alive/xJS
Reviewers: spatel, craig.topper
Reviewed By: spatel
Subscribers: andreadb, llvm-commits
Differential Revision: https://reviews.llvm.org/D46494
llvm-svn: 331685
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 18 | 
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b809bbc1c6c..863fcf1be0b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5372,6 +5372,9 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {  //    |  D  |  // Into:  //   (x & m) | (y & ~m) +// If y is a constant, and the 'andn' does not work with immediates, +// we unfold into a different pattern: +//   ~(~x & m) & (m | y)  // NOTE: we don't unfold the pattern if 'xor' is actually a 'not', because at  //       the very least that breaks andnpd / andnps patterns, and because those  //       patterns are simplified in IR and shouldn't be created in the DAG @@ -5428,12 +5431,19 @@ SDValue DAGCombiner::unfoldMaskedMerge(SDNode *N) {    if (!TLI.hasAndNot(M))      return SDValue(); -  // If Y is a constant, check that 'andn' works with immediates. -  if (!TLI.hasAndNot(Y)) -    return SDValue(); -    SDLoc DL(N); +  // If Y is a constant, check that 'andn' works with immediates. +  if (!TLI.hasAndNot(Y)) { +    assert(TLI.hasAndNot(X) && "Only mask is a variable? Unreachable."); +    // If not, we need to do a bit more work to make sure andn is still used. +    SDValue NotX = DAG.getNOT(DL, X, VT); +    SDValue LHS = DAG.getNode(ISD::AND, DL, VT, NotX, M); +    SDValue NotLHS = DAG.getNOT(DL, LHS, VT); +    SDValue RHS = DAG.getNode(ISD::OR, DL, VT, M, Y); +    return DAG.getNode(ISD::AND, DL, VT, NotLHS, RHS); +  } +    SDValue LHS = DAG.getNode(ISD::AND, DL, VT, X, M);    SDValue NotM = DAG.getNOT(DL, M, VT);    SDValue RHS = DAG.getNode(ISD::AND, DL, VT, Y, NotM);  | 

