-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 -O3 on x86_64-linux-gnu #25407
Comments
assigned to @MatzeB |
As far as I can tell, in this example ExpandPostRA::LowerCopy I think there are two indpendent issues here: In MachineBasicBlock::computeRegisterLiveness, we need something like diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp
because otherwise we'll conclude, e.g., AX is killed by "%AH = Secondly, I think there's a bug in diff --git a/lib/CodeGen/MachineInstrBundle.cpp b/lib/CodeGen/MachineInstrBundle.cpp
|
I'm not sure if the following change is correct (I'd need to dig some more to understand):
But the name of the variable should change to IsSuperReg if the change is correct :-) Could you elaborate on why you think MOReg == Reg is incorrect? |
This is calling
The important semantic change is in the order of the operands, so IIUC this change makes the code equivalent to bool IsRegOrSuperReg = MOReg == Reg || TRI->isSubRegister(MOReg, Reg); (Lots of IIUC's there, because this is the first time I'm reading this code :) ) |
A note about reproducibility: I could not reproduce this directly using clang on OSX. But I can reproduce this by running ./bin/llc -O3 small.ll && clang -m32 small.s -o small (with the attached small.ll) Is it possible that the exact pipeline differs between OSX and linux? |
The following testcase likely reveals the same issue(s): $ clang-trunk -v int a, b, c, e, *f = &e, k; void int if (d) return 0; |
I think the following bugs all trigger similar bugs: MachineOperandIteratorBase::analyzePhysReg and MachineBasicBlock::computeRegisterLiveness aren't quite in sync with each other when it comes to super-registers and sub-registers. I think the following is also working around the same issue: Sanjoy: I tried out your proposed fix and it doesn't seem to address the other issues. Have you made any progress since then? I also tried a few things but the logic of this code is giving me a headache. |
Here's a workaround for now: |
I haven't spent more time looking at this. But this is what I analyzePhysReg returns Clobber if the register Reg is only partially computeRegisterLiveness thinks a register is dead if it it finds a
This means we fail see that RAX (say) is partially live over FOO in %eax = ... ;; (1) analyzePhysReg says %rax is clobbered by (1). computeRegisterLiveness The fix is either to
|
The workaround is now checked in. We should leave these bugs open and fix the core issue. |
Sanjoy was right in that computeRegisterLiveness() interpreted the meaning of Clobbers wrong. I figured that part of the problem was that the meaning of Clobbers as clobbered by the regmask or partially defined wasn't particularily usefull for the usecase (you want to know about full clobbers or defines). I cleaned up/rewrote the code in http://reviews.llvm.org/D15320 |
*** Bug #24909 has been marked as a duplicate of this bug. *** |
*** Bug #25365 has been marked as a duplicate of this bug. *** |
*** Bug #25366 has been marked as a duplicate of this bug. *** |
*** Bug llvm/llvm-bugzilla-archive#25201 has been marked as a duplicate of this bug. *** |
I tried the reproducers in all the bugs mentioned in comment #7 and they all work fine with my patch (clang -O3 -m32 xxx.c on OS X). |
Should be fine now that http://reviews.llvm.org/D15320 landed. |
mentioned in issue llvm/llvm-bugzilla-archive#25201 |
Extended Description
The following code is miscompiled by the current clang trunk on x86_64-linux-gnu at -O2 and -O3 in 32-bit mode (but not in 64-bit mode).
This is a regression from 3.7.x.
It seems different from PR 24991, which disappears with -g enabled.
$ clang-trunk -v
clang version 3.8.0 (trunk 249170)
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.2
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.1.0
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.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
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 -m64 -O2 small.c; ./a.out
$ clang-trunk -m32 -Os small.c; ./a.out
$ clang-3.7.0 -m32 -O2 small.c; ./a.out
$
$ clang-trunk -m32 -O2 small.c
$ ./a.out
Aborted (core dumped)
$ clang-trunk -m32 -O2 -g small.c
$ ./a.out
Aborted (core dumped)
$
int a, b, c, e, f, g, h;
char d;
int
main ()
{
f = 0;
h = d > 0;
c = g;
e--;
a = b <= 0;
e && (g = 0);
g--;
d ^= 1;
if (d != 1)
__builtin_abort ();
return 0;
}
The text was updated successfully, but these errors were encountered: