<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Option 3? Add APSInt as a new member?<div class=""><br class=""></div><div class="">Current:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">Scalar</span>::<span style="color: #326d74" class="">Type</span> m_type;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">llvm</span>::<span style="color: #326d74" class="">APInt</span> m_integer;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">llvm</span>::<span style="color: #326d74" class="">APFloat</span> m_float;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #9b2393" class=""><b class="">bool</b></span> m_ieee_quad = <span style="color: #9b2393" class=""><b class="">false</b></span>;</div><div class=""><br class=""></div><div class="">Option #3:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">Scalar</span>::<span style="color: #326d74" class="">Type</span> m_type;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">llvm</span>::<span style="color: #326d74" class="">APInt</span> m_uint;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: rgb(50, 109, 116);" class="">llvm</span>::<span style="color: rgb(50, 109, 116);" class="">APSInt</span> m_sint;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #326d74" class="">llvm</span>::<span style="color: #326d74" class="">APFloat</span> m_float;</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">  <span style="color: #9b2393" class=""><b class="">bool</b></span> m_ieee_quad = <span style="color: #9b2393" class=""><b class="">false</b></span>;</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I don't know enough about APInt and APSInt to know if one or the other can correctly be used for mixed operations.</div><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 4, 2019, at 1:57 PM, Davide Italiano <<a href="mailto:dccitaliano@gmail.com" class="">dccitaliano@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">While adding support for 512-bit integers in `Scalar`, I figured I<br class="">could add some coverage.<br class=""><br class="">TEST(ScalarTest, Signedness) {<br class=""> auto s1 = Scalar(APInt(32, 12, false /* isSigned */));<br class=""> auto s2 = Scalar(APInt(32, 12, true /* isSigned */ ));<br class=""> ASSERT_EQ(s1.GetType(), Scalar::e_uint); // fails<br class=""> ASSERT_EQ(s2.GetType(), Scalar::e_sint); // pass<br class="">}<br class=""><br class="">The result of `s1.GetType()` is Scalar::e_sint.<br class="">This is because an APInt can't distinguish between "int patatino = 12"<br class="">and "uint patatino = 12".<br class="">The correct class in `llvm` to do that is `APSInt`.<br class=""><br class="">I think there are at least a couple of possibilities to fix this:<br class="">1) Change the constructor in Scalar to always get an APSInt. This<br class="">would be fairly invasive but we could always query isSigned() to make<br class="">sure we instantiate the correct scalar type.<br class="">2) Change the implementation of Scalar(APInt v) to look at the sign<br class="">bit, and if that's set, treat the value as signed (and unsigned<br class="">otherwise). This will be definitely more correct than the current<br class="">implementation which always construct signed types from APInt(s), but<br class="">I'm not entirely sure of all the implications.<br class=""><br class="">What do you think?<br class=""><br class="">--<br class="">Davide<br class=""></div></div></blockquote></div><br class=""></div></body></html>