[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 12 16:55:09 PDT 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.136 -> 1.137
---
Log message:

implement a couple of simple shift foldings.

e.g.  (X & 7) >> 3   -> 0



---
Diffs of the changes:  (+18 -0)

 SelectionDAG.cpp |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.136 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.137
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.136	Wed Aug 10 21:18:13 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Fri Aug 12 18:54:58 2005
@@ -993,6 +993,24 @@
         return getNode(ISD::UNDEF, N1.getValueType());
       }
       if (C2 == 0) return N1;
+      
+      if (Opcode == ISD::SRA) {
+        // If the sign bit is known to be zero, switch this to a SRL.
+        if (MaskedValueIsZero(N1,
+                              1ULL << MVT::getSizeInBits(N1.getValueType())-1,
+                              TLI))
+          return getNode(ISD::SRL, N1.getValueType(), N1, N2);
+      } else {
+        // If the part left over is known to be zero, the whole thing is zero.
+        uint64_t TypeMask = ~0ULL >> (64-MVT::getSizeInBits(N1.getValueType()));
+        if (Opcode == ISD::SRL) {
+          if (MaskedValueIsZero(N1, TypeMask << C2, TLI))
+            return getConstant(0, N1.getValueType());
+        } else if (Opcode == ISD::SHL) {
+          if (MaskedValueIsZero(N1, TypeMask >> C2, TLI))
+            return getConstant(0, N1.getValueType());
+        }
+      }
 
       if (Opcode == ISD::SHL && N1.getNumOperands() == 2)
         if (ConstantSDNode *OpSA = dyn_cast<ConstantSDNode>(N1.getOperand(1))) {






More information about the llvm-commits mailing list