diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-11-18 17:36:23 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-11-18 17:36:23 +0000 |
commit | 8c0cd77bffb55151dcfcf58caf0f6a60b7556bcc (patch) | |
tree | 279187f1dfbf9e7914f9b094465c64cbab0d6b5b /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | ec808cf541e351d2f7129e5faa154fe84afc8087 (diff) | |
download | bcm5719-llvm-8c0cd77bffb55151dcfcf58caf0f6a60b7556bcc.tar.gz bcm5719-llvm-8c0cd77bffb55151dcfcf58caf0f6a60b7556bcc.zip |
[DAG] add undef simplifications for select nodes
Sadly, this duplicates (twice) the logic from InstSimplify. There
might be some way to at least share the DAG versions of the code,
but copying the folds seems to be the standard method to ensure
that we don't miss these folds.
Unlike in IR, we don't run DAGCombiner to fixpoint, so there's no
way to ensure that we do these kinds of simplifications unless the
code is repeated at node creation time and during combines.
There were other tests that would become worthless with this
improvement that I changed as pre-commits:
rL347161
rL347164
rL347165
rL347166
rL347167
I'm not sure how to salvage the remaining tests (diffs in this patch).
So the x86 tests verify that the new code is working as intended.
The AMDGPU test is actually similar to my motivating case: we have
some undef value that has survived to machine IR in an x86 test, and
then it gets folded in some weird way, or we crash if we don't transfer
the undef flag. But we would have been better off never getting to that
point by doing these simplifications.
This will lead back to PR32023 someday...
https://bugs.llvm.org/show_bug.cgi?id=32023
llvm-svn: 347170
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 24f019d55c9..0f428b72d52 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7236,21 +7236,24 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) { EVT VT0 = N0.getValueType(); SDLoc DL(N); - // fold (select C, X, X) -> X - if (N1 == N2) - return N1; - - // fold (select, C, X, undef) -> X - if (N2.isUndef()) - return N1; + // select undef, N1, N2 --> N1 (if it's a constant), otherwise N2 + if (N0.isUndef()) + return isa<ConstantSDNode>(N1) ? N1 : N2; + // select, ?, undef, N2 --> N2 if (N1.isUndef()) return N2; + // select, ?, N1, undef --> N1 + if (N2.isUndef()) + return N1; - if (const ConstantSDNode *N0C = dyn_cast<const ConstantSDNode>(N0)) { - // fold (select true, X, Y) -> X - // fold (select false, X, Y) -> Y - return !N0C->isNullValue() ? N1 : N2; - } + // fold (select true, X, Y) -> X + // fold (select false, X, Y) -> Y + if (auto *N0C = dyn_cast<const ConstantSDNode>(N0)) + return N0C->isNullValue() ? N2 : N1; + + // select ?, N1, N1 --> N1 + if (N1 == N2) + return N1; // fold (select X, X, Y) -> (or X, Y) // fold (select X, 1, Y) -> (or C, Y) |