In this section, we will see how we fold instructions into simpler forms in LLVM. Here, the creation of new instructions will not take place. Instruction simplification does constant folding:
sub i32 2, 1 -> 1
That is, it simplifies the sub
instruction to a constant value 1
.
It can handle non-constant operands as well:
or i32 %x, 0 -> %x
It returns a value of variable %x
and i32 %x %x -> %x
In this case, it returns an already existing value.
The implementations for the methods that simplify instructions are located in lib/Analysis/InstructionSimplify.cpp
.
Some of the important methods of dealing with the simplification of instructions are:
Here, by Opcode
, we mean the operator...