[cfe-dev] Trying to figure out where a front-end optimization occurs

bharathi seshadri via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 23 16:24:38 PST 2017


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!

Bharathi



More information about the cfe-dev mailing list