[llvm-dev] IR "canonicalization"

Lorenzo Laneve via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 5 15:49:20 PDT 2016

I’m implementing a front-end compiler and I need to do the most basic optimizations to the IR it generates, just like Clang does.

For example:

"if not x” becomes:

%1 = xor %x, true
br i1 %1 label %2, label %3

and Clang (even with -O0) just swaps labels:

bt i1 %x label %3, label %2

Another optimization is to remove “empty blocks” that simply br to another label:

br i1 %x label %emp1, label %emp2 

	br label %cont


which becomes simply:

br i1 %x label %cont, label %emp2 


Is there a pass Clang uses to do these basic optimizations? Where should I look in the Clang source code?

More information about the llvm-dev mailing list