summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-08-30 02:03:58 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-08-30 02:03:58 +0000
commitcfb7f3abdff10b573ef73216784e1a3bdd77c0c5 (patch)
treebffbc5ff6c525d7607119f72523a893b20b8b73d /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parent8eec985ac701aeba22a929ea2e1adc458ed2de7c (diff)
downloadbcm5719-llvm-cfb7f3abdff10b573ef73216784e1a3bdd77c0c5.tar.gz
bcm5719-llvm-cfb7f3abdff10b573ef73216784e1a3bdd77c0c5.zip
Transform (x << (y&31)) -> (x << y). This takes advantage of the fact x86 shift instructions 2nd operand (shift count) is limited to 0 to 31 (or 63 in the x86-64 case).
llvm-svn: 55558
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d0a36100a26..bb9dde00766 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2310,6 +2310,26 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
if (DAG.MaskedValueIsZero(SDValue(N, 0),
APInt::getAllOnesValue(VT.getSizeInBits())))
return DAG.getConstant(0, VT);
+ // fold (shl x, (trunc (and y, c))) -> (shl x, (and (trunc y), c))
+ // iff (trunc c) == c
+ if (N1.getOpcode() == ISD::TRUNCATE &&
+ N1.getOperand(0).getOpcode() == ISD::AND) {
+ SDValue N101 = N1.getOperand(0).getOperand(1);
+ ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
+ if (N101C) {
+ MVT TruncVT = N1.getValueType();
+ unsigned TruncBitSize = TruncVT.getSizeInBits();
+ APInt ShAmt = N101C->getAPIntValue();
+ if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getValue()) {
+ SDValue N100 = N1.getOperand(0).getOperand(0);
+ return DAG.getNode(ISD::SHL, VT, N0,
+ DAG.getNode(ISD::AND, TruncVT,
+ DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
+ DAG.getConstant(N101C->getValue(), TruncVT)));
+ }
+ }
+ }
+
if (N1C && SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);
// fold (shl (shl x, c1), c2) -> 0 or (shl x, c1+c2)
@@ -2421,6 +2441,26 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
}
}
+ // fold (sra x, (trunc (and y, c))) -> (sra x, (and (trunc y), c))
+ // iff (trunc c) == c
+ if (N1.getOpcode() == ISD::TRUNCATE &&
+ N1.getOperand(0).getOpcode() == ISD::AND) {
+ SDValue N101 = N1.getOperand(0).getOperand(1);
+ ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
+ if (N101C) {
+ MVT TruncVT = N1.getValueType();
+ unsigned TruncBitSize = TruncVT.getSizeInBits();
+ APInt ShAmt = N101C->getAPIntValue();
+ if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getValue()) {
+ SDValue N100 = N1.getOperand(0).getOperand(0);
+ return DAG.getNode(ISD::SRA, VT, N0,
+ DAG.getNode(ISD::AND, TruncVT,
+ DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
+ DAG.getConstant(N101C->getValue(), TruncVT)));
+ }
+ }
+ }
+
// Simplify, based on bits shifted out of the LHS.
if (N1C && SimplifyDemandedBits(SDValue(N, 0)))
return SDValue(N, 0);
@@ -2520,6 +2560,26 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
return DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(1, VT));
}
}
+
+ // fold (srl x, (trunc (and y, c))) -> (srl x, (and (trunc y), c))
+ // iff (trunc c) == c
+ if (N1.getOpcode() == ISD::TRUNCATE &&
+ N1.getOperand(0).getOpcode() == ISD::AND) {
+ SDValue N101 = N1.getOperand(0).getOperand(1);
+ ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
+ if (N101C) {
+ MVT TruncVT = N1.getValueType();
+ unsigned TruncBitSize = TruncVT.getSizeInBits();
+ APInt ShAmt = N101C->getAPIntValue();
+ if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getValue()) {
+ SDValue N100 = N1.getOperand(0).getOperand(0);
+ return DAG.getNode(ISD::SRL, VT, N0,
+ DAG.getNode(ISD::AND, TruncVT,
+ DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
+ DAG.getConstant(N101C->getValue(), TruncVT)));
+ }
+ }
+ }
// fold operands of srl based on knowledge that the low bits are not
// demanded.
OpenPOWER on IntegriCloud