diff options
author | Bob Wilson <bob.wilson@apple.com> | 2009-01-22 22:05:48 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2009-01-22 22:05:48 +0000 |
commit | 67ba22318b49200ffdedb1f50a8d89f08e6c710c (patch) | |
tree | 5a0e209e5839e816bee8219f8f2578f463210645 | |
parent | 760f86f3395750ef6d03ecfe6f82d2867fbf568b (diff) |
Fix a minor bug in DAGCombiner's folding of SELECT. Folding "select C, 0, 1"
to "C ^ 1" is only valid when C is known to be either 0 or 1. Most of the
similar foldings in this function only handle "i1" types, but this one appears
intentionally written to handle larger integer types. If C has an integer
type larger than "i1", this needs to check if the high bits of a boolean
are known to be zero. I also changed the comment to describe this folding as
"C ^ 1" instead of "~C", since that is what the code does and since the latter
would only be valid for "i1" types. The good news is that most LLVM targets
use TargetLowering::ZeroOrOneBooleanContent so this change will not disable
the optimization; the bad news is that I've been unable to come up with a
testcase to demonstrate the problem.
I have also removed a "FIXME" comment for folding "select C, X, 0" to "C & X",
since the code looks correct to me. It could be made more aggressive by not
limiting the type to "i1", but that would then require checking for
TargetLowering::ZeroOrNegativeOneBooleanContent. Similar changes could be
done for the other SELECT foldings, but it was decided to be not worth the
trouble and complexity (see e.g., r44663).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62790 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index e494da3644..7e8e46fba5 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2746,8 +2746,11 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) { // fold select C, 1, X -> C | X if (VT == MVT::i1 && N1C && N1C->getAPIntValue() == 1) return DAG.getNode(ISD::OR, VT, N0, N2); - // fold select C, 0, 1 -> ~C - if (VT.isInteger() && VT0.isInteger() && + // fold select C, 0, 1 -> C ^ 1 + if (VT.isInteger() && + (VT0 == MVT::i1 || + (VT0.isInteger() && + TLI.getBooleanContents() == TargetLowering::ZeroOrOneBooleanContent)) && N1C && N2C && N1C->isNullValue() && N2C->getAPIntValue() == 1) { SDValue XORNode = DAG.getNode(ISD::XOR, VT0, N0, DAG.getConstant(1, VT0)); if (VT == VT0) @@ -2770,7 +2773,6 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) { return DAG.getNode(ISD::OR, VT, NOTNode, N1); } // fold select C, X, 0 -> C & X - // FIXME: this should check for C type == X type, not i1? if (VT == MVT::i1 && N2C && N2C->isNullValue()) return DAG.getNode(ISD::AND, VT, N0, N1); // fold X ? X : Y --> X ? 1 : Y --> X | Y |