Bugs and their Fixes - Introduction

Bugs are both fun and frustrating to discover and fix. Here are some of the weird bugs we've encountered through LegUp. Maybe some day this list will help solve future bugs by example.

gsm bug - phi dependencies

Due to the SSA nature of LLVM, the phi instruction is a necessity. Since it's not found in either software or normal assembly, it's trickier. A phi instruction assigns a variable depending on which basic block branched to the current one. After upgrading llvm-gcc from 2.6svn to 2.7, this bug showed up on gsm. It was also the cause of http://www.legup.org/bugs/show_bug.cgi?id=3. Andrew fixed this bug after looking for the cause for several days by adding display statements in Verilog. A well-placed printf fixed the result, but did not fix the underlying cause. http://www.legup.org/git?p=legup.git;a=commit;h=15869e30493a50f2cd4bcf9af4a85151a94a0bf1 was the result after finding the bug. After this, LegUp became more methodical at finding bugs, with the assert statements and a debugger that just printed out variable dumps, that could diff with the expected result.

switch/case outputted incorrect assembly syntax, but which made sense otherwise. I initially wrote a script to parse the assembly and output the correct result. This worked, but was an ugly hack. In the mips backend, I searched for JT, which was where the bad syntax started. No results, so I searched JumpTable and found the code that lowered switch/case into a form that the mips backend would then output. After playing around with a few flags, I stumbled upon a working solution by adding a ! in an if statement. In a function that lowered another function, the ! was equivalently present in the if statement.

Mark and I looked at the reason behind the select problem and we were able to quickly trace down the cause to a piece of code which contradicted its comment. A simple fix was now satisfactory. I posted a patch of my switch/case fix and the LLVM mips backend maintainer was able to confirm that it was a correct fix that made sense.