[llvm-commits] [llvm] r64782 - in /llvm/branches/release_25: lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/nobt.ll

Tanya Lattner tonic at nondot.org
Tue Feb 17 11:01:36 PST 2009


Author: tbrethou
Date: Tue Feb 17 13:01:36 2009
New Revision: 64782

URL: http://llvm.org/viewvc/llvm-project?rev=64782&view=rev
Log:
Merge 64314 from mainline.
Make a transformation added in 63266 a bit less aggressive.
It was transforming (x&y)==y to (x&y)!=0 in the case where
y is variable and known to have at most one bit set (e.g. z&1).
This is not correct; the expressions are not equivalent when y==0.
I believe this patch salvages what can be salvaged, including
all the cases in bt.ll.

Added:
    llvm/branches/release_25/test/CodeGen/X86/nobt.ll
      - copied unchanged from r64314, llvm/trunk/test/CodeGen/X86/nobt.ll
Modified:
    llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Modified: llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=64782&r1=64781&r2=64782&view=diff

==============================================================================
--- llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/branches/release_25/lib/CodeGen/SelectionDAG/TargetLowering.cpp Tue Feb 17 13:01:36 2009
@@ -1346,20 +1346,21 @@
   return 1;
 }
 
-static bool ValueHasAtMostOneBitSet(SDValue Val, const SelectionDAG &DAG) {
+static bool ValueHasExactlyOneBitSet(SDValue Val, const SelectionDAG &DAG) {
   // Logical shift right or left won't ever introduce new set bits.
   // We check for this case because we don't care which bits are
   // set, but ComputeMaskedBits won't know anything unless it can
   // determine which specific bits may be set.
   if (Val.getOpcode() == ISD::SHL || Val.getOpcode() == ISD::SRL)
-    return ValueHasAtMostOneBitSet(Val.getOperand(0), DAG);
+    return ValueHasExactlyOneBitSet(Val.getOperand(0), DAG);
 
   MVT OpVT = Val.getValueType();
   unsigned BitWidth = OpVT.getSizeInBits();
   APInt Mask = APInt::getAllOnesValue(BitWidth);
   APInt KnownZero, KnownOne;
   DAG.ComputeMaskedBits(Val, Mask, KnownZero, KnownOne);
-  return KnownZero.countPopulation() == BitWidth - 1;
+  return (KnownZero.countPopulation() == BitWidth - 1) &&
+         (KnownOne.countPopulation() == 1);
 }
 
 /// SimplifySetCC - Try to simplify a setcc built with the specified operands 
@@ -1832,9 +1833,12 @@
     }
 
     // Simplify x&y == y to x&y != 0 if y has exactly one bit set.
+    // Note that where y is variable and is known to have at most
+    // one bit set (for example, if it is z&1) we cannot do this;
+    // the expressions are not equivalent when y==0.
     if (N0.getOpcode() == ISD::AND)
       if (N0.getOperand(0) == N1 || N0.getOperand(1) == N1) {
-        if (ValueHasAtMostOneBitSet(N1, DAG)) {
+        if (ValueHasExactlyOneBitSet(N1, DAG)) {
           Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true);
           SDValue Zero = DAG.getConstant(0, N1.getValueType());
           return DAG.getSetCC(dl, VT, N0, Zero, Cond);
@@ -1842,7 +1846,7 @@
       }
     if (N1.getOpcode() == ISD::AND)
       if (N1.getOperand(0) == N0 || N1.getOperand(1) == N0) {
-        if (ValueHasAtMostOneBitSet(N0, DAG)) {
+        if (ValueHasExactlyOneBitSet(N0, DAG)) {
           Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true);
           SDValue Zero = DAG.getConstant(0, N0.getValueType());
           return DAG.getSetCC(dl, VT, N1, Zero, Cond);





More information about the llvm-commits mailing list