New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong code at -Os and above on x86_64-linux-gnu (DemandedBits) #26445
Comments
Bisection points to r249687. |
define i32 @main(i32 %i3) { if: exit: $ ./opt 26071small.ll -S |./llc -o - -mtriple=x86_64-apple-darwin |./clang -x assembler - ; ./a.out ; echo $? |
Did this get fixed? |
No, this is still broken as of r259529. |
We should probably revert r249687 in the meanwhile. |
Hi, Sorry, this seemed to fly by me. I'm surprised my recent bug fix to this code didn't sort this; I will investigate with urgency tomorrow. James |
Hi, This code is indeed wrong. What's happening is that ComputeKnownZeroes is telling us that all bits except the LSB are zero. We're then deciding that only the LSB needs to be demanded from the icmp's inputs. This is where we're wrong - we're assuming that after simplification the bits that were known zero will continue to be known zero. But they're not - during trivialization the upper bits get changed (because an XOR isn't shrunk), so the icmp fails. The fault is in demandedbits - its contract does clearly state that a non-demanded bit may either be zero or one. I will revert the change and think about how to do this better. James |
Reverted in r259649. I had to remove a LoopVectorize test that is now failing, so I will need to go think about how to implement this in a sane way. |
Extended Description
The following code is miscompiled by the current clang trunk on x86_64-linux-gnu at -Os and above in both 32-bit and 64-bit modes.
This is a regression from 3.7.x.
$ clang-trunk -v
clang version 3.8.0 (trunk 257078)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/tools/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.2.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.2.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
$
$ clang-trunk -O1 small.c; ./a.out
0
$ clang-3.7.0 -Os small.c; ./a.out
0
$
$ clang-trunk -Os small.c; ./a.out
$
int printf (const char *, ...);
char a;
int b, c;
int
main ()
{
int d = c = 1;
for (; a < 1; a++)
{
char e;
for (;;)
{
e = ~((c || c) | ~(b && -d));
if (e < c)
{
printf ("%d\n", b);
c = 1;
}
break;
}
}
return 0;
}
The text was updated successfully, but these errors were encountered: