Open 2994186010 opened 1 year ago
@llvm/issue-subscribers-debuginfo
Both versions are too old. Could you please try 16 release candidate or main
branch? https://godbolt.org should be helpful.
@llvmbot @EugeneZelenko , about this problem, I want to tell you some interesting attempts. First, I use the following code to make some tests in https://godbolt.org/.
double sum(double value, int exp) {
if(value==1.0||value==0.0) return value;
return 3.0;
}
The main branch should be x86-64 clang(trunk). I use x86-64 clang(trunk) as the compiler. The debug info of "value==0.0" is still missing. I try other clang releases. The debug info is not missing when using clang8, clang9 and clang10. The debug info is missing when using clang11, clang12, clang13, clang14 and clang15. The corresponding tests is in the above short links. The source code is considered as C++ for the compiler. One test is as following.
Strangely, The debug info is not missing when the source code is considered as C for the compiler. The corresponding test is as following.
I have one question. Can I get the detailed compilation command in https://godbolt.org/. In my local clang compilation environment, I can only get the same compilation result as https://godbolt.org/ when https://godbolt.org/ consider the source code as C++.
I make one test using clang11 and find that the simplify pass throws down the debug info.
/root/apps/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -emit-llvm -g -O3 -c s_ldexp.c -mllvm -print-after-all >& clang.log
At last, I hope that I can get some useful tips to help me fix this bug. Certainly, I would appreciate it if someone can fix the bug.
This replicates with eb8fcc1e835ac, which is only a month old -- however, I believe the source location is being dropped deliberately, and it's the correct behaviour in this situation.
The SimplifyCFG pass chooses to speculatively execute the second part of each "if" condition to reduce the amount of branching, and folds the relevant instructions into the same block as the first condition, hence you get two fcmp
's together. The updating-debug-info guide [0] says that when this happens, we need to drop the source location, so that debuggers don't appear to step through lines that are never actually reached. This is designed for the scenario where the whole body of an "if" condition gets speculated, unfortunately your code sample matches that pattern in a different way.
We can handle this situation better, and there's a general interest in LLVM for separating out the attribution of where-an-instruction-came-from from what-to-step-through, however that isn't likely to happen very soon, sorry.
@jmorse , I don't agree with you. When change the optimization level from "-O3" to "-O0", the debug info is not missing as the following.
And the debug info is not missing when the source code is considered as C for the compiler as the following.
Indeed, at O0 almost everything about the source program will be retained, as no optimisations will be applied to the LLVM-IR program. It's the transformations that happen to the program during optimisation destroy the relationship between the source program and the optimised one.
Following both examples in your screenshots, the fcmp in question has stayed in it's own conditionally executed block, therefore there has been no need to remove that information.
(links to godbolt rather than/or in addition to screenshots is probably good)
But yeah, everything @jmorse said - this looks correct to me. Optimizations made conditional code unconditional and so the location was removed so as not to confuse users or profilers.
The C source code is as following.
The compilation command is
clang -emit-llvm -g -O3 -D_IEEE_LIBM -Wall -Wuninitialized -c s_ldexp.c -o s_ldexp.bc
I transform the bitcode into human-readable LLVM assembly language using this commandllvm-dis s_ldexp.bc -o s_ldexp.ll
The IR compiled by clang8 is as following.
The IR compiled by clang11 is as following.
In the
s_ldexp.c
, there one code snippetvalue==0.0
. The corresponding IR compiled by clang8 is%5 = fcmp oeq double %0, 0.000000e+00, !dbg !19
. The corresponding IR compiled by clang11 is%5 = fcmp oeq double %0, 0.000000e+00
. Compared with clang8, the debug info!dbg !19
is missing in the corresponding IR compiled by clang11. The debug info is important to me. I hope that LLVM11 can reserve the debug info. For LLVM11, there are there methods that can solve the problem.The first method is to run these two commands.
When using Clang to compile source code,
-g
parameter is not used. And we can use LLVM opt command to attach debug info into the IR.The second method is to run this command.
The command is to lower the optimization level of compiler and keep as much debug info as possible.
The third method is to modify the C source code. The code after modification is as following.
We can get around this problem using the third method.
Though these three method can solve this problem, I still have two questions. The first question is why the debug info is missing in the IR compiled by clang11. The second question is that is there any option or LLVM pass can check whether some debug info is missing and complement the missing debug info.