When UpdateBaseRegUses sees an instruction that defines the base register it must stop, as the base register value it is updating is no longer live. Ideally we would already have seen the register be killed (which is already checked for), but the kill flags may be inaccurate and we have to account for this.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Nice catch! Kill flags are indeed optional nowadays so the additional check for definesRegister is necessary. Do you happen to have a llvm-lit testcase that exposes the bug?
I have a .ll file that exposes the bug but it's ~150 lines long and generates assembly that's ~450 lines long, with the incorrectly-generated code sequence in the middle which is rather infeasible to test. I haven't been able to reduce it to produce a sensible test case - it looks like it's a very specific combination of regalloc and post-regalloc optimization that produces the input to the load/store optimizer that triggers the bug.
It's probably tricky to get the compiler into a state where the kill flag is omitted. I guess until we have a way to serialize MI it is very hard to a proper testcase. So LGTM without testcase.