llvm / llvm-project

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

[Debuginfo] @​llvm.dbg.value changes behaviour of "Speculatively execute instructions" #39919

Open JonPsson opened 5 years ago

JonPsson commented 5 years ago
Bugzilla Link 40573
Version trunk
OS Linux
Attachments reduced testcase
CC @dwblaikie,@JonPsson,@pogo59,@uweigand

Extended Description

Without the @​llvm.dbg instruction in the test case, the fdiv instruction is moved up in the CFG by

bin/opt -mtriple=systemz-unknown -mcpu=z13 -S tc_speculexe.ll -speculative-execution

I suspect that this is also (as in bug 40564) related to counting instructions in the block on the line

 if (NotHoisted.size() > SpecExecMaxNotHoisted)

in SpeculativeExecution.cpp

JonPsson commented 5 years ago

OK, I think I know how to fix this, I'll submit a patch soon. Any chance you can reduce this a bit? The testcase is 2000 lines, but I guess only a small subset of them is needed.

I can only suggest that you try

bin/opt -strip -metarenamer -debugify

...

I did reduce it from the benchmark, but I may have missed using -debugify as well. Just need to make sure to not loose the llvm.dbg instruction...

llvmbot commented 5 years ago

OK, I think I know how to fix this, I'll submit a patch soon. Any chance you can reduce this a bit? The testcase is 2000 lines, but I guess only a small subset of them is needed.

llvmbot commented 5 years ago

bb5: ; preds = %bb br label %bb6

llvmbot commented 5 years ago

This is why it's failing.

200 // If a block has only one instruction, then that is a terminator 201 // instruction so that the block does nothing. This does happen. 202 if (Succ1.size() == 1) // equivalent to if-then -> 203 return considerHoistingFromTo(Succ0, B);

JonPsson commented 5 years ago

So, just to understand, this is the thing not hoisted.

bb3: ; preds = %bb %tmp4 = fdiv double 1.000000e+00, %tmp, !dbg !​1200

yes, exactly...

llvmbot commented 5 years ago

So, just to understand, this is the thing not hoisted.

bb3: ; preds = %bb %tmp4 = fdiv double 1.000000e+00, %tmp, !dbg !​1200