Trying to figure out where a front-end optimization occurs

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

$ cat test.c
void foo(int x);
int main() {
int x = 0;
if (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.