<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>I get your point. I agree the transformation is correct.<br>
    </p>
    <p>As I understand, Instead of evaluating/folding (a & undef) 
      and (~a & undef) individually, LLVM creates a^undef directly
      and then it is safe to evaluate a^undef to undef. <br>
    </p>
    <p>Thanks to all for the discussion.<br>
    </p>
    <p> Best Regards,</p>
    <p>soham<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 9/14/2016 5:27 PM, Mehdi Amini
      wrote:<br>
    </div>
    <blockquote
      cite="mid:012CC9EB-53CC-4681-93D8-7E043492CBF4@apple.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <br class="">
      <div>
        <blockquote type="cite" class="">
          <div class="">On Sep 14, 2016, at 4:55 AM, sohachak via
            llvm-dev <<a moz-do-not-send="true"
              href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>>
            wrote:</div>
          <br class="Apple-interchange-newline">
          <div class="">
            <meta content="text/html; charset=utf-8"
              http-equiv="Content-Type" class="">
            <div bgcolor="#FFFFFF" text="#000000" class="">
              <p class="">Hi,</p>
              <font class="" color="#993300">> Both A and B are
                undef:<br class="">
                >    LHS = (undef & undef) | (undef & undef)
                = undef  // Since ~undef = undef<br class="">
                >    RHS = undef<br class="">
                >    Thus transform is correct.<br class="">
                <br class="">
              </font><font class="" face="Arial">LLVM documentation (<a
                  moz-do-not-send="true" class="moz-txt-link-freetext"
                  href="http://llvm.org/docs/LangRef.html#undefined-values">http://llvm.org/docs/LangRef.html#undefined-values</a>)
                suggests that </font><br class="">
              <div style="font-size: small; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: normal; letter-spacing: normal;
                line-height: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px;" class=""><font class="" face="Arial"><br
                    class="">
                  it is unsafe to consider (a & undef = undef) and
                   (a | undef = undef). <br class="">
                </font></div>
            </div>
          </div>
        </blockquote>
        <div><br class="">
        </div>
        <div><br class="">
        </div>
        <div>Yes, but the documentation specifies correctly "a &
          undef”, which does not have the same properties as “undef
          & undef”.</div>
        <div>While “a & undef” (for an arbitrary a) can’t be folded
          to undef, “undef & undef” can be folded to undef.</div>
        <div><br class="">
        </div>
        <div>— </div>
        <div>Mehdi</div>
        <div><br class="">
        </div>
        <div><br class="">
        </div>
        <br class="">
        <blockquote type="cite" class="">
          <div class="">
            <div bgcolor="#FFFFFF" text="#000000" class="">
              <div style="font-size: small; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: normal; letter-spacing: normal;
                line-height: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px;" class=""><font class="" face="Arial">
                  <br class="">
                  <font class="" color="#3366ff">"</font></font><font
                  class="" face="Arial"><font class="" color="#3366ff"><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">As such, it is
                      unsafe to optimize or assume that the result of
                      the ‘</span><code class="literal docutils"
                      style="font-family: Consolas,"Deja Vu Sans
                      Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">and</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ is ‘</span><code
                      class="literal docutils" style="font-family:
                      Consolas,"Deja Vu Sans
                      Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">undef</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘. However, it is
                      safe to assume that all bits of the ‘</span><code
                      class="literal docutils" style="font-family:
                      Consolas,"Deja Vu Sans
                      Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">undef</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ could be 0, and
                      optimize the ‘</span><code class="literal
                      docutils" style="font-family: Consolas,"Deja
                      Vu Sans Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">and</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ to 0. Likewise, it
                      is safe to assume that all the bits of the ‘</span><code
                      class="literal docutils" style="font-family:
                      Consolas,"Deja Vu Sans
                      Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">undef</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ operand to the ‘</span><code
                      class="literal docutils" style="font-family:
                      Consolas,"Deja Vu Sans
                      Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">or</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ could be set,
                      allowing the ‘</span><code class="literal
                      docutils" style="font-family: Consolas,"Deja
                      Vu Sans Mono","Bitstream Vera Sans
                      Mono",monospace; font-size: 0.95em;
                      font-style: normal; font-variant-ligatures:
                      normal; font-variant-caps: normal; font-weight:
                      normal; letter-spacing: normal; line-height: 21px;
                      text-align: left; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; background-color: rgb(255, 255,
                      255);"><span class="pre">or</span></code><span
                      style="font-family: "Lucida
                      Grande","Lucida Sans
                      Unicode",Geneva,Verdana,sans-serif;
                      font-size: 14px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: normal; letter-spacing:
                      normal; line-height: 21px; text-align: left;
                      text-indent: 0px; text-transform: none;
                      white-space: normal; word-spacing: 0px; display:
                      inline ! important; float: none; background-color:
                      rgb(255, 255, 255);" class="">‘ to be folded to
                      -1.</span>"</font><br class="">
                  <br class="">
                </font></div>
              <div style="font-size: small; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: normal; letter-spacing: normal;
                line-height: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px;" class=""><font class="" face="Arial"><br
                    class="">
                </font></div>
              <div style="font-size: small; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: normal; letter-spacing: normal;
                line-height: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px;" class=""><font class="" face="Arial">As
                  a result,  <br class="">
                </font></div>
              <div style="font-size: small; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: normal; letter-spacing: normal;
                line-height: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px;" class=""><font class="" face="Arial"> 
                   LHS = (undef & undef) | (undef & undef) = c_1
                  | c_2 where c_1 and c_2 are constants and as a result,
                  <br class="">
                  <br class="">
                   And finally,  LHS = c where c is a constant; not
                  undef.</font></div>
              <div style="font-family: arial,sans-serif; font-size:
                small; font-style: normal; font-variant-ligatures:
                normal; font-variant-caps: normal; font-weight: normal;
                letter-spacing: normal; line-height: normal; text-align:
                start; text-indent: 0px; text-transform: none;
                white-space: normal; word-spacing: 0px;" class=""><font
                  class="" face="Arial"> <br class="">
                  <br class="">
                </font>Please correct me if I am missing something.    </div>
              <p class="">Best Regards,</p>
              <p class="">soham<br class="">
              </p>
              <br class="">
              <div class="moz-cite-prefix">On 9/13/2016 7:27 PM, Sanjoy
                Das wrote:<br class="">
              </div>
              <blockquote
                cite="mid:57D83706.104@playingwithpointers.com"
                type="cite" class="">Hi Soham, <br class="">
                <br class="">
                Soham Chakraborty wrote: <br class="">
                > As a result,  the transformation ' ((a&  (~b))
                |((~a)&  b)) ~>  xor a b ' <br class="">
                > is unsound. LLVM presently performs this
                transformation. <br class="">
                <br class="">
                This transform looks fine to me. <br class="">
                <br class="">
                For simplicity let's look at an `i1` expression.  Since
                these are <br class="">
                bitwise ops we can extend the reasoning below to iN. <br
                  class="">
                <br class="">
                Transform: ((A & (~B)) | ((~A) & B))  ~> A ^
                B <br class="">
                <br class="">
                Neither A nor B are undef: <br class="">
                  Transform is correct by normal boolean algebra <br
                  class="">
                <br class="">
                Both A and B are undef: <br class="">
                  LHS = (undef & undef) | (undef & undef) =
                undef  // Since ~undef = undef <br class="">
                  RHS = undef <br class="">
                  Thus transform is correct. <br class="">
                <br class="">
                A is undef but B is not undef: <br class="">
                  LHS = ((undef & (~B)) | (undef & B)) // Since
                ~undef = undef <br class="">
                <br class="">
                  Now, by choosing 0 for undef in LHS, we can make LHS
                be equal to 0, <br class="">
                  and by choosing 1 for undef in LHS, we can make LHS be
                equal to 1. <br class="">
                  Therefore <br class="">
                <br class="">
                  LHS = undef <br class="">
                  RHS = undef ^ B = undef <br class="">
                <br class="">
                  Thus the transform is correct. <br class="">
                <br class="">
                A is not undef but B is undef: <br class="">
                  Similar reasoning follows. <br class="">
                <br class="">
                -- Sanjoy <br class="">
              </blockquote>
              <br class="">
            </div>
            _______________________________________________<br class="">
            LLVM Developers mailing list<br class="">
            <a moz-do-not-send="true"
              href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br
              class="">
            <a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br
              class="">
          </div>
        </blockquote>
      </div>
      <br class="">
    </blockquote>
    <br>
  </body>
</html>