[llvm-commits] Review Request: incorrect xor->and transformation

Joel Jones joel_k_jones at apple.com
Tue Apr 17 14:50:48 PDT 2012


Fixes a problem in instruction selection with testing whether or not the transformation:

 (X op C1) ^ C2 --> (X op C1) & ~C2 iff (C1&C2) == C2

should be done.  

This change has been tested:
  Using a debug+asserts build:
    on the specific test case that brought this bug to light
    make check-all
    lnt nt
    using this clang to build a release version of clang
  Using the release+asserts clang-with-clang build:
    on the specific test case that brought this bug to light
    make check-all
    lnt nt


Index: lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/TargetLowering.cpp	(revision 154936)
+++ lib/CodeGen/SelectionDAG/TargetLowering.cpp	(working copy)
@@ -1367,8 +1367,9 @@
     // bits on that side are also known to be set on the other side, turn this
     // into an AND, as we know the bits will be cleared.
     //    e.g. (X | C1) ^ C2 --> (X | C1) & ~C2 iff (C1&C2) == C2
-    if ((NewMask & (KnownZero|KnownOne)) == NewMask) { // all known
-      if ((KnownOne & KnownOne2) == KnownOne) {
+    // NB: it is okay if more bits are known than are requested
+    if ((NewMask & (KnownZero|KnownOne)) == NewMask) { // all known on one side 
+      if (KnownOne == KnownOne2) { // set bits are the same on both sides
         EVT VT = Op.getValueType();
         SDValue ANDC = TLO.DAG.getConstant(~KnownOne & NewMask, VT);
         return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::AND, dl, VT,




More information about the llvm-commits mailing list