Hello, I am opening llvm more and more for me, so now I have some questions about shifting and undef value: 1) undef value is like a separate entity. But I have seen in some notes, that this is legal to compute expressions with undef value. So , undef |1 will be equal to one (the size of the result will depended on the size of one)? And undef & 0 will be equal to zero and so on? 2) Is it compiler dependent (may be here there is a lack of my knowledges) that unoptimized version of llvm , when I try: char a = 6; char a = 2; char c = 6<<2 - performs sext on 6 before performing a 32 bit shl? Thank you in advance for the answers. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170725/48c4d804/attachment.html>
I have also tested and found out, that however in this example: unsigned a = 1; unsigned b = a << 33; for (int i = 0; i < 32; i++) printf("%d ", ((b >> i) & 1)); return b; I get the undef value at the end: * ret i32 undef* he bits are printed correctly - shifted by the modulo, as is defined in the standard. What is the explanation? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170725/81d9e78b/attachment.html>
This seems like a misunderstanding of the standard. For unsigned a, a << b is equal to (a * pow(2,b)) % (MAXUINT+1), *except* if b is greater than or equal to the word size, in which case the result is undefined. For the particular case of 1 << 33, many machines will give 0 and many will give 2. Some many give other values. As far as the C standard, the result is undefined and llvm is correct. On Tue, Jul 25, 2017 at 3:15 PM, Anastasiya Ruzhanskaya via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I have also tested and found out, that however in this example: > unsigned a = 1; > unsigned b = a << 33; > for (int i = 0; i < 32; i++) > printf("%d ", ((b >> i) & 1)); > return b; > I get the undef value at the end: > * ret i32 undef* > he bits are printed correctly - shifted by the modulo, as is defined in > the standard. What is the explanation? > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170725/aeec5d34/attachment.html>