Constant propagation over RTL. This is one of the optimizations
performed at RTL level. It proceeds by a standard dataflow analysis
and the corresponding code rewriting.
.
.
.
.
.
The code transformation builds on the results of the static analysis
of values from module
ValueAnalysis. It proceeds instruction by
instruction.
-
Operators whose arguments are all statically known are turned into
``load integer constant'', ``load float constant'' or ``load
symbol address'' operations. Likewise for loads whose result can
be statically predicted.
-
Operators for which some but not all arguments are known are subject
to strength reduction (replacement by cheaper operators) and
similarly for the addressing modes of load and store instructions.
-
Cast operators that have no effect (because their arguments are
already normalized to the destination type) are removed.
-
Conditional branches and multi-way branches are statically resolved
into Inop instructions when possible.
-
Other instructions are unchanged.
In addition, we try to jump over conditionals whose condition can
be statically resolved based on the abstract state "after" the
instruction that branches to the conditional. A typical example is:
1: x := 0 and goto 2
2: if (x == 0) goto 3 else goto 4
where other instructions branch into 2 with different abstract values
for
x. We transform this code into:
1: x := 0 and goto 3
2: if (x == 0) goto 3 else goto 4
For debug annotations, add constant values to the original info
instead of replacing it.