Hello. Could you please tell me which passes in opt perform DCE for the following code (I am aware of the passes from the source file lib/Transforms/IPO/PassManagerBuilder.cpp): void foo(TYPE *A, TYPE *B, TYPE *C, TYPE N) { int tmpToBeDCE; for (TYPE i = 0; i < N; ++i) { C[i] = A[i] + B[i]; tmpToBeDCE = 2; } tmpToBeDCE++; } I ask because when I give this code to clang -O3 (I require -O3 to perform vectorization), in the resulting .ll file there is no reference to the tmpToBeDCE variable - it was eliminated since it has no real use. I would like to still have this variable implemented in the output .ll file. Thank you, Alex
Hi Alex, You can print the IR after each optimization pass using the '-mllvm -print-after-all' option. clang++ -O3 -mllvm -print-after-all -S -emit-llvm -o - test.cpp From there you should be able to determine which pass is removing the dead code. HTH, Chad On 2016-11-15 09:00, Alex Susu via llvm-dev wrote:> Hello. > Could you please tell me which passes in opt perform DCE for the > following code (I am aware of the passes from the source file > lib/Transforms/IPO/PassManagerBuilder.cpp): > void foo(TYPE *A, TYPE *B, TYPE *C, TYPE N) { > int tmpToBeDCE; > > for (TYPE i = 0; i < N; ++i) { > C[i] = A[i] + B[i]; > tmpToBeDCE = 2; > } > > tmpToBeDCE++; > } > > I ask because when I give this code to clang -O3 (I require -O3 to > perform vectorization), in the resulting .ll file there is no > reference to the tmpToBeDCE variable - it was eliminated since it has > no real use. > I would like to still have this variable implemented in the output > .ll file. > > Thank you, > Alex > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Hi Alex, That's probably not the answer you're looking for, but declaring tmpToBeDCE as volatile has the side effect of preventing DCE :-) On Tue, Nov 15, 2016 at 04:00:21PM +0200, Alex Susu via llvm-dev wrote:> Hello. > Could you please tell me which passes in opt perform DCE for the > following code (I am aware of the passes from the source file > lib/Transforms/IPO/PassManagerBuilder.cpp): > void foo(TYPE *A, TYPE *B, TYPE *C, TYPE N) { > int tmpToBeDCE; > > for (TYPE i = 0; i < N; ++i) { > C[i] = A[i] + B[i]; > tmpToBeDCE = 2; > } > > tmpToBeDCE++; > } > > I ask because when I give this code to clang -O3 (I require -O3 to > perform vectorization), in the resulting .ll file there is no reference to > the tmpToBeDCE variable - it was eliminated since it has no real use. > I would like to still have this variable implemented in the output .ll file. > > Thank you, > Alex > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Mikhail Zolotukhin via llvm-dev
2016-Nov-15 22:18 UTC
[llvm-dev] Disabling DCE pass from opt
> On Nov 15, 2016, at 6:00 AM, Alex Susu via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello. > Could you please tell me which passes in opt perform DCE for the following code (I am aware of the passes from the source file lib/Transforms/IPO/PassManagerBuilder.cpp): > void foo(TYPE *A, TYPE *B, TYPE *C, TYPE N) { > int tmpToBeDCE; > > for (TYPE i = 0; i < N; ++i) { > C[i] = A[i] + B[i]; > tmpToBeDCE = 2; > } > > tmpToBeDCE++; > } > > I ask because when I give this code to clang -O3 (I require -O3 to perform vectorization), in the resulting .ll file there is no reference to the tmpToBeDCE variable - it was eliminated since it has no real use. > I would like to still have this variable implemented in the output .ll file.Hi Alex, You can try to add a use of the variable, so that compiler cannot analyze it, e.g.: void use (int); // external function void foo(TYPE *A, TYPE *B, TYPE *C, TYPE N) { int tmpToBeDCE; for (TYPE i = 0; i < N; ++i) { C[i] = A[i] + B[i]; tmpToBeDCE = 2; } tmpToBeDCE++; use(tmpToBeDCE); } Michael> Thank you, > Alex > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev