[cfe-dev] Trying to figure out where a front-end optimization occurs
Friedman, Eli via cfe-dev
cfe-dev at lists.llvm.org
Mon Jan 23 17:35:18 PST 2017
On 1/23/2017 4:24 PM, bharathi seshadri via cfe-dev wrote:
> I'm trying to understand where, in the front-end, the if block in the
> example shown below is optimized away (with optimization level -O1 and
> above).
>
> $ cat test.c
> void foo(int x);
> int main() {
> int x = 0;
> if (x)
> foo(x);
> return 0;
> }
> $clang -emit-llvm -O2 -S test.c
>
>
> I tried to figure this out by debugging clang using gdb, but without
> success. I see that in CodeGenFunction::EmitIfStmt, the call to
> ConstantFoldsToSimpleInteger(), which appears to help decide removal
> of the dead arm of the if/else, returns false in this case and the
> code proceeds to emit the IF block. I see that
> CodeGenFunction::EmitCall is also being invoked for foo(). But the
> final output (test.ll) shows that the if block is optimized away and
> there is no call to foo().
>
> Any pointers would be greatly appreciated!
>
echo "int g(); void f() { int x = 0; if (x) g(); }" | clang -x c - -o -
-S -mllvm -print-after-all -O2 |& less
That shows the IR after each step of the optimizer.
-Eli
--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
More information about the cfe-dev
mailing list