llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.21k stars 11.64k forks source link

[DebugInfo@O2][Dexter] static function variable debug values not updating in loops after LICM #38125

Open gregbedwell opened 6 years ago

gregbedwell commented 6 years ago
Bugzilla Link 38777
Version trunk
OS Windows NT
Blocks llvm/llvm-project#38116
Attachments pre-LICM DExTer trace, post-LICM DExTer trace
CC @adrian-prantl,@dwblaikie,@CarlosAlbertoEnciso,@JDevlieghere,@jmorse,@pogo59

Extended Description

Testcase (simplified version of https://github.com/SNSystems/dexter/blob/d2a419e49/tests/nostdlib/static_loop_variables/test.cpp ):

// ===================================================== int Foo(const int iterations, const int initial) { static int val = initial;

for (static int i = 0; i <= iterations; ++i) val += (i % 2 ? 50 : 25) * i; // <-- BREAK HERE

return val; }

int main(int argc, char**) { return Foo(4 + argc, 5 + argc); } // =====================================================

Using LLVM/Clang r341056.

Compiling with "-O0 -g -fno-inline", if I put a breakpoint in the loop and inspect variable "i" at each iteration, I will see "0", "1", "2", "3", "4", "5" as expected. Similarly, if I inspect variable "val", I will see "6", "6", "56", "106", "256", "356" as expected. On the "return val" line, I see "6" for "i" and "606" for "val".

Compiling with "-O2 -g -fno-inline", if I put a breakpoint in the loop and inspect variable i at each iteration, I will see "0" for each iteration, and inspecting "val" I will see "6" at each iteration. On the "return val" line, I still see "6" for "i" and "606" for "val".

Using DExTer's clang-opt-bisect tool: $ dexter.py clang-opt-bisect --builder clang --debugger lldb --cflags="-O2 -g -fno-inline" --ldflags="-g" -- tests\nostdlib\static_loop_variables I've narrowed this change down to LICM running on the loop.

jmorse commented 5 years ago

Hmm, there are no dbg.values in that function when it gets to LICM -- I think this is happening because LICM promotes the global to be in a register for the body of the loop, thus the effect of the loop doesn't reach memory until the end of the loop.