<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 14, 2016, at 4:55 AM, sohachak via llvm-dev <<a 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 color="#993300" 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="">
</font><font face="Arial" class="">LLVM documentation
(<a 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 face="Arial" class=""><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 face="Arial" class="">
<br class="">
<font color="#3366ff" class="">"</font></font><font face="Arial" class=""><font color="#3366ff" class=""><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 face="Arial" 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 face="Arial" class="">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 face="Arial" class=""> 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 face="Arial" class=""> <br class="">
<br class="">
</font><font face="Arial" 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 href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>