Hi, I am using opt to perform GVNSink optimization on my code. However, I found that the GVNSink pass failed to optimize my code when I gave it the LLVM IR with debug info. If I give it the LLVM IR without debug info, it performs well. I thought this may be a bug in GVNSink, so I file this issue. After trying to find why this happened, I found the root cause.
Here is the source code:
int fun(int a, int b) {
int ret;
if (b > 10) {
int a1 = a + 1;
int a2 = a1 ^ 1;
ret = a2;
} else {
int b1 = b + 1;
int b2 = b1 ^ 1;
ret = b2;
}
return ret;
}
The clang and opt used are the latest version built from the source code:
Apparently, in the main-dbg-sink.ll (compiled with -g), the instructions (add and xor) in the if.then block and the if.else block are not sunk to the if.end block.
This is caused by the mishandle of LLVM Debug Intrinsics in GVNSink. When reversely traversing the current basic block's predecessors to find instructions to sink, GVNSink does not exclude LLVM Debug Intrinsics, which cannot be sunk, resulting in an empty candidate vector.
I have a patch for this issue. A pull request will be made later.
Hi, I am using
opt
to perform GVNSink optimization on my code. However, I found that the GVNSink pass failed to optimize my code when I gave it the LLVM IR with debug info. If I give it the LLVM IR without debug info, it performs well. I thought this may be a bug in GVNSink, so I file this issue. After trying to find why this happened, I found the root cause.Here is the source code:
The clang and opt used are the latest version built from the source code:
First, GVNSink is performed on LLVM IR without debug info
Then we have the following LLVM IR:
Then, we perform GVNSink on LLVM IR with debug info:
We will get the following IR:
Apparently, in the main-dbg-sink.ll (compiled with
-g
), the instructions (add
andxor
) in the if.then block and the if.else block are not sunk to the if.end block.This is caused by the mishandle of LLVM Debug Intrinsics in GVNSink. When reversely traversing the current basic block's predecessors to find instructions to sink, GVNSink does not exclude LLVM Debug Intrinsics, which cannot be sunk, resulting in an empty candidate vector.
I have a patch for this issue. A pull request will be made later.