[llvm-commits] [llvm] r56452 - /llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Evan Cheng evan.cheng at apple.com
Mon Sep 22 11:19:24 PDT 2008


Author: evancheng
Date: Mon Sep 22 13:19:24 2008
New Revision: 56452

URL: http://llvm.org/viewvc/llvm-project?rev=56452&view=rev
Log:
Per review feedback: Only perform
(srl x, (trunc (and y, c))) -> (srl x, (and (trunc y), c))
etc. when both "trunc" and "and" have single uses.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=56452&r1=56451&r2=56452&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Sep 22 13:19:24 2008
@@ -2312,21 +2312,17 @@
   // 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) {
+      N1.getOperand(0).getOpcode() == ISD::AND &&
+      N1.hasOneUse() && N1.getOperand(0).hasOneUse()) {
     SDValue N101 = N1.getOperand(0).getOperand(1);
-    ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
-    if (N101C) {
+    if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
-      unsigned TruncBitSize = TruncVT.getSizeInBits();
-      APInt ShAmt = N101C->getAPIntValue();
-      if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getZExtValue()) {
-        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->getZExtValue(),
-                                                  TruncVT)));
-      }
+      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->getZExtValue(),
+                                                     TruncVT)));
     }
   }
 
@@ -2444,21 +2440,17 @@
   // 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) {
+      N1.getOperand(0).getOpcode() == ISD::AND &&
+      N1.hasOneUse() && N1.getOperand(0).hasOneUse()) {
     SDValue N101 = N1.getOperand(0).getOperand(1);
-    ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
-    if (N101C) {
+    if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
-      unsigned TruncBitSize = TruncVT.getSizeInBits();
-      APInt ShAmt = N101C->getAPIntValue();
-      if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getZExtValue()) {
-        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->getZExtValue(),
-                                                  TruncVT)));
-      }
+      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->getZExtValue(),
+                                                     TruncVT)));
     }
   }
 
@@ -2565,21 +2557,17 @@
   // 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) {
+      N1.getOperand(0).getOpcode() == ISD::AND &&
+      N1.hasOneUse() && N1.getOperand(0).hasOneUse()) {
     SDValue N101 = N1.getOperand(0).getOperand(1);
-    ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101);
-    if (N101C) {
+    if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
-      unsigned TruncBitSize = TruncVT.getSizeInBits();
-      APInt ShAmt = N101C->getAPIntValue();
-      if (ShAmt.trunc(TruncBitSize).getZExtValue() == N101C->getZExtValue()) {
-        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->getZExtValue(),
-                                                  TruncVT)));
-      }
+      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->getZExtValue(),
+                                                     TruncVT)));
     }
   }
   





More information about the llvm-commits mailing list