Skip to content
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

[DebugInfo@O2] CodeGenPrepare drops reference to local in dbg.value intrinsic #39192

Closed
wolfy1961 opened this issue Nov 30, 2018 · 3 comments
Closed
Labels
bugzilla Issues migrated from bugzilla llvm:codegen

Comments

@wolfy1961
Copy link
Collaborator

Bugzilla Link 39845
Resolution FIXED
Resolved on Dec 14, 2018 09:23
Version trunk
OS All
Blocks #38116
CC @jmorse,@pogo59,@wjristow
Fixed by commit(s) r348896

Extended Description

extern void use(int);
extern int foo(long long);

void test(int p)
{
int i = p + 4;
(void)foo(i); // sign extension of i
if (p)
return;
use(i); // use of original i
}
// =====================================

Compile with -g -O2.

CodeGenPrepare seems to drop a reference to a local from a dbg.value
intrinsic:

*** IR Dump Before CodeGen Prepare ***
...
entry:
call void @​llvm.dbg.value(metadata i32 %p, metadata !​12, ...
%add = add nsw i32 %p, 4, !dbg !​15
call void @​llvm.dbg.value(metadata i32 %add, metadata !​13, ...

*** IR Dump After CodeGen Prepare ***
entry:
call void @​llvm.dbg.value(metadata i32 %p, metadata !​12, ...
%add = add nsw i32 %p, 4, !dbg !​15
call void @​llvm.dbg.value(metadata !​2, metadata !​13, ...

with:
!​2 = !{}
!​13 = !DILocalVariable(name: "i", scope: !​7, ...

So "i" does not get any location information in the .o.
If we change "foo" to take an int instead of a long long, the reference
is not dropped, and i has good location info.

On initial investigation it seems that CodeGenPrepare tries to
optimize sign/zero extensions and in the process replaces all uses of operands that it found worthy of extension with the extended versions.
When it finds that the optimization is not worth it (after it has already
performed it), it attempts to undo the replacement, but fails to restore
the Metadata uses.

It might be worth assessing whether this optimization is really all that useful, or find a way to restore the Metadata uses correctly.

@pogo59
Copy link
Collaborator

pogo59 commented Nov 30, 2018

Might want to collect some stats on how often CGP decides to back it out;
also might try speculatively nuking the optimization and see if there's
any effect on final emitted code.

@wolfy1961
Copy link
Collaborator Author

Might want to collect some stats on how often CGP decides to back it out;
also might try speculatively nuking the optimization and see if there's
any effect on final emitted code.

CGP uses the rollback technique on a variety of optimizations it attempts. In the example I'm using the statistics indicate that the number of rollbacks is quite large (in one case, in a 900 line file it's rolling something back over 4000 times). Now, these are total rollbacks, not just sign/zero extends, so I'm afraid nuking this one optimization would still leave the problem in place for all the others.

It feels like it would be best to teach it to properly roll back Metadata in debug instructions. That way we would eliminate this category of problems wholesale.

@wolfy1961
Copy link
Collaborator Author

Fixed with r348896.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen
Projects
None yet
Development

No branches or pull requests

2 participants