[llvm-commits] CVS: llvm/lib/Target/TargetLowering.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Feb 26 17:00:54 PST 2006



Changes in directory llvm/lib/Target:

TargetLowering.cpp updated: 1.40 -> 1.41
---
Log message:

Implement bit propagation through sub nodes, this (re)implements
PowerPC/div-2.ll


---
Diffs of the changes:  (+29 -3)

 TargetLowering.cpp |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)


Index: llvm/lib/Target/TargetLowering.cpp
diff -u llvm/lib/Target/TargetLowering.cpp:1.40 llvm/lib/Target/TargetLowering.cpp:1.41
--- llvm/lib/Target/TargetLowering.cpp:1.40	Sun Feb 26 18:36:27 2006
+++ llvm/lib/Target/TargetLowering.cpp	Sun Feb 26 19:00:42 2006
@@ -598,6 +598,12 @@
       }
     }
     break;
+  case ISD::SUB:
+    // Just use ComputeMaskedBits to compute output bits, there are no
+    // simplifications that can be done here, and sub always demands all input
+    // bits.
+    ComputeMaskedBits(Op, DemandedMask, KnownZero, KnownOne, Depth);
+    break;
   }
   
   // If we know the value of all of the demanded bits, return this as a
@@ -861,12 +867,32 @@
     KnownOne = 0;
     return;
   }
-  case ISD::SUB:
+  case ISD::SUB: {
+    ConstantSDNode *CLHS = dyn_cast<ConstantSDNode>(Op.getOperand(0));
+    if (!CLHS) return;
+
     // We know that the top bits of C-X are clear if X contains less bits
     // than C (i.e. no wrap-around can happen).  For example, 20-X is
-    // positive if we can prove that X is >= 0 and < 16.  Remember to update 
-    // SimplifyDemandedBits if/when this is implemented.
+    // positive if we can prove that X is >= 0 and < 16.
+    MVT::ValueType VT = CLHS->getValueType(0);
+    if ((CLHS->getValue() & MVT::getIntVTSignBit(VT)) == 0) {  // sign bit clear
+      unsigned NLZ = CountLeadingZeros_64(CLHS->getValue()+1);
+      uint64_t MaskV = (1ULL << (63-NLZ))-1; // NLZ can't be 64 with no sign bit
+      MaskV = ~MaskV & MVT::getIntVTBitMask(VT);
+      ComputeMaskedBits(Op.getOperand(1), MaskV, KnownZero, KnownOne, Depth+1);
+
+      // If all of the MaskV bits are known to be zero, then we know the output
+      // top bits are zero, because we now know that the output is from [0-C].
+      if ((KnownZero & MaskV) == MaskV) {
+        unsigned NLZ2 = CountLeadingZeros_64(CLHS->getValue());
+        KnownZero = ~((1ULL << (64-NLZ2))-1) & Mask;  // Top bits known zero.
+        KnownOne = 0;   // No one bits known.
+      } else {
+        KnownOne = KnownOne = 0;  // Otherwise, nothing known.
+      }
+    }
     return;
+  }
   default:
     // Allow the target to implement this method for its nodes.
     if (Op.getOpcode() >= ISD::BUILTIN_OP_END)






More information about the llvm-commits mailing list